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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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. What are SELinux Users and how to Map Linux Users to SELinux Users
  2. Understanding rsyslog Templates
  3. CentOS / RHEL : How to rotate /var/log/wtmp and /var/log/btmp file using logrotate
  4. How to disable auto completion (tab completion) in bash shell
  5. RHEL 7 – RHCSA Notes – System documentation including man, info, and files in /usr/share/doc
  6. How to Execute Scripts/Commands using /etc/rc.d/rc.local in CentOS/RHEL 7
  7. What are Shell Scripts? How to Create Shell Scripts?
  8. Server Application Getting “connection refused” From Remote Servers [due to firewalld or iptables] – CentOS/RHEL 7
  9. How to activate and mount 2 Volume groups with same names in CentOS/RHEL
  10. How to Install and Configure Device Mapper Multipath in CentOS/RHEL 6,7

You May Also Like

Primary Sidebar

Recent Posts

  • What are Command Rules in oracle Database
  • Using Rule Sets in Oracle Database Vault
  • How Realms Work in Oracle Database Vault
  • How to use Privilege Analysis in Oracle Database
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary