My trusted Ubuntu server ran out of space (again), and again it was the root partition. Luckily, I chose LVM this time during installation...
First, add more space to the volume in ESXi using vSphere client. That was
Next, login to the server, and start extending...
Scan for added space
First, you need to make the server notice the extra space. In order to do
that, use this command:
echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scan
Where host0, host1, host2 is depending on the number of hosts
on the machine. Use this command to find out:
Verify by calling fdisk -l, the disk should now have grown to
the given size.
Note: If you're adding a new disk instead of growing an existing, you probably need to reboot (at least I did).
Create new partition
Start fdisk, parted or cfdisk to create a new partition. For
some reason, both fdisk and parted refused to let me use all the
available space, so I ended up using cfdisk.
Use partition type 8e (Linux LVM extended).
Create a new physical partition using pvcreate (here using sda3):
Verify by calling lvdisplay. The partition should be listed as unused.
Extended the logical disk
Find the name of the logical disk, and use vgextend
vgextend replicant-vg /dev/sda3
Expand the logical volume
Expand the logical volume (the name is root, and the size was increased by
lvextend -L+10G /dev/replicant-vg/root
Resize the logical volume to use the new space:
resize2fs -f /dev/replicant-vg/root
Test by using vgdisplay, the output should be along these lines:
--- Volume group ---
VG Name replicant-vg
Metadata Areas 4
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 4
Act PV 4
VG Size 59.75 GiB
PE Size 4.00 MiB
Total PE 15296
Alloc PE / Size 15292 / 59.73 GiB
Free PE / Size 4 / 16.00 MiB
VG UUID 7TprTS-t9Yq-nCy1-D26a-IWAl-f7BG-bZaSqr
Check the new partition by calling df -h:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/replicant--vg-root 39G 23G 15G 62% /
Ah, lots of space again!