📜 ⬆️ ⬇️

Boot from GPT disk from BIOS

The article describes how to make the computer boot from the BIOS, from the hard disk marked in GPT. This article is not a translation of the original article, but rather a free retelling of an article written by Rod Smith , for which I personally am very grateful to him. Link to the source at the end of this article.

Motivation


On the working video server, the hard drive marked up in the MBR , on which Windows 7 was installed, has failed.

The situation was complicated by the fact that the replacement disk was not at hand, buying for a long time, from the word VERY (features of the organization of processes in the enterprise), and the server must be put into operation.

From scrap materials was only the disk, which in this server was used to store the archive. The server is old, and the disk is new ( WD Purple line), respectively, the question was how to force the old computer (read the computer with BIOS ) to boot from this hard disk, which is marked up in GPT , so as not to lose the useful volume.
')
The study of this issue led to the site rodsbooks.com, on which there was a solution.

The solution of the problem


Actually a free paraphrase, after the theoretical part, why this turned out to be not a trivial task, welcome to the great and mighty Google

So, to solve this problem, we need a Live CD / DVD / USB with GNU / Linux.
Personally, I tried using Ubuntu 16.04 and Debian 8 for these purposes. The author himself proposes to use Gparted , written to the “disc”, but everyone is free to use what is closer to him.

First, you need to get DUET : gitlab.com/tianocore_uefi_duet_builds/tianocore_uefi_duet_installer/repository/master/archive.tar.gz (actually all the “magic” is contained in it), as well as SYSLINUX : www.kernel.org/pub/linux/ utils / boot / syslinux / 5.xx / syslinux-5.10.tar.gz (you need to download this particular version, the subsequent gptmbr.bin file necessary for further manipulations is not compiled. In order not to compile it yourself, just download the archive by reference) .

The resulting files must be recorded in a convenient network storage (or on a USB flash drive) and then, for convenience, transferred to temporary storage on a Linux-running system.
Now boot into your favorite GNU / Linux distribution.

The first thing that is needed after loading into the Live CD is to partition our disk in the GPT partition table.
(I give examples for Ubuntu 04/16)
Open the console (the console should be English, the localized console causes errors when processing the script) and mark up the disk with fdisk:

ubuntu@ubuntu:~$ sudo fdisk /dev/sda 

Now we are creating a new GPT partition table on the disk, as well as the necessary partitions. It is assumed that the disk in the system is one and is defined as / dev / sda, otherwise, it is necessary to change the name of the disk to the one that is right for you.

 Command (m for help): g Created a new GPT disklabel (GUID: 416CDA03-62CB-4E45-8260-DD7723111AF7). Command (m for help): n Partition number (1-128, default 1): 1 First sector (2048-62914526, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-62914526, default 62914526): +100M Created a new partition 1 of type 'Linux filesystem' and of size 100 MiB. Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 1 Changed type of partition 'Linux filesystem' to 'EFI System'. Command (m for help): n Partition number (2-128, default 2): First sector (206848-62914526, default 206848): Last sector, +sectors or +size{K,M,G,T,P} (206848-62914526, default 62914526): Created a new partition 2 of type 'Linux filesystem' and of size 29.9 GiB. Command (m for help): t Partition number (1,2, default 2): 2 Hex code (type L to list all codes): 11 Changed type of partition 'Linux filesystem' to 'Microsoft basic data'. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. 

I will not comment on the steps described above, because these are standard procedures that are performed in fdisk. The only thing you should pay attention to is that when creating the first partition on which DUET will be stored, you need to change its type to 'EFI System' (

 Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 1 Changed type of partition 'Linux filesystem' to 'EFI System'. 

), and the type of the second section, select as 'Microsoft basic data' (

 Command (m for help): t Partition number (1,2, default 2): 2 Hex code (type L to list all codes): 11 Changed type of partition 'Linux filesystem' to 'Microsoft basic data'. 

) in fact, it will be installed on Windows later.

