I could really use some help figuring out how to safely expand the root partition on my Linux server VM. I’ve added 50GB of extra space to the VM’s virtual disk, and I can see it using fdisk, but I'm unsure how to allocate it without breaking the system.
Here’s my current partition layout:
home-srv-01:~ # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 8M 0 part
├─sda2 8:2 0 30.8G 0 part /var
│ /usr/local
│ /tmp
│ /boot/grub2/i386-pc
│ /boot/grub2/x86_64-efi
│ /opt
│ /srv
│ /.snapshots
│ /root
│ /
├─sda3 8:3 0 17.2G 0 part /home
└─sda4 8:4 0 2G 0 part [SWAP]
sr0 11:0 1 15.3G 0 rom
home-srv-01:~ #
home-srv-01:~ # fdisk -l
GPT PMBR size mismatch (104857599 != 209715199) will be corrected by write.
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: A1C8759F-D45C-4FB4-A365-1402AD4516B3
Device Start End Sectors Size Type
/dev/sda1 2048 18431 16384 8M BIOS boot
/dev/sda2 18432 64600063 64581632 30.8G Linux filesystem
/dev/sda3 64600064 100661247 36061184 17.2G Linux filesystem
/dev/sda4 100661248 104857566 4196319 2G Linux swap
home-srv-01:~ #
The goal is to expand the Btrfs root partition (sda2) into the new free space without losing the data on /home (sda3 XFS) or causing the system to become unbootable. Unfortunately, my earlier attempts resulted in boot issues, so I’m being extra cautious now.
Recap of Steps:
- Backed up all data from
/home
(/dev/sda3
). - Booted into a live CD/USB environment.
- Moved data from
/home
to an external disk. - Ran
swapoff /dev/sda4
and deleted/dev/sda4
. - Deleted
/dev/sda3
(this creates free space next to/dev/sda2
). - Resized the Btrfs filesystem on
/dev/sda2
usingbtrfs filesystem resize max /
. - Recreated
/dev/sda3
and restored the/home
data from the backup. - Recreated
/dev/sda4
and ranswapon /dev/sda4
. - Once completed, the system does not boot anymore.
Thanks a lot in advance for any advice or step-by-step suggestions. I’d really appreciate your guidance.
LX
You want to use
btrfs filesystem resize max /path
. Check the examples in the manpage https://btrfs.readthedocs.io/en/latest/btrfs-filesystem.html#examplesStandard disclaimer applies: make a backup and make sure it's functional before taking any potentially destructive action.
You don't even need to go through all the effort of reshuffling partitions to change the size of
/dev/sda2
in place. Btrfs natively supports using multiple underlying devices in a single file system, so adding space is as easy as creating a new partition in the new free space at the end of your virtual disk. This can all be done online with at most two simple reboots needed, no backup-restore needed at all (although having backups is strongly advised as always)./dev/sda
). This might require rebooting the VM to apply the change. Alternatively, create a brand new VM disk instead of resizing the existing one if that's easier (might work without a reboot, depending on your hypervisor).fdisk /dev/sda
/dev/sda5
does not appear automatically, runpartprobe /dev/sda
. If that doesn't help, reboot the VM.btrfs device add /dev/sda5 /
and enjoy your enlarged root file system.