Migrating Physical Volume root to LVM

From Labrats.us
Revision as of 02:04, 22 August 2019 by Sfiggins (talk | contribs)
Jump to navigationJump to search

Expand hard drive

Assuming you are on VMware, you just shut down and increase the virtual hard drive size. You should know how to do this, so I won;t include it here. You may also be able to add a physical or virtual disk.

Create LVM Physical Volume

Using fdisk, add a new partition with type 8e. If possible, leave room between the end of the last existing partition and the new partition.

Using pvcreate, create the physical lvm volume.

# pvcreate /dev/sda4

Create volume group

Using vgcreate, vreate new volume group

# vgcreate VolGroup00  /dev/sda4

Create new logical root volume

Make sure to create the new logical volume the same size as the existing volume. Use lvcreate.

# lvcreate -L 4G -n root VolGroup00

Format the new logical volume

Using mkfs.ext3 or mkfs.ext4. as required by the OS version.

# mkfs.ext3 /dev/VolGroup00/root

Mount new root volume

# mount /dev/VolGroup00/root  /mnt

Begin copy of the data to new volume

You can use tar or you can use rsync. Either seems to work.

# rsync  --archive --sparse --one-file-system --delete-during --delete-excluded \
  --force --numeric-ids --hard-links / /mnt/

OR

# tar -cvpf - --one-file-system --acls --xattrs --selinux / | tar -C /mnt xf -


(Optional) Create new SWAP partition

You likely want to move the SWAP partition to the new VG as well, or you may have trouble further down the instructions. MAke it the same size as your existing SWAP partition. If you don't know what size your existing SWAP is, you can use the swapon command.

# # swapon -s
Filename				Type		Size	Used	Priority
/dev/sda2                              	partition	4194300	155704	-1
# lvcreate -L 4G -n swap VolGroup00
# mkswap /dev/VolGroup00/swap

Copy the /dev partition