• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL : Converting an Existing Root Filesystem to LVM Partition

by admin

Question: Root Filesystem is full and it is not LVM. We need to move this to new partition which is LVM. How this can be achieved?

Answer :
Procedure to convert an existing root file system on a normal disk partition to LVM volume is as follows :

1. First Create an LVM partition:
Select a free disks and create an LVM partition on it.

# pvcreate /dev/sdb1
# vgcreate vg_new_root  /dev/sdb1
# lvcreate -L 4G -n lv0 vg_new_root

2. Format this new LVM partition with ext3 or ext4 (or as needed). The example given below creates aext4 file system :

# mkfs.ext4 /dev/vg_new_root/lv0

3. Create a new mount point and then mount the LVM Partition on it:

# mkdir /mnt/NEW_ROOT_PARTITION
# mount /dev/vg_new_root/lv0  /mnt/NEW_ROOT_PARTITION

4. Copy all contents of “/” to the newly mounted folder:

# tar -cvpf - --one-file-system --acls --xattrs --selinux / | tar -C /mnt/NEW_ROOT_PARTITION -xf
# cp -aux /dev /mnt/NEW_ROOT_PARTITION

5. Now edit the file – /mnt/NEW_ROOT_PARTITION/etc/fstab to reflect the new root:

/dev/vg_new_root/lv0      /       ext4    defaults     1 1

6. Now it is needed to chroot to new filesystem and create initrd with raid and lvm support:

# mount --bind /dev /mnt/NEW_ROOT_PARTITION
# chroot /mnt/NEW_ROOT_PARTITION
# mount -t proc /proc /proc
# mount -t sysfs /sys /sys
# vgscan
# vgchange -ay
# mkinitrd -v /boot/initrd-`uname -r`.lvm.img `uname -r`
# umount /sys
# umount /proc
# exit
# mv /mnt/lv0/boot/initrd-`uname -r`.lvm.img /boot

7. Edit /boot/grub/grub.conf to point to new root /dev/vg_new_root/lv0. Backup the old initrd in “/boot” directory and rename the new initrd to the existing one or edit the entry in grub.conf.

8. Reboot

# shutdown -r now

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to enable Debug Option For CIFS Module in CentOS/RHEL 7 and 8
  2. setpci command – configure PCI device
  3. How to move /tmp on a separate disk as a separate mount point (Online)
  4. cut Command Examples in Linux
  5. How to use the ssh-keygen Command in Linux
  6. raspistill: command not found
  7. bspc Command Examples in Linux
  8. Installing Security Vulnerabilities with yum on CentOS/RHEL 5,6,7 (Cheat Sheet)
  9. which: command not found
  10. apt-key Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright