move to lvm usage

Add new disk

I forgot to do this the first time, and was just using the device without a partition. This does not work :)

fdisk -l

See the new disk then

 fdisk /dev/<NEWDISK>
 n
 p
 1
 <return>

View using

 p

If OK

 w

We now have a partition

Then

  • boot machine

Create Physical Group

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.

Run Level Change the run level - on RHEL reboot press a key in Grub, go to the kernel like. Press e and add 1 at the end of the line.

Then Press b

5

Copy old partition

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

You may also be able to do this using rsync - but I used tar.

6

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

/dev/vg_new_root/lv0      /       ext4    defaults     1 1

7

new command for me chroot, looks useful for jailshells etc

 mount --bind /dev /mnt/NEW_ROOT_PARTITION
 chroot /mnt/NEW_ROOT_PARTITION
 mount -t proc /proc /proc
 mount -t sysfs /sys /sys   

chroot did cause a lot of issues.

8

Other stuff

Show lv

lvs

Remove a lv

lvremove /dev/vg_dev_root/lv0