OS Migration Across Local Disks - Oracle Linux 8
Host has 1 disk with 2 partitions (/boot and / of type xfs).
Adding another disk of same size.
[root@oraclevm ~]# fdisk -l | grep -i disk | grep -i dev
Disk /dev/nvme0n1: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk /dev/nvme0n2: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk /dev/mapper/ol-root: 17 GiB, 18249416704 bytes, 35643392 sectors
Disk /dev/mapper/ol-swap: 2 GiB, 2147483648 bytes, 4194304 sectors
[root@oraclevm ~]#
Existing OS:
[root@oraclevm ~]# df -TH | grep -i xfs
/dev/mapper/ol-root xfs 19G 5.6G 13G 31% /
/dev/nvme0n1p1 xfs 1.1G 311M 754M 30% /boot
[root@oraclevm ~]#
Format the new disk in the same layout as 1st disk: /dev/nvme0n1:
[root@oraclevm ~]# fdisk -l /dev/nvme0n1
Disk /dev/nvme0n1: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1c2f4a7c
Device Boot Start End Sectors Size Id Type
/dev/nvme0n1p1 * 2048 2099199 2097152 1G 83 Linux
/dev/nvme0n1p2 2099200 41943039 39843840 19G 8e Linux LVM
[root@oraclevm ~]#
[root@oraclevm ~]# fdisk /dev/nvme0n2
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/nvme0n2: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x25d7b68c
Device Boot Start End Sectors Size Id Type
/dev/nvme0n2p1 2048 2099199 2097152 1G 83 Linux
/dev/nvme0n2p2 2099200 41943039 39843840 19G 83 Linux
Command (m for help):
Edit the "boot" flag on /dev/nvme0n2p1:
Command (m for help): a
Partition number (1,2, default 2): 1
The bootable flag on partition 1 is enabled now.
Command (m for help): p
Disk /dev/nvme0n2: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x25d7b68c
Device Boot Start End Sectors Size Id Type
/dev/nvme0n2p1 * 2048 2099199 2097152 1G 83 Linux
/dev/nvme0n2p2 2099200 41943039 39843840 19G 83 Linux
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@oraclevm ~]#
Lets migrate /boot first to the new disk and boot it.
Existing OS is created based on LVM but I am going to copy it as standard partiton.
/boot migration:
Format the partition as "xfs".
[root@oraclevm ~]# mkfs.xfs /dev/nvme0n2p1
[root@oraclevm ~]# mount /dev/nvme0n2p1 /tmp_boot
[root@oraclevm ~]# df -TH /tmp_boot
Filesystem Type Size Used Avail Use% Mounted on
/dev/nvme0n2p1 xfs 1.1G 42M 1.1G 4% /tmp_boot
[root@oraclevm ~]#
I am using xfsdump and xfsrestore for data copy.
[root@oraclevm ~]# xfsdump -f /tmp/boot.img /boot
[root@oraclevm ~]# xfsrestore -f /tmp/boot.img /tmp_boot/
Repeat the same for root (/):
[root@oraclevm default]# mkfs.xfs /dev/nvme0n2p2
[root@oraclevm /]# mkdir /tmp_os
[root@oraclevm /]# mount /dev/nvme0n2p2 /tmp_os
[root@oraclevm /]# df -TH /tmp_os
Filesystem Type Size Used Avail Use% Mounted on
/dev/nvme0n2p2 xfs 21G 12G 9.1G 56% /tmp_os
[root@oraclevm /]#
[root@oraclevm /]# blkid | grep -i "/dev/nvme0n2"
/dev/nvme0n2p1: UUID="bb83e8cd-16ad-4aff-a3f4-4a9505d9b5ca" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="25d7b68c-01"
/dev/nvme0n2p2: UUID="35e305ec-c8d4-40f9-a9e8-98dc3b27f565" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="25d7b68c-02"
/dev/nvme0n2: PTUUID="25d7b68c" PTTYPE="dos"
[root@oraclevm /]#
Lets update GRUB_CMDLINE_LINUX and GRUB_ENABLE_BLSCFG=false in /etc/default/grub. This will prevent GRUB from recreating new GRUB configuration during boot.
Old entry: GRUB_CMDLINE_LINUX="resume=/dev/mapper/ol-swap rd.lvm.lv=ol/root rd.lvm.lv=ol/swap rhgb quiet"
[root@oraclevm /]# blkid | grep -i "/dev/nvme0n2"
/dev/nvme0n2p1: UUID="bb83e8cd-16ad-4aff-a3f4-4a9505d9b5ca" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="25d7b68c-01"
/dev/nvme0n2p2: UUID="35e305ec-c8d4-40f9-a9e8-98dc3b27f565" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="25d7b68c-02"
/dev/nvme0n2: PTUUID="25d7b68c" PTTYPE="dos"
[root@oraclevm /]#
[root@oraclevm /]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=false
[root@oraclevm /]#
Once updated, Re-Create GRUB.
[root@oraclevm /]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.17-2136.307.3.1.el8uek.x86_64
Found initrd image: /boot/initramfs-5.4.17-2136.307.3.1.el8uek.x86_64.img
Found linux image: /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64
Found initrd image: /boot/initramfs-4.18.0-372.9.1.el8.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-e9ce9a3dac2048a8bab69e64e6f64d92
Found initrd image: /boot/initramfs-0-rescue-e9ce9a3dac2048a8bab69e64e6f64d92.img
Found Oracle Linux Server 8.6 on /dev/nvme0n2p2
done
[root@oraclevm /]#
Install GRUB on /dev/nvme0n2.
[root@oraclevm /]# grub2-install /dev/nvme0n2
Installing for i386-pc platform.
Installation finished. No error reported.
[root@oraclevm /]#
Edit /boot/grub2/grub.cfg and replace root=/dev/mapper/ol-root with migrated disk UUID (root=UUID=35e305ec-c8d4-40f9-a9e8-98dc3b27f565)
Now mount the new disk.
[root@oraclevm ~]# mount /dev/nvme0n2p1 /tmp_boot/
[root@oraclevm ~]# mount /dev/nvme0n2p2 /tmp_os
Copy the updated /etc/default/grub and /boot/grub2/grub.cfg file to the new disk.
[root@oraclevm ~]# cp /etc/default/grub /tmp_os/etc/default/grub
cp: overwrite '/tmp_os/etc/default/grub'? y
[root@oraclevm ~]# cat /tmp_os/etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=false
[root@oraclevm ~]#
Updated /boot/grub2/grub.cfg and copy the same to new disk.
[root@oraclevm grub2]# cp grub.cfg /tmp_boot/grub2/grub.cfg
cp: overwrite '/tmp_boot/grub2/grub.cfg'? y
[root@oraclevm grub2]#
Update /etc/fstab and copy the same.
[root@oraclevm /]# cat /etc/fstab | grep -v "^#"
UUID=35e305ec-c8d4-40f9-a9e8-98dc3b27f565 / xfs defaults 0 0
UUID=bb83e8cd-16ad-4aff-a3f4-4a9505d9b5ca /boot xfs defaults 0 0
[root@oraclevm /]#
[root@oraclevm /]# cp /etc/fstab /tmp_os/etc/fstab
cp: overwrite '/tmp_os/etc/fstab'? y
[root@oraclevm /]#
Reboot the server.
[root@oraclevm ~]# uptime
15:27:10 up 1 min, 1 user, load average: 0.52, 0.24, 0.09
[root@oraclevm ~]# cat /proc/cmdline
BOOT_IMAGE=/vmlinuz-5.4.17-2136.307.3.1.el8uek.x86_64 root=UUID=35e305ec-c8d4-40f9-a9e8-98dc3b27f565 ro rhgb quiet
[root@oraclevm ~]#
[root@oraclevm ~]# df -TH | grep -i xfs
/dev/nvme0n2p2 xfs 21G 12G 9.1G 56% /
/dev/nvme0n2p1 xfs 1.1G 311M 754M 30% /boot
[root@oraclevm ~]#
We were successfully able to boot from migrated disk. Lets remove the old disk.
[root@oraclevm ~]# uptime
15:29:58 up 1 min, 1 user, load average: 0.79, 0.29, 0.11
[root@oraclevm ~]# fdisk -l
Disk /dev/nvme0n1: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x25d7b68c
Device Boot Start End Sectors Size Id Type
/dev/nvme0n1p1 * 2048 2099199 2097152 1G 83 Linux
/dev/nvme0n1p2 2099200 41943039 39843840 19G 83 Linux
[root@oraclevm ~]#
Dont get confuse with the name as /dev/nvme0n1. udev has renamed (/dev/nvme0n2 to /dev/nvme0n1) the disk name post removal of Original disk.
Comments
Post a Comment