Fix detection of root device resize

If xvda is not partitioned, checking size of device mounted as root dev
doesn't detect xvda resize - it will have the new size, while the fs on
it not. Change to checking actual filesystem size.

Also, improve log message to include the size.

Fixes QubesOS/qubes-issues#4274
This commit is contained in:
Marek Marczykowski-Górecki 2018-09-04 17:43:49 +02:00
parent aa5d955fbc
commit 581d9c12ed
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -11,14 +11,16 @@ if [ "$(blockdev --getro /dev/xvda)" -eq "1" ]; then
exit 0 exit 0
fi fi
sysfs_root_dev="/sys/dev/block/$(mountpoint -d /)"
sysfs_xvda="/sys/class/block/xvda" sysfs_xvda="/sys/class/block/xvda"
# if root filesystem use already (almost) the whole dis # if root filesystem use already (almost) the whole dis
non_rootfs_data=$(( 250 * 1024 * 2 )) non_rootfs_data=$(( 250 * 1024 * 2 ))
rootfs_size=$(df --output=size / | tail -n 1)
# convert to 512-byte blocks
rootfs_size=$(( rootfs_size * 2 ))
if [ "$(cat "$sysfs_xvda/size")" -lt \ if [ "$(cat "$sysfs_xvda/size")" -lt \
$(( non_rootfs_data + $(cat "$sysfs_root_dev/size") )) ]; then $(( non_rootfs_data + rootfs_size )) ]; then
echo "root filesystem already at the right size" >&2 echo "root filesystem already at $rootfs_size blocks" >&2
exit 0 exit 0
fi fi