# LinuxPizza

## Expanding the drive on a live Linux system

#### 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.

1. First of all, add the storage in you hypervisor.
2. 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
3. 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
4. Just to make sure, check the partinion by selecting p, if the disk looks like it should, you may continue
5. Delete the partition by pressing d
6. Press n to create a new partinion
7. Press p to chose “Primary Partition”
8. Press 1 to chose the partition number 1
9. Press ENTERtwice
10. 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.
11. !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.
12. Now, run partprobe (you have to install parted for this to work). If you are using an older kernel, you maybe would need to reboot if the partprobe task did not work.
13. 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.

1. First, expand your physical volume: pvresize /dev/sda1
2. 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
3. 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.