I was testing Fedora 20 inside a KVM guest this week when the disk space run out. The system was configured to use Btrfs filesystem and this is how to extend it.
First you have to extend the underlying guest storage. On the host I'm using LVM so this is a no brainer:
# pvs
PV VG Fmt Attr PSize PFree
/dev/mapper/luks-f3f6cea1-baba-4aaf-bca8-33a0ec540369 vg_redbull_mini lvm2 a-- 289,11g 134,11g
# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
vm_fedora vg_redbull_mini -wi-ao--- 15,00g
# lvextend -L +5G /dev/mapper/vg_redbull_mini-vm_fedora
Extending logical volume vm_fedora to 20,00 GiB
Logical volume vm_fedora successfully resized
# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
vm_fedora vg_redbull_mini -wi-ao--- 20,00g
# pvs
PV VG Fmt Attr PSize PFree
/dev/mapper/luks-f3f6cea1-baba-4aaf-bca8-33a0ec540369 vg_redbull_mini lvm2 a-- 289,11g 129,11g
On the VM we have a default Btrfs layout:
# blkid
/dev/vda1: UUID="410ee563-e701-42ff-9d5f-5805dd103e35" TYPE="ext4" PARTUUID="0000330f-01"
/dev/vda2: UUID="f4addad4-a0fc-482e-ad5a-240864b76f09" TYPE="swap" PARTUUID="0000330f-02"
/dev/vda3: LABEL="fedora" UUID="f0b589ce-061c-4ac3-826e-7f3f8c8a6d30" UUID_SUB="11aa8414-3ce1-4fe7-a506-9a4f91ba5c30" TYPE="btrfs" PARTUUID="0000330f-03"
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda3 13G 11G 1.4G 89% /
devtmpfs 996M 0 996M 0% /dev
tmpfs 1002M 80K 1002M 1% /dev/shm
tmpfs 1002M 668K 1002M 1% /run
tmpfs 1002M 0 1002M 0% /sys/fs/cgroup
tmpfs 1002M 16K 1002M 1% /tmp
/dev/vda3 13G 11G 1.4G 89% /home
/dev/vda1 477M 72M 376M 17% /boot
Now power-off (not reboot) and power-on the VM guest so that it sees the new size of the underlying storage. See the fdisk header (line 9 below), vda is now 20GiB!
Before extending the filesystem you have to extend the underlying disk partition! This is the trickiest part. Using fdisk or parted you have to delete the partition and add it again. Make sure to use the SAME starting sector for the new partition (line 33)!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
See lines 36 and 49 above. The new partition has a greater size. After reboot just resize the filesystem and verify the new space has been added
# btrfs filesystem resize max /
Resize '/' of 'max'
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda3 18G 11G 6.4G 63% /
devtmpfs 996M 0 996M 0% /dev
tmpfs 1002M 80K 1002M 1% /dev/shm
tmpfs 1002M 660K 1002M 1% /run
tmpfs 1002M 0 1002M 0% /sys/fs/cgroup
tmpfs 1002M 16K 1002M 1% /tmp
/dev/vda3 18G 11G 6.4G 63% /home
/dev/vda1 477M 72M 376M 17% /boot
This is it, more disk space available for the virtual machine. Let me know how it works for you.
Comments !