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 LVMI 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.imgAfter 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
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 4 to 8e (Unknown)
Command (m for help): w
#partprobe
# vgscan
# pvcreate /dev/sda3
# vgcreate vg0 /dev/sda3
# lvcreate -L 24G -n lvroot0 vg0
# mke2fs -j /dev/vg0/lvroot0
# mount /dev/vg0/lvroot0 /mnt
# yum update kernel
# find / -xdev | cpio -pvmd /mnt
Note: 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.ELsmp.img | cpio -id
# ls -al bin/lvm
-r-x------ 1 root root 1417512 May 24 14:38 bin/lvm
If 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.img 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.imgReboot, and enjoy the flexibility of lvm!!
lvm-logical-volume-manager
Try this url, helped me a lot
http://www.redhatlinux.info/2010/11/lvm-logical-volume-manager.html
Some of the steps not working in Debian
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-filesystem-to-lvm-in-debian/
sorry forgot to
sorry forgot to say
excellent guide thank you so much. It was exactly what I needed
cheers
Paul
/bin/bash permission denied accessing ssh after first reboot
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