Home / How to convert a standard partitioned system to LVM?

How to convert a standard partitioned system to LVM?

When you add a new device to the server, you need to partition it up. You only need two of them. This will make a 1GB device for /boot and use the rest for LVM.

# fdisk /dev/<new_dev>
Command: n
Primary?: p
Number: 1
Start: <enter>
End: 1G
Command: n
Primary?: p
Number: 2
Start: <enter>
End: <enter>

Install LVM on the <new_dev>2. This will make a 1G swap and give the rest to /. This will change depending on where you are. You might need to make more LVs if you want /var or /usr to be on different drives.

 # pvcreate /dev/<new_dev>2
# vgcreate vg_root /dev/<new_dev>2
# lvcreate -n lv_swap vg_root -L 1G
# lvcreate -n lv_root vg_root -l 100%FREE

Create the file-systems for /boot and / (and any other devices you may have created), and enable swap

 # mkfs.ext4 /dev/<new_dev>1
# mkfs.ext4 /dev/vg_root/lv_root
# mkswap /dev/vg_root/lv_swap

Set up a temporary environment under /mnt and copy the files (be sure to create any other mounts you need and mount the OS related LVs there)

 # mount /dev/vg_root/lv_root /mnt
# mkdir /mnt/boot
# mkdir /mnt/proc
# mkdir /mnt/sys
# mkdir /mnt/dev
# mount /dev/<new_dev>1 /mnt/boot
# cp -vax / /mnt/
# cp -vax /boot /mnt/

Go into the new temporary setting. This will trick your console into thinking you are now in the new environment.

 # mount -o bind /proc /mnt/proc
# mount -o bind /dev /mnt/dev
# mount -o bind /sys /mnt/sys
# choot /mnt

Rebuild the initial ramdisk.

 # dracut -f

Update the “kernel” line in /boot/grub/grub.conf file with the following.

 * set the root= parameter to /dev/vg_root/lv_root
* remove rd_NO_LVM
* add rd_LVM_LV=vg_root/lv_root

Make a file under /boot so that grub can find it.

 # touch /boot/testfile

Type grub and look for the file. This will give you a value of (hdX,X).

 grub> find /testfile

Use the value from the above command and reinstall grub.

 grub> root (hdX,X)
grub> setup (hdX)
grub> quit

Update your /etc/fstab with the new locations to your devices.

Turn off the computer and get rid of the old disks. Start up again and make sure everything works right.

Leave a Reply