• 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. tracepath Command Examples in Linux
  2. kpackagetool5: command not found
  3. How to Create a Bridge Interface Using nmcli in CentOS/RHEL 7 and 8
  4. dnf Command Examples
  5. How to configure AD group in sudoers file to provide sudo access to users on Linux system
  6. How to truncate /var/log/lastlog File
  7. Defining System Jobs Using Cron under Linux
  8. Unable to Start RDMA Services on CentOS/RHEL 7
  9. asterisk Command Example
  10. What is the purpose of “wheel” group in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright