How to extend the volume (Linux)?
It is possible to extend the Volume from Horizon dashboard.
Another method is to create a new volume, attach it to the VM, copy all the data from the old volume to the new one, check if the data is properly copied, then detach and delete the old one. Not all filesystems are resizable.
You may use following guide to backup the volume:
Resizing the volume:
In this tutorial we will resize 1GB volume to 5GB.
First we need to extend the volume in Horizon.
Lets say that we have 1GB volume attached to our instance as /dev/vdb
And we have it mounted in our Linux machine as /dev/vdb1
# df -kh Filesystem Size Used Avail Use% Mounted on udev 478M 0 478M 0% /dev tmpfs 100M 11M 89M 11% /run /dev/vda1 7.8G 5.2G 2.3G 70% / tmpfs 497M 0 497M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 497M 0 497M 0% /sys/fs/cgroup tmpfs 100M 0 100M 0% /run/user/1001 /dev/vdb1 991M 322M 603M 35% /mnt/vol2
We already have some data on it, we don't want to lose.
First we need to unmount it in Linux:
# umount /dev/vdb1
Then detach it in Horizon by clicking "Manage Attachments" > "Detach Volume"
After detaching we will have "Extend Volume" option available.
We enter new size, for example 5GB and click "Extend Volume"
Our new volume size is now 5GB.
Attach it to your Virtual Machine again.
Now we need to extend our /dev/vdb partition in Linux.
Expand the modified partition using growpart (and note the unusual syntax of separating the device name from the partition number):
# growpart /dev/vdb 1
Next use resize2fs:
# resize2fs /dev/vdb1 resize2fs 1.42.13 (17-May-2015) Please run 'e2fsck -f /dev/vdb1' first.
Most of the time a filesystem check will be recommended by the system.
# e2fsck -f /dev/vdb1 e2fsck 1.42.13 (17-May-2015) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vdb1: 41/65536 files (31.7% non-contiguous), 90414/261888 blocks
After doing e2fsck we proceed with extending partition:
# resize2fs /dev/vdb1 resize2fs 1.42.13 (17-May-2015) Resizing the filesystem on /dev/vdb1 to 1310459 (4k) blocks. The filesystem on /dev/vdb1 is now 1310459 (4k) blocks long.
We can now mount our extended volume again.
# mount /dev/vdb1 /mnt/vol2
# df -kh Filesystem Size Used Avail Use% Mounted on udev 478M 0 478M 0% /dev tmpfs 100M 11M 89M 11% /run /dev/vda1 7.8G 5.2G 2.3G 70% / tmpfs 497M 0 497M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 497M 0 497M 0% /sys/fs/cgroup tmpfs 100M 0 100M 0% /run/user/1001 /dev/vdb1 5.0G 322M 4.4G 7% /mnt/vol2
The new size is now 5GB and the data that were previously there are intact.