Difference between revisions of "Migrating Physical Volume root to LVM"
Line 9: | Line 9: | ||
Using pvcreate, create the physical lvm volume. | Using pvcreate, create the physical lvm volume. | ||
− | < | + | <pre> |
− | # pvcreate /dev/ | + | # pvcreate /dev/sda4 |
− | </ | + | </pre> |
+ | == Create volume group == | ||
− | < | + | Using vgcreate, vreate new volume group |
− | ---- | + | |
− | + | <pre> | |
+ | # vgcreate VolGroup00 /dev/sda4 | ||
+ | </pre> | ||
+ | |||
+ | == Create new logical root volume == | ||
+ | |||
+ | Make sure to create the new logical volume the same size as the existing volume. Use lvcreate. | ||
+ | |||
+ | <pre> | ||
+ | # lvcreate -L 4G -n root VolGroup00 | ||
+ | </pre> | ||
+ | |||
+ | == Format the new logical volume == | ||
+ | |||
+ | Using mkfs.ext3 or mkfs.ext4. as required by the OS version. | ||
+ | |||
+ | <pre> | ||
+ | # mkfs.ext3 /dev/VolGroup00/root | ||
+ | </pre> | ||
+ | |||
+ | == Mount new root volume == | ||
+ | |||
+ | <pre> | ||
+ | # mount /dev/VolGroup00/root /mnt | ||
+ | </pre> | ||
+ | |||
+ | == Begin copy of the data to new volume == | ||
+ | |||
+ | You can use tar or you can use rsync. Either seems to work. | ||
+ | |||
+ | <pre> | ||
+ | # rsync --archive --sparse --one-file-system --delete-during --delete-excluded \ | ||
+ | --force --numeric-ids --hard-links / /mnt/ | ||
+ | </pre> | ||
+ | |||
+ | OR | ||
+ | |||
+ | <pre> | ||
+ | # tar -cvpf - --one-file-system --acls --xattrs --selinux / | tar -C /mnt xf - | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | ==(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. | ||
+ | |||
+ | <pre> | ||
+ | # # swapon -s | ||
+ | Filename Type Size Used Priority | ||
+ | /dev/sda2 partition 4194300 155704 -1 | ||
+ | </pre> | ||
+ | |||
+ | <pre> | ||
+ | # lvcreate -L 4G -n swap VolGroup00 | ||
+ | # mkswap /dev/VolGroup00/swap | ||
+ | </pre> | ||
+ | |||
+ | == Copy the /dev partition == |
Revision as of 02:04, 22 August 2019
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