Skip to content

Commit

Permalink
Support btrfs while resizing root filesystem
Browse files Browse the repository at this point in the history
Fedora now ships with btrfs as default, add support for it.

QubesOS/qubes-issues#7310
  • Loading branch information
marmarek committed Feb 27, 2022
1 parent 5c8fab9 commit c701729
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
19 changes: 16 additions & 3 deletions init/resize-rootfs-if-needed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,22 @@ boot_data_size=$((203 * 2 * 1024))
# because that can change dynamically over the filesystem's lifetime.
# See QubesOS/qubes-core-agent-linux#146 and QubesOS/qubes-core-agent-linux#152
# for more details
ext4_block_count=$(dumpe2fs /dev/mapper/dmroot | grep '^Block count:' | sed -E 's/Block count:[[:space:]]+//')
ext4_block_size=$(dumpe2fs /dev/mapper/dmroot | grep '^Block size:' | sed -E 's/Block size:[[:space:]]+//')
rootfs_size=$((ext4_block_count * ext4_block_size / 512))
rootfs_type=$(blkid --output value --match-tag TYPE /dev/mapper/dmroot)
case "$rootfs_type" in
ext*)
ext4_block_count=$(dumpe2fs /dev/mapper/dmroot | grep '^Block count:' | sed -E 's/Block count:[[:space:]]+//')
ext4_block_size=$(dumpe2fs /dev/mapper/dmroot | grep '^Block size:' | sed -E 's/Block size:[[:space:]]+//')
rootfs_size=$((ext4_block_count * ext4_block_size / 512))
;;
btrfs)
rootfs_size_bytes=$(btrfs filesystem usage --raw / | grep 'Device size:' | sed -E 's/Device size:[[:space:]]+//')
rootfs_size=$((rootfs_size_bytes / 512))
;;
*)
echo "Unsupported filesystem $fstype" >&2
exit 1
;;
esac
# 5 MB in 512-byte units for some random extra bits
size_margin=$((5 * 1024 * 2))
if [ "$(cat $sysfs_xvda/size)" -lt \
Expand Down
14 changes: 13 additions & 1 deletion qubes-rpc/resize-rootfs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@ case "$(stat -Lc %t:%T /dev/mapper/dmroot)" in
exit 1
;;
esac
resize2fs /dev/mapper/dmroot
fstype=$(blkid --output value --match-tag TYPE /dev/mapper/dmroot)
case "$fstype" in
ext*)
resize2fs /dev/mapper/dmroot
;;
btrfs)
btrfs filesystem resize max /
;;
*)
echo "Unsupported filesystem $fstype" >&2
exit 1
;;
esac

0 comments on commit c701729

Please sign in to comment.