With the markup finished, now we create the file systems:

 ubuntu@ubuntu:~$ sudo mkfs.fat -F32 /dev/sda1 mkfs.fat 3.0.28 (2015-05-16) ubuntu@ubuntu:~$ sudo mkfs.ntfs -f /dev/sda2 Cluster size has been automatically set to 4096 bytes. Creating NTFS volume structures. mkntfs completed successfully. Have a nice day. 

With standard procedures finished, now we pass to magic.

DUET installation


I copied SYSLINUX and TianoCore to / tmp / 1 and moved to the TianoCore folder:

 ubuntu@ubuntu:~$ cd /tmp/1/tianocore_uefi_duet_installer/ ubuntu@ubuntu:/tmp/1/tianocore_uefi_duet_installer$ ll total 96 drwxrwxr-x 10 ubuntu ubuntu 400 Nov 7 2013 ./ drwxrwxr-x 4 ubuntu ubuntu 80 Sep 1 06:37 ../ drwxrwxr-x 2 ubuntu ubuntu 260 Nov 7 2013 BootSector/ -rw-rw-r-- 1 ubuntu ubuntu 2155 Nov 7 2013 copy_duet_files.sh -rw-rw-r-- 1 ubuntu ubuntu 2921 Nov 7 2013 CreateUSB.cmd -rw-rw-r-- 1 ubuntu ubuntu 16019 Nov 7 2013 duet-install -rw-rw-r-- 1 ubuntu ubuntu 9116 Nov 7 2013 duet-install.8 drwxrwxr-x 4 ubuntu ubuntu 80 Nov 7 2013 Efildr/ -rw-rw-r-- 1 ubuntu ubuntu 20480 Nov 7 2013 Elevate.exe drwxrwxr-x 3 ubuntu ubuntu 60 Nov 7 2013 Extras/ drwxrwxr-x 2 ubuntu ubuntu 80 Nov 7 2013 Licenses/ drwxrwxr-x 3 ubuntu ubuntu 60 Nov 7 2013 Linux_Source/ -rw-rw-r-- 1 ubuntu ubuntu 9282 Nov 7 2013 Migle_BootDuet_INSTALL.txt drwxrwxr-x 3 ubuntu ubuntu 160 Nov 7 2013 Modified_files_for_compiling_EDK1_DUET_in_Windows_X64/ -rw-rw-r-- 1 ubuntu ubuntu 3536 Nov 7 2013 README.txt drwxrwxr-x 2 ubuntu ubuntu 80 Nov 7 2013 Shell/ -rw-rw-r-- 1 ubuntu ubuntu 13673 Nov 7 2013 UDK_EDK2_DuetPkg_Changes_to_Makefiles.patch -rw-rw-r-- 1 ubuntu ubuntu 1821 Nov 7 2013 Usage_Linux.txt -rw-rw-r-- 1 ubuntu ubuntu 2165 Nov 7 2013 Usage_Windows.txt drwxrwxr-x 2 ubuntu ubuntu 80 Nov 7 2013 Windows_Binaries/ ubuntu@ubuntu:/tmp/1/tianocore_uefi_duet_installer$ 

Make the executable copy_duet_files.sh and duet-install:

 ubuntu@ubuntu:/tmp/1/tianocore_uefi_duet_installer$ chmod +x copy_duet_files.sh duet-install 

Install DUET:

 ubuntu@ubuntu:/tmp/1/tianocore_uefi_duet_installer$ sudo ./duet-install -m -s ../syslinux-5.10/mbr /dev/sda1 Will install SYSLINUX to the MBR Will install SYSLINUX to the MBR Path to SYSLINUX is ../syslinux-5.10/mbr Path to bootduet is /tmp/1/tianocore_uefi_duet_installer/BootSector Path to UEFI DUET is /tmp/1/tianocore_uefi_duet_installer Will install UEFI version UDK Target partition is /dev/sda1 Target disk (for storing MBR boot code) is /dev/sda Partition number is 1 Partition starts at sector 2048 FAT32 filesystem found on /dev/sda1 Partition table type is gpt Proceeding with installation will overwrite at least some data on /dev/sda1. This is your LAST CHANCE to abort! Do you want to continue (Y/N)? y Preparing disk... Writing 00 08 00 00 to boot partition's hidden sectors field Installing SYSLINUX... Installing BootDuet... Installing UEFI DUET.... Installation completed without errors; the disk should now be bootable! You may need to copy an EFI boot loader, such as ELILO or GRUB 2, to the disk. 

