Adding more space to Linux Volume (Ubuntu Server 16.04)
This is probably quite specific to my server setup, noted for future reference. If you aren't using LVM, or have multiple Logical Volumes on your Volume Groups then it might not work so smoothly...
My server is set up with a couple of Volume Groups (removed some of the less interesting info, but seems notable that both are resizable)
$ sudo vgdisplay
--- Volume group ---
VG Name chipshop-os
Format lvm2
VG Status resizable
VG Size 110.81 GiB
PE Size 4.00 MiB
Total PE 28367
Alloc PE / Size 7328 / 28.62 GiB
Free PE / Size 21039 / 82.18 GiB
--- Volume group ---
VG Name chipshop-data
Format lvm2
VG Status resizable
VG Size 3.64 TiB
PE Size 4.00 MiB
Total PE 953861
Alloc PE / Size 655360 / 2.50 TiB
Free PE / Size 298501 / 1.14 TiB
Each Volume group has Logical Volumes defined as follows:
$ sudo lvdisplay
--- Logical volume ---
LV Path /dev/chipshop-vg/root
LV Name root
VG Name chipshop-os
LV Size 24.73 GiB
--- Logical volume ---
LV Path /dev/chipshop-vg/swap_1
LV Name swap_1
VG Name chipshop-os
LV Size 3.89 GiB
--- Logical volume ---
LV Path /dev/chipshop-data/chipshop-media
LV Name chipshop-media
VG Name chipshop-data
LV Size 2.50 TiB
Used disk space can be easily viewed with the command
$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.8G 0 3.8G 0% /dev
tmpfs 769M 9.1M 760M 2% /run
/dev/mapper/chipshop--vg-root 25G 14G 9.7G 59% /
tmpfs 3.8G 12K 3.8G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/sda2 473M 177M 273M 40% /boot
/dev/sda1 511M 3.4M 508M 1% /boot/efi
/dev/mapper/chipshop--data-chipshop--media 2.5T 2.3T 61G 98% /data/media
tmpfs 769M 0 769M 0% /run/user/1000
I can see that /data/media is limited on space, so I can extend the Logical Volume using the command
$sudo lvextend --size +75G /dev/chipshop-data/chipshop-media
Size of logical volume chipshop-data/chipshop-media changed from 2.52 TiB (661760 extents) to 2.60 TiB (680960 extents).
Logical volume chipshop-media successfully resized.
Assuming this all goes smoothly resize2fs can be used to extend the partition to the full size of the logical volume.
$ sudo resize2fs /dev/chipshop-data/chipshop-media
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/chipshop-data/chipshop-media is mounted on /data/media; on-line resizing required
old_desc_blocks = 162, new_desc_blocks = 167
The filesystem on /dev/chipshop-data/chipshop-media is now 697303040 (4k) blocks long.
Size can then be checked again with df -h
- now showing the new size "/dev/mapper/chipshop--data-chipshop--media 2.6T 2.4T 131G 95% /data/media"