Friday, March 18, 2011

Stuffing around with LVM on ubuntu

A while ago I installed Ubuntu and went a bit nuts with my partition table with separate partitions for /var /home /tmp etc. etc. I also setup raid and LVM with the intention of having a raid 1 backup partition and a logical volume for myth tv.

One of the results of this was that I didn't put enough space on /home which I have been working around by creating symlinks and directories that live in the large LVM partition I setup for myth tv. My plan to fix this is to remove one of the physical volumes from the myth LVM, create a new volume group for home and move my data into this group. I could create one big volume group with two logical volumes for home and myth data but I wanted to try creating a group from scratch.

This has been irking me for a while so I am finally going to fix it, below is what i ended up doing:

Removing a physical volume from the lvm group

As I used JSF for the format of the logical volume I couldn't reduce the size of the file system so I ended up just running
lvreduce --size 148G /dev/mapper/mythLVMGroup-mythData
which would have the result of losing any data that happened to be in the rest of the volume, I then reformatted it with
mkfs.jfs /dev/mapper/mythLVMGroup-mythData
at this point I could then modify the logical volume by removing the device from the group:
pvmove /dev/sdb8
lvreduce --size 148G /dev/mapper/mythLVMGroup-mythData
pvmove is rather slow so I started writing this post whilst I waited for that to complete. I should have just used the -A n flag as I had deleted the data prior to doing this anyway, also as there was no data it failed. One side result of this was the UUID of the device changed (not sure if was the mkfs or the change to the lvm) so I had to update my /etc/fstab with the new id which I found by running
ls -la /dev/disk/by-uuid/
After this I remove the physical volume from the group:
vgreduce mythLVMGroup /dev/sdb8
At which point I have completed my first step of removing and resizing the mythtv volume.

Setting up the volume group
There are plenty of other guides around about setting up LVM etc. but here is what I ended up doing:
Create the volume group from two partitions:
vgcreate -s 32M homeLVMGroup /dev/sdb1 /dev/sdb8
then create the logical volume:
lvcreate --size 259G -n home_lv homeLVMGroup
now to format it
mkfs.ext4 /dev/homeLVMGroup/home_lv
at which point I mounted it, copied my old home files across and then edited fstab to mount it as home when I rebooted. I did make one stupid mistake here where I had formatted it as ext4 but then had the fstab entry as ext3!

References
I mainly used the following two pages and google to help me get this working:
http://www.walkernews.net/2007/07/02/how-to-create-linux-lvm-in-3-minutes/ 
http://tldp.org/HOWTO/LVM-HOWTO/reducelv.html

badness = 10000

Well I have been meaning to setup a blog for a couple of years now and am finally getting around to it.

The title of the blog is taken from the error messages that LaTeX produces when it runs into trouble formatting, for some reason I always found this error message amusing.