So what are the benefits about running a filesystem with LVM.. well for one say you create a normal non-LVM setup with a 20gig home dir. Now over the next few weeks you download so much porn that its filled.. so your option is get a new drive and either move everything to the new drive or do some symlinking. Well if you created your /home partition under a LVM enviroment, you could just grow /home with the new drive and have that extra 400 gigs to download more porn.
IMO that is one of the biggest points to using LVM is it allows you to easily change the size of a partition. With that said you should never make / or /boot LVM.. this just creates evilness.. or so i've read.. So in my example I will have a extra partition I made on my sda drive called sda7 which has no filesystem on it or such
Code:
[root@localhost ~]# fdisk -l
Disk /dev/sda: 80.0 GB, 80000000000 bytes
255 heads, 63 sectors/track, 9726 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 3200 25599577+ 83 Linux
/dev/sda3 3201 5112 15358140 83 Linux
/dev/sda4 5113 9726 37061955 5 Extended
/dev/sda5 5113 5214 819283+ 82 Linux swap
/dev/sda6 5215 5278 514048+ 83 Linux
/dev/sda7 5279 9726 35728528+ 8e Linux LVM
I gave it a system type of LVM.. that is only needed for LVM v1.. most modern distros should ship with v2 now anyway. Ok now lets init that partition
Code:
[root@localhost ~]# pvcreate /dev/sda7
Physical volume "/dev/sda7" successfully created
Now you might get a partition not found error. I ran into this when i just created sda7 using fdisk. The only work around I found out was a reboot. You could also use pvcreate on a whole disk. Like if i had a sdb i could do it on the whole disk. There is no need to do it just on a partition.
Now we need to create out volume group. You might think of this as the extended partition which holds all the extended partitions. That might not be explaining it good enough but oh well..
Code:
[root@localhost ~]# vgcreate volume_group /dev/sda7
Volume group "volume_group" successfully created
Feel free to change volume_group to whatever identifier you want to use. You will notice how its used in a bit.. just hold on!
Ok now lets see if it worked
Code:
[root@localhost ~]# pvdisplay /dev/sda7
--- Physical volume ---
PV Name /dev/sda7
VG Name volume_group
PV Size 34.07 GB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 8722
Free PE 8722
Allocated PE 0
PV UUID i9r7Pt-o8Jl-bhSW-LfCN-lVlW-FPZX-ZYgvyM
Now you can see my pv name is the partition i used..
My volume group is what i used above. and you can see I have around 34gigs of space you allocate. So lets get down to using that all up now
So lets create a logical device for our old lady porn
Code:
[root@localhost ~]# lvcreate -L3000 -nporn_old_lady volume_group
Logical volume "porn_old_lady" created
Now lets create the filesystem. I shall use ext3 here
Code:
mkfs.ext3 /dev/volume_group/porn_old_lady
Now we can mount it
Code:
mount /dev/volume_group/porn_old_lady /dump/
Now lets see it in all its glory
Code:
[root@localhost ~]# df -h | grep dump
2.9G 37M 2.8G 2% /dump
So you can see our size is 2.9gigs and we have used 37megs and we have aroudn 2.8gigs left. So you downloaded a ton of old lady porn and you want to grow your partition.. ok lets do it! Lets say we want to increase it to 7gigs
Code:
[root@localhost ~]# lvextend -L7G /dev/volume_group/porn_old_lady
Extending logical volume porn_old_lady to 7.00 GB
Logical volume porn_old_lady successfully resized
Now if you use ext3 you have to resize it.. so you have to umount it and do some magic
Code:
umount /dump
e2fsck -f /dev/volume_group/porn_old_lady
resize2fs /dev/volume_group/porn_old_lady
mount /dev/volume_group/porn_old_lady /dump/
Now lets check out the new size
Code:
[root@localhost ~]# df -h | grep dump
6.9G 39M 6.6G 1% /dump
Yaya.. more space for old lady porn.. that would make randall happy. You can just see the benefits of using this if you are a hosting company or such. Now there is a ext2online patch you can apply to your kernel so you can resize it while its still mounted. I have never tried it.