Expanding the drive on a live Linux system
This assumes that you are running your Linuxsystem as a virtual server on VMWare, KVM, XEN or AHV.
Be sure to take a backup first!
It is quite common – for me atleast – that a busy databaseserver is going to use more and more space. And in most cases it is not always that attractive to have to restart the server and resize it with a LiveCD such as gparted live.
Luckily, there is possible to expand the partitions while your machine is running. I will try to guide you with this step to step guide on how you can successfully proceed with it:
If you are using LVM, read until 12, and skip 13.
- First of all, add the storage in you hypervisor.
- Next, you want to tell the kernel that to rescan the bulk device:
echo 1 > /sys/class/block/sda/device/rescan
fdisk are now able to “see” the expanded disk, in this case/dev/sda
- Now, we need to do the actual expansion of the partinion, so we need to “delete” the partion and add it again via fdisk – dont worry, we are not going to write the changes to disk while the partinion is deleted:
fdisk /dev/sda
- Just to make sure, check the partinion by selecting
p
, if the disk looks like it should, you may continue - Delete the partition by pressing
d
- Press
n
to create a new partinion - Press
p
to chose “Primary Partition” - Press
1
to chose the partition number 1 - Press
ENTER
twice - And lastly, doublecheck the changes by pressing
p
, note the difference from the first time you did it. You should see that the partition has been expanded. - !The following actions will write the changes to disk!
Now, in order to make is real, press
w
in order to write the changes to disk, you will see a warning about that the partition table has been changed. Do not worry, it is expected. - Now, run
partprobe
(you have to installparted
for this to work). If you are using an older kernel, you maybe would need to reboot if thepartprobe
task did not work. - Now, we just need to expand the filesystem itself in order to actually use the newly added space:
resize2fs -p /dev/sda1
Verify with df -h
or lsblk
Steps for if you are using LVM
I assume that you have done step 1-12 in the previous section.
- First, expand your physical volume:
pvresize /dev/sda1
- Then, we will proceed with expanding the Logical volume, replace “X1” with the Logical Volume you want to extend:
lvextend --extents +100%FREE /dev/vg0/X1
- After that is done, we have to expand the filesystem, again – replace “X1” with the Logical Volume you want to extend
resize2fs /dev/vg0/X1
Verify with df -h
or lsblk
You should be able to see the new size now.