I converted root filesystem to lvm since the root partition was huge and I needed more flexibility in managing the partitions. Besides, lvm would also enable for easy backups with lvm snapshots.
I had a sizable swap partition of 2GB which I used to transfer my root files to and rebooted to it, prior to the conversion.
Please know what you are doing prior and make sure to create backups.
- 
This is what the partitions looked like prior to the change:
 
# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 228G 1.4G 215G 1% / /dev/sda1 99M 17M 77M 19% /boot none 1014M 0 1014M 0% /dev/shm # fdisk -l Disk /dev/sda: 250.0 GB, 250000000000 bytes 255 heads, 63 sectors/track, 30394 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 267 2040255 82 Linux swap /dev/sda3 268 30394 241995127+ 83 LinuxWith the current setup, I have a better sized partition, and can further create/resize partitions to add or remove at will:
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg0-lvroot0
                       24G  1.3G   22G   6% /
/dev/sda1              99M   19M   75M  21% /boot
none                 1014M     0 1014M   0% /dev/shm
# fdisk -l
Disk /dev/sda: 250.0 GB, 250000000000 bytes
255 heads, 63 sectors/track, 30394 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         267     2040255   83  Linux swap
/dev/sda3             268       30394   241995127+  8e  Linux LVM
I had a sizable swap partition of 2GB, so I turned it off.# swapoff -a# mke2fs -j /dev/sda2
# mount /dev/sda2 /mnt/
# find / -xdev | cpio -pvmd /mnt/dev/sda2 / ext3 defaults 1 1Add a grub section to use "/dev/sda2" as the new root.
title CentOS (2.6.9-55.0.9.ELsmp.sda2)
        root (hd0,0)
        kernel /vmlinuz-2.6.9-55.0.9.ELsmp ro root=/dev/sda2
        initrd /initrd-2.6.9-55.0.9.ELsmp.img 
After reboot the original root (/dev/sda3) is no longer mounted and is free to work with.
Change the partition type from Linux to LVM (8e).
       # fdisk /dev/sda
    &nbs p; Command (m for help): t
    &nbs p; Partition number (1-4): 3
    &nbs p; Hex code (type L to list codes): 8e
    &nbs p; Changed system type of partition 4 to 8e (Unknown)
    &nbs p; Command (m for help): w       #partprobe       # vgscan       # pvcreate /dev/sda3   &nb sp;    &nb sp;         # vgcreate vg0 /dev/sda3       # lvcreate -L 24G -n lvroot0 vg0       # mke2fs -j /dev/vg0/lvroot0
    &nbs p; # mount /dev/vg0/lvroot0 /mnt
    &nbs p; # yum update kernel
    &nbs p; # find / -xdev | cpio -pvmd /mntNote: At this stage, instead of creating a new image, I update the kernel so that the new image supports lvm. LVM support can also be checked via extracting the initrd image file and checking for lvm binary in the bin folder.
# mkdir -p /tmp/kill/00
# cd /tmp/kill/00
# gunzip < /boot/initrd-2.6.9-55.0.9.ELsm p.img | cpio -id
# ls -al bin/lvm
-r-x------ 1 root root 1417512 May 24 14:38 bin/lvmIf image does not have the lvm binary, create and move it to the /boot folder.
# chroot /mnt
# mount -t proc /proc /proc
# mount -t sysfs /sys /sys
# vgmknodes -v
# mkinitrd -v initrd-2.6.9-55.0.9.ELsmp.lv.i mg 2.6.9-55.0.9.ELsmp/dev/vg0/lvroot0 / ext3 defaults 1 1Add grub section to use "/dev/vg0/lvroot0" to boot to.
title CentOS (2.6.9-55.0.9.ELsmp.lvroot0)
        root (hd0,0)
        kernel /vmlinuz-2.6.9-55.0.9.ELsmp ro root=/dev/vg0/lvroot0
        initrd /initrd-2.6.9-55.0.9.ELsmp.lv. img
Reboot, and enjoy the flexibility of lvm!!
- sandip's blog
 - Login or register to post comments
 
Comments
Try this url, helped me a lot 010/11/lvm-logical-volume-mana ger.html
http://www.redhatlinux.info/2
I found that, putting:
/dev/vg0/lvroot0 / ext3 defaults 1 1
in steps 16 doesn't work.
I need to put /dev/mapper/vg0-lvroot0 instead.
Also, there is not mkinitrd in Debian.
Anyway, I worked that out, and put that step by step in the following site. Thank you very much for your information though. They are really very helpful.
http://www.voofie.com/content/ 13/converting-existing-root-fi lesystem-to-lvm-in-debian/
sorry forgot to say
excellent guide thank you so much. It was exactly what I needed
cheers
Paul
Thought I'd add this in as it tripped me up for a while
If you follow this guide ensure you have selinux disabled
vi /etc/sysconfig/selinux
set to
SELINUX=disabled
Otherwise you'll get the error above and it won't work