blob: 0730733c2ef2285c6adbfbe2344f4d1304384e26 [file] [log] [blame]
#!/bin/bash
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
CGPT=/usr/share/cloud/cgpt
resolve_children() {
local MAX_DEPTH=8
local dev; dev="$(basename "$(realpath "${1}")")"
for ((i=0; i<${MAX_DEPTH}; ++i)); do
local sysfs="/sys/class/block/${dev}/slaves"
if [[ -d "${sysfs}" ]]; then
dev="$(ls -1 "${sysfs}" | head -n1)"
else
break
fi
done
if [[ -e "/dev/${dev}" ]]; then
echo "/dev/${dev}"
fi
}
# Detect stateful partition
lsblk -P -o NAME,FSTYPE,MOUNTPOINT 2>/dev/null | while read dev_info; do
eval $dev_info
if [[ "${MOUNTPOINT}" == "/mnt/stateful_partition" ]]; then
STATE_PART="$(resolve_children "/dev/${NAME}")"
old_size=$(blockdev --getsz "${STATE_PART}")
echo "Old size of ${STATE_PART} is ${old_size} in 512-byte sectors."
$CGPT resize ${STATE_PART}
new_size=$(blockdev --getsz "${STATE_PART}")
echo "New size of ${STATE_PART} is ${new_size} in 512-byte sectors."
if [[ "${old_size}" -ne "${new_size}" ]]; then
echo "Resizing file system..."
resize2fs "/dev/${NAME}"
fi
break
fi
done