Now you need to copy the EFI TianoCore emulator:

 ubuntu@ubuntu:/tmp/1/tianocore_uefi_duet_installer$ sudo mount /dev/sda1 /mnt ubuntu@ubuntu:/tmp/1/tianocore_uefi_duet_installer$ sudo ./copy_duet_files.sh /mnt EDK_UEFI64 -------- PARTITION MOUNTPOINT = /mnt PARTITION FILESYSTEM = FAT32 UEFI-DUET FIRMWARE BUILD = EDK_UEFI64 -------- + cp --verbose /tmp/1/tianocore_uefi_duet_installer///Efildr/EDK_UEFI64//Efildr20 /mnt/EFILDR20 '/tmp/1/tianocore_uefi_duet_installer///Efildr/EDK_UEFI64//Efildr20' -> '/mnt/EFILDR20' + mkdir -p /mnt/EFI/tools/ + cp --verbose /tmp/1/tianocore_uefi_duet_installer///Shell//shellx64_v1.efi /tmp/1/tianocore_uefi_duet_installer///Shell//shellx64_v2.efi /mnt/EFI/tools/ '/tmp/1/tianocore_uefi_duet_installer///Shell//shellx64_v1.efi' -> '/mnt/EFI/tools/shellx64_v1.efi' '/tmp/1/tianocore_uefi_duet_installer///Shell//shellx64_v2.efi' -> '/mnt/EFI/tools/shellx64_v2.efi' + mkdir -p /mnt/EFI/tools/extras + cp --verbose /tmp/1/tianocore_uefi_duet_installer///Extras/X64//diskpart.efi /tmp/1/tianocore_uefi_duet_installer///Extras/X64//efichk.efi /tmp/1/tianocore_uefi_duet_installer///Extras/X64//efifmt.efi /mnt/EFI/tools/extras/ '/tmp/1/tianocore_uefi_duet_installer///Extras/X64//diskpart.efi' -> '/mnt/EFI/tools/extras/diskpart.efi' '/tmp/1/tianocore_uefi_duet_installer///Extras/X64//efichk.efi' -> '/mnt/EFI/tools/extras/efichk.efi' '/tmp/1/tianocore_uefi_duet_installer///Extras/X64//efifmt.efi' -> '/mnt/EFI/tools/extras/efifmt.efi' + set +x +e -------- DUET EDK_UEFI64 files have been copied to the FAT32 PARTITION successfully -------- 

Mount the first partition in / mnt and install EFI. I chose EDK_UEFI64, because later when setting up the boot, UDK_X64 for some reason did not save the settings. It was too lazy to understand.

That's all the magic. It is enough to restart the computer and in BIOS set up the boot from the hard disk. The result should be a welcome inscription as shown below:



After it, if everything went smoothly, and the copy_duet_files.sh script worked correctly, an EFI emulator prompt will appear.

Unfortunately, it’s impossible to reproduce it on a virtual machine, so I brought a picture from EFI VirtualBox, it is almost the same as the one that you should see.



Further setup of the boot is made through this menu. I leave the subsequent setup of loading through the EFI menu for personal study, especially since there is nothing complicated there. For example, for starters, you can practice in the same VirtualBox in EFI boot mode.

Insert the CD with the distribution of Windows in the drive or use a pre-formed installation flash drive. In the EFI emulator menu, select where to boot from (this is selected via the menu 'Boot Maintenance Manager' → 'Boot From File', selecting the device from which the USB flash drive or CD / DVD is loaded. To start the installation, this is enough. You will need to select the bootx64 file in the list. efi is the one that is bootable). Further download and installation takes place using the standard Windows installer, but with the ability to install on a disk that is marked up in GPT.

That's all. Thanks for attention.

Original article: by Rod Smith

Source: https://habr.com/ru/post/336686/


All Articles