An adventure in resizing partitions
Posted on 2019-09-19 Edit on GitHub
Recently I began working with some VirtualBox VMs. My Asus Zenbook, which comes with 256 GB of SSD dual-booted with Windows and Fedora, soon found its Fedora installation aching for more disk space.
So I fired up GParted, shrank the Windows partition, and tried to extend the Fedora one. Well, turns out you can't modify a partition that GParted is running from (duh!), so I created a Fedora Live USB with Fedora Media Writer, booted into the live image, and installed GParted. I moved the unallocated space to the right of several partitions, but it came to the Fedora partition, I again found that I couldn't modify it. What's going on?
Turns out that the Fedora partition is set up as a logical volume group1. The volume group contains several logical volumes like root
, home
(the one I'm interested in adding more space to), and swap
. By default, Fedora uses swap space when it's available, and since swap
is being used, the partition is locked. So I had to turn off swap and unmount the partition:
swapoff -a umount /dev/fedora/swap
And now I'm able to extend it! Phew!
After GParted finished resizing the partitions, I rebooted and…disaster! After being stuck on the logo for what seemed like an eternity, Fedora dropped into a dracut
console and complained that
Warning: /dev/fedora/swap does not exist
Turns out that by turning off swap and resizing the partition, I'd gotten rid of the swap volume altogether!
OK, no need to panic. After exit
from dracut
, Fedora was able to reboot. A look at the System Monitor, though, confirmed that no swap space was being used. This is a real bummer for performance, so I had to add the swap space back.
The easiest way to do this was to create a logical volume with the same name as the old one so that I didn't need to modify /etc/fstab
. Fortunately, the internet is full of good tutorials on how to do this:
sudo lvcreate -L 8G -n swap fedora sudo mkswap /dev/fedora/swap sudo swapon -va
Great! I've got swap space back.
A look at df -h
, however, showed that /dev/mapper/fedora-home
hadn't actually increased in size. Even though we'd increased the size of the volume group, we hadn't specified that the space should be used by a logical volume and file system. So it's off to the internet again to figure out how to do that:
sudo lvextend -l +100%FREE /dev/fedora/home # to use all the free space in the volume group sudo resize2fs /dev/fedora/home # since the volume is ext4
Finally! I've enough disk space to work with my VMs without running into DISK_FULL
errors.
Footnotes:
This is the default for new Fedora installations, though in my case it's not really necessary, as I only have one hard drive.