Resizing Ubuntu Root with LVM
Ok, I needed to do this, and for some reason was having a difficult time figuring out exactly how to do it and after hours of searching one of my co-workers found a writeup for how to expand the root file system on Ubuntu if you add an additional drive and want to utilize LVM. The document was ok, and correct, but I wanted to write it down again in case some other person out there is looking for it. So this will be a cleaner more simplified version.
For this example, lets assume /dev/sdb is your new hard disk.
Step 1: Fdisk the new hard disk.
fdisk /dev/sdbi. Type “n” to create a new partition,
ii. then “p” to select to create a primary partition,
iii. then “1″ for the partition number,
iv. then “1″ to start from the first cylinder,
v. for the last cylinder I just pressed enter for the default max size. You can enter whatever you want here.
vi. Type “t” to set the partition’s system id. Then “8e” to set the partition for LVM.
Finally type “w” to write the changes to the disk.
Step 2: Fdisk to verify.
fdisk -l
Step 3: We create the physical volume (PV) for the new partition.
pvcreate /dev/sdb1
Step 4: I’m adding a PV to en existing Volume Group (VG), so I’ll just do a “vgextend”. My group name is Ubuntu, yours may be different.
vgextend Ubuntu /dev/sdb1
Step 5: Display so you can see how much free space you have, when you do this extend, be careful in the calculation of how much free space you think you have. You can calculate this by running vgdisplay and multiply FREE PE x PE SIZE. The following code displays the params, while lvextend actually extends the logical drive /dev/Ubunut/root by 145G.
vgdisplay
lvextend -L+145G /dev/Ubuntu/root
Step 6: Resize the filesystem. This gets a bit tricky, as you cannot resize the root file system because your mounted to it, and no you cant unmount the root so don’t ask. The trick is to boot Knoppix 5.1> from CD at the prompt type knoppix 2, which is to a command prompt. Knoppix does not mount LVM drives, so you will have to manually do this by following the commands listed below. vgchange -a y basically means change the attributes ‘availability’ to ‘yes’, and being you don’t specify which, it does it for them all.
vgchange -a y
resize2fs -f /dev/Ubuntu/root
Step 7: Reboot back into Ubuntu and your done.
Big thanks to Gerard Setho who posted the original version of this.
12 Sep 2007 vMonkey comments off