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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • 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. ioping: command not found
  2. How to change the default permissions on /var/log/audit/audit.log file in CentOS/RHEL
  3. How to resolve the error “-bash: xclock: command not found” in CentOS / RHEL
  4. dunstify Command Examples in Linux
  5. How to uninstall Ansible software package in Ubuntu
  6. “shutdown” Command Examples in Linux
  7. terminator Command Examples in Linux
  8. Mutt, Mail and Telnet – Send mails from linux command line or terminal
  9. How to log every shell command in Linux
  10. How to install rsyslog7 when rsyslog5 is already installed in CentOS/RHEL

You May Also Like

Primary Sidebar

Recent Posts

  • gml2gv Command Examples
  • glow Command Examples
  • glib-compile-resources Command Examples
  • glances Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright