๐ How-to: Migrate a CentOS installation from BIOS/Legacy boot to EFI boot.
๐ก Newskategorie: Linux Tipps
๐ Quelle: reddit.com
Introduction
I've upgraded a small, private server from an Intel Atom D510 to an Intel Celeron J5005 and encountered the problem that the new board does not support BIOS/Legacy boot. So here is a small write-up on how you can achieve this without any data- or system-loss...if everything goes well, that is.
I've pieced this information together from several different sources, hence this write-up.
Reminder: We're going to change the partition layout. Every time before you touch the partitions you should make sure that you have a backup. These instructions have the potential to corrupt your data for good. Think about every step you're doing, and read every message and warning that is displayed on screen.
Prerequisites
I'm assuming you're having a system with a msdos partition table and an installed CentOS. What you need is a CentOS installation medium.
Conversion
These steps could most likely be done at least partially with the old board, but in my case I only noticed that problem after having migrated the hardware to the new board.
First, boot into the CentOS install medium, select the "Troubleshooting" option in the boot menu and "Rescue an CentOS installation".
Short detour, if your boot fails at this point and it can't mount the root/medium (dracut reports starting timeout scripts and drops you in a rescue shell), you most likely have a problem with the configuration of the medium you created. There is the problem that the boot configuration on the medium might not match the medium it was flashed onto. To remedy that, you have to replace the label/name of the medium in the "grub.cfg" and "syslinux.cfg" on the medium.
If the rescue system boots, Anaconda will automatically ask whether it should mount an existing installation, proceed with that. Another word of warning, some times it failed to find my installation, but after a reboot it worked. You're now in shell which allows you to chroot into the actual installation, if you want to, it's not necessary for changing the partition table/layout.
Converting the partition table
We will now convert from the msdos partition table to a GPT one. Have a good look at the backup you've made beforehand and ask yourself "can I lose all that data currently on this disk?", then continue confidently.
Now, we start gdisk. gdisk is basically parted but for GPT partitioned disks.
gdisk /dev/yourharddiskgoeshere
It should now inform you right after the start that a msdos partition table was found, and it has been converted to a GPT one in memory. No changes have been done to disk at this point and quitting the application will not change your disk. You can type p
to see the new layout of the disk. If you're happy with it, proceed to write the new layout with w
.
Reboot back into the rescue system afterwards to make sure the changes are being picked up correctly.
Creating an EFI partition.
We will now create an additional EFI partition, around 30MB should me more than enough. If you don't have that much space left, resize another partition to get it. You can create the new partition directly in gdisk.
gdisk /dev/yourharddiskgoeshere
Then type n
to create a new partition. The type of the partition will be "ef00", which dedicates it as an EFI partition. Whether or not the legacy boot flag (under expert/attributes x
/a
) must be set, is a little bit unclear, a few people reporting it to be necessary, it most likely depends on the board.
After the partition has been created and you have written the changes to the partition table with w
, you must format the partition with FAT32. mkfs.fat
is in the "dosfstools" package.
mkfs.fat -F32 -s1 /dev/yourefipartitiongoeshere
The -F
states the "type" of the FAT created, -s
tells it to use one sector as one cluster.
Now that we have the partition set up, we can chroot into our system for the first time and add it to the "fstab".
chroot /mnt/sysimage
The EFI partition should be mounted under "/boot/efi".
Install GRUB-EFI
Install "grub-efi" and "efibootmgr" on your system, if it is not already there.
Restoring GRUB and the boot process.
Make sure that the EFI partition is mounted. From here on the instructions are a little bit fuzzy, and I'm sorry for that, as I had trouble to get the machine to boot, so any of these steps might suffice.
First, reinstall GRUB to be able to boot from EFI.
grub2-install --target=x86_64-efi --bootloader-id=centos --boot-directory=/boot --efi-directory=/boot/efi --recheck --verbose /dev/yourharddiskgoeshere
Now regenerate the "grub.cfg":
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
My system still did not boot after that, as it failed to mount the root filesystem. What I had to do was reinstall the kernel:
yum reinstall kernel
Or rather, as there were updates available, update the kernel:
yum update kernel
Conclusion
From here on, your system should boot with EFI again, and behave otherwise quite as before.
[link] [comments] ...