How to migrate boot partition to other storage disk partition in RHEL
Environment
- Red Hat Enterprise Linux 7
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 9
- Red Hat Enterprise Linux 10
Issue
- Storage migration is in progress, and need to move smaller /boot partition to some another disk containing larger partition for /boot
- How to migrate the data from /boot to some other higher storage capacity first partition of another disk and make it bootable?
- Need information on changing the /boot partition to a different disk
Resolution
Red Hat does not support planned migrations where the boot location is changed
The supported method to change the boot method is to use the Anaconda installer in the regular Red Hat Enterprise Linux installation process to reinstall the OS onto the new boot target.
The supported procedure is covered by the following resources:
- Installation Guide Red Hat Enterprise Linux 7
- Installing Red Hat Enterprise Linux 8
- Installing Red Hat Enterprise Linux 9
- Installing Red Hat Enterprise Linux 10
An unsupported solution is provided below (it's unsupported because there is no formal guarantee it will work, depending on the hardware).
Unsupported Disclaimer
The following information has been provided by Red Hat, but is outside the scope of the posted Service Level Agreements and support procedures (Production Support - Red Hat Customer Portal). The information is provided as-is and any configuration settings or installed applications made from the information in this article could make the Operating System unsupported by Red Hat Global Support Services. The intent of this article is to provide information to accomplish the system's needs. Use of the information in this article at the user's own risk.
Workaround Instructions
Note: Please make sure to have a backup of data before applying these steps on the production server, since unforeseen issues may occur.
Let assume two disks: /dev/sda and /dev/sdb.
Steps to migrate the /boot partition from /dev/sda to a new device /dev/sdb.
-
First we create the new
/dev/sdb1partition on/dev/sdbWe also need to make sure that we have a post-MBR gap (unallocated space) where grub will be installed. We will leave
1MiBof unallocated space at the start of the device which is the size used during installation. If there is no partition table on this device, create it:# parted /dev/sdb mklabel msdosNote: Please make sure that there is no data present on disk
/dev/sdb, as the following procedure will re-create a new disk label on it and a new partition will be created on disk/dev/sdb, thus it would erase any previous data present on it.Create the partition:
# parted /dev/sdb mkpart p xfs 1MiB 1024MiB -
Format the new partition with a filesystem
# mkfs.xfs /dev/sdb1 Or # fdisk /dev/sdb [...] -
Mount the filesystem on
/mntand copy files from/boot# mount /dev/sdb1 /mnt # cp -a /boot/* /mnt/ -
Unmount both file systems
On BIOS systems:
# umount /mnt /bootOn UEFI systems:
Ref: How to determine if the system is booted in BIOS or UEFI mode# umount /mnt /boot/efi /boot -
Update
/etc/fstabChange the relevant entry for the boot filesystem so that it uses the new partition. If you are using UUIDs to identify the filesystem in
/etc/fstab, you can find the UUID for the new filesystem withblkid /dev/sdb1:# blkid /dev/sdb1 -
Reload systemd and mount the new
/bootOn BIOS systems:
# systemctl daemon-reload # mount /bootOn UEFI systems:
# systemctl daemon-reload # mount /boot # mount /boot/efi -
Only on BIOS systems: install the grub bootloader on the primary device
# grub2-install /dev/sdaYou may also install the grub bootloader on the new device, in case it gets selected as primary device by the BIOS:
# grub2-install /dev/sdb -
Rebuild the grub menu
# grub2-mkconfig -o /etc/grub2$(test -e /sys/firmware/efi && echo "-efi").cfg $(grub2-mkconfig --help | grep -q -- --update-bls-cmdline && echo "--update-bls-cmdline") -
[Optional]: RHEL9 and later UEFI systems only : update
/boot/efi/EFI/redhat/grub.cfgstub file with new /boot UUID:# cat /boot/efi/EFI/redhat/grub.cfg search --no-floppy --root-dev-only --fs-uuid --set=dev <UUID OF BOOT PARTITION> set prefix=($dev)/grub2 export $prefix configfile $prefix/grub.cfg -
Reboot the system and make sure BIOS is pointed to the newly configured boot device.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.