From 0e537017a534502fecc513df279f95c3b8f3ad83 Mon Sep 17 00:00:00 2001 From: Adrian Date: Mon, 7 Jan 2019 15:31:11 +0100 Subject: [PATCH] New Hybrid Boot documentation --- doc/Hybrid-Boot/README.md | 190 ++++++++++++++++++++++++++ doc/Hybrid-Boot/create-minimal.bat | 14 ++ doc/Hybrid-Boot/create-winre-bios.bat | 19 +++ doc/Hybrid-Boot/create-winre-uefi.bat | 19 +++ doc/Hybrid-Boot/winre-bios.bcd | Bin 0 -> 8192 bytes doc/Hybrid-Boot/winre-uefi.bcd | Bin 0 -> 8192 bytes doc/Multiboot-Guide.md | 136 ------------------ 7 files changed, 242 insertions(+), 136 deletions(-) create mode 100644 doc/Hybrid-Boot/README.md create mode 100644 doc/Hybrid-Boot/create-minimal.bat create mode 100644 doc/Hybrid-Boot/create-winre-bios.bat create mode 100644 doc/Hybrid-Boot/create-winre-uefi.bat create mode 100644 doc/Hybrid-Boot/winre-bios.bcd create mode 100644 doc/Hybrid-Boot/winre-uefi.bcd delete mode 100644 doc/Multiboot-Guide.md diff --git a/doc/Hybrid-Boot/README.md b/doc/Hybrid-Boot/README.md new file mode 100644 index 0000000..61b8002 --- /dev/null +++ b/doc/Hybrid-Boot/README.md @@ -0,0 +1,190 @@ +# 3-in-1 Hybrid Boot Disk (BIOS/UEFI) + +This guide shows how to prepare a disk on Ubuntu +to be bootable from BIOS, 32-bit and 64-bit UEFI +with Secure Boot enabled. +The intention is to create a bootable USB stick +that can be used to boot a rescue system. + +All commands should be executed as root. + +For more technical information, see the [notes section](#notes) at the end. + +Grub will be used as the bootloader. +Install the following packages: + + apt install grub-efi-amd64-bin grub-efi-ia32-bin grub-pc-bin + apt install grub-efi-amd64-signed # grub-efi-ia32-signed not available on Ubuntu + +## Partitioning + +* The GUIDs are fixed for easier setup with Windows +* The last partition is optional: it can be used to make changes of Ubuntu persistent +* Set the `dev` variable accordingly + + + + dev=/path/to/dev + + sgdisk --disk-guid=4b534944-4949-4949-b741-44495858580a $dev + + sgdisk --new=1:1M:+1M --typecode=1:ef02 --partition-guid=1:42555247-4949-4949-b741-44495858580a $dev + sgdisk --new=2:2M:+14M --typecode=2:ef00 --partition-guid=2:49494645-4949-4949-b741-44495858580a $dev + sgdisk --new=3:16M:+496M --typecode=3:2700 --partition-guid=3:524e4957-4945-4949-b741-44495858580a $dev + sgdisk --new=4:512M:+2048M --typecode=4:8300 --partition-guid=4:4e554255-5554-4949-b741-44495858580a $dev + sgdisk --new=5:2560M:4G --typecode=5:8300 --partition-guid=5:50534143-5245-4949-b741-44495858580a $dev + +## Format + +* Run `partprobe` before working with the disk references below +* The labels are set for easier configuration of GRUB +* The first partition is not formatted as it will be used by GRUB to store its executable code + + + + mkdosfs -F 16 -n hybrid-boot /dev/disk/by-partuuid/49494645-4949-4949-b741-44495858580a + mkntfs -Q -L hybrid-winre /dev/disk/by-partuuid/524e4957-4945-4949-b741-44495858580a + mkfs.ext4 -L hybrid-ubuntu /dev/disk/by-partuuid/4e554255-5554-4949-b741-44495858580a + mkfs.ext4 -L casper-rw /dev/disk/by-partuuid/50534143-5245-4949-b741-44495858580a + +## Install GRUB + +* Set the `mnt` variable accordingly + + + + mnt=/path/to/mount + + mount /dev/disk/by-partuuid/4e554255-5554-4949-b741-44495858580a $mnt + mkdir -p $mnt/boot/efi + mount /dev/disk/by-partuuid/49494645-4949-4949-b741-44495858580a $mnt/boot/efi + + grub-install --root=$mnt --removable --no-nvram --uefi-secure-boot --target=x86_64-efi $dev + grub-install --root=$mnt --removable --no-nvram --uefi-secure-boot --target=i386-efi $dev + grub-install --root=$mnt --modules='ext2 part_gpt' --target=i386-pc $dev + +Place the following configuration snippets in `$mnt/boot/grub/grub.cfg`. + +### Ubuntu + + menuentry 'Ubuntu' { + search --set --label hybrid-ubuntu + linux /casper/vmlinuz boot=casper ignore_uuid persistent + initrd /casper/initrd + } + +The `persistent` parameter is only useful, if the persistence partition was created. + +### Windows + + menuentry 'Windows (UEFI)' { + search --set --label hybrid-boot + chainloader /EFI/Microsoft/Boot/bootmgfw.efi + } + + menuentry 'Windows (BIOS)' { + search --set --label hybrid-winre + ntldr /Boot/bootmgr + } + +## Copy OS Files + +### Ubuntu + +* Set the `cdrom` variable accordingly + + + + cdrom=/path/to/ubuntu-iso + + cp -r $cdrom/casper $cdrom/preseed $mnt + +### Windows + +* Set the `cdrom` and `winre` variables accordingly + + + + cdrom=/path/to/windows-iso + winre=/path/to/winre-mnt + + mount /dev/disk/by-partuuid/524e4957-4945-4949-b741-44495858580a $winre + + wim=$cdrom/sources/install.wim + + dir=$winre/Recovery + mkdir $dir + 7z e -o$dir $wim 1/Windows/System32/Recovery/Winre.wim + 7z e -o$dir $wim 1/Windows/System32/boot.sdi + + dir=$winre/Boot + mkdir $dir + 7z e -o$dir $wim 1/Windows/Boot/PCAT/bootmgr + + dir=$mnt/boot/efi/EFI/Microsoft/Boot + mkdir -p $dir + 7z e -o$dir $wim 1/Windows/Boot/EFI/bootmgfw.efi + +#### BCD + +Copy [winre-uefi.bcd](winre-uefi.bcd) and [winre-bios.bcd](winre-bios.bcd): + + cp winre-uefi.bcd $mnt/boot/efi/EFI/Microsoft/Boot/BCD + cp winre-bios.bcd $winre/Boot/BCD + +## Windows Hybrid Boot + +Windows can not be booted from BIOS and UEFI with the same configuration. +The above procedure enables Windows to boot using UEFI. + +### Boot in BIOS + +Windows needs an MBR to boot from BIOS: + + sgdisk --hybrid=3 $dev + printf DISK | dd bs=1 seek=440 conv=notrunc of=$dev + +If you try to boot without the above configuration, +the following message appears in the blink of an eye: + + ata1 master: Unknown device + +### Boot in UEFI + +Remove the hybrid MBR: + + echo start=1,type=ee | sfdisk -Y dos $dev + +Do *not* use `sgdisk` because it wipes the MBR boot code of GRUB. + +If you try to boot without the above configuration, +the following message appears: + + BlInitializeLibrary failed 0xc00000bb + +## Notes + +### Windows Bootloaders + +The Windows bootloader is configured using a file called `BCD` (Boot Configuration Data). +The file is a binary Windows Registry file and references IDs from the partition table. +This can make Windows boot problems cumbersome to fix. + +The above BCD files are usable if the disks were created using the described IDs. +They were created in a VM using BCDEdit: +[create-winre-uefi.bat](create-winre-uefi.bat) and +[create-winre-bios.bat](create-winre-bios.bat). + +The UEFI bootloader `bootmgfw.efi` uses the disk and partition GUIDs from the GPT. +The BIOS bootloader `bootmgr` uses the disk signature and partition start offsets in the MBR. + +To change GUIDs in a BCD, partitions with the same GUIDs can be recreated in a VM +and BCDEdit can be used to recreate a BCD: [create-minimal.bat](create-minimal.bat). + +Alternatively `hivexsh` can be used to change the GUIDs in an existing BCD. + +### Casper Persistence + +The casper manual mentions the use of a file, +but this only works on FAT, see +[find_cow_device in casper-helpers](https://git.launchpad.net/ubuntu/+source/casper/tree/scripts/casper-helpers). diff --git a/doc/Hybrid-Boot/create-minimal.bat b/doc/Hybrid-Boot/create-minimal.bat new file mode 100644 index 0000000..9a637fa --- /dev/null +++ b/doc/Hybrid-Boot/create-minimal.bat @@ -0,0 +1,14 @@ +@echo off + +bcdedit /createstore minimal.bcd + +bcdedit /store minimal.bcd /create {bootmgr} +bcdedit /store minimal.bcd /create {2f4e4957-0d58-11e9-8000-080027414449} /application osloader /d "Windows 10" + +bcdedit /store minimal.bcd /set {bootmgr} default {2f4e4957-0d58-11e9-8000-080027414449} +bcdedit /store minimal.bcd /set {bootmgr} displayorder {default} + +bcdedit /store minimal.bcd /set {default} device partition=C: +bcdedit /store minimal.bcd /set {default} osdevice partition=C: +bcdedit /store minimal.bcd /set {default} path \Windows\System32\winload.efi +bcdedit /store minimal.bcd /set {default} systemroot \Windows diff --git a/doc/Hybrid-Boot/create-winre-bios.bat b/doc/Hybrid-Boot/create-winre-bios.bat new file mode 100644 index 0000000..70f3e00 --- /dev/null +++ b/doc/Hybrid-Boot/create-winre-bios.bat @@ -0,0 +1,19 @@ +@echo off + +bcdedit /createstore winre-bios.bcd + +bcdedit /store winre-bios.bcd /create {bootmgr} +bcdedit /store winre-bios.bcd /create {2e455257-0d58-11e9-8000-080027414449} /application osloader /d "Windows Recovery Environment" +bcdedit /store winre-bios.bcd /create {2e564544-0d58-11e9-8000-080027414449} /device + +bcdedit /store winre-bios.bcd /set {bootmgr} default {2e455257-0d58-11e9-8000-080027414449} +bcdedit /store winre-bios.bcd /set {bootmgr} displayorder {default} + +bcdedit /store winre-bios.bcd /set {default} device ramdisk=[C:]\Recovery\Winre.wim,{2e564544-0d58-11e9-8000-080027414449} +bcdedit /store winre-bios.bcd /set {default} osdevice ramdisk=[C:]\Recovery\Winre.wim,{2e564544-0d58-11e9-8000-080027414449} +bcdedit /store winre-bios.bcd /set {default} path \Windows\System32\winload.exe +bcdedit /store winre-bios.bcd /set {default} systemroot \Windows +bcdedit /store winre-bios.bcd /set {default} winpe yes + +bcdedit /store winre-bios.bcd /set {2e564544-0d58-11e9-8000-080027414449} ramdisksdidevice partition=C: +bcdedit /store winre-bios.bcd /set {2e564544-0d58-11e9-8000-080027414449} ramdisksdipath \Recovery\boot.sdi diff --git a/doc/Hybrid-Boot/create-winre-uefi.bat b/doc/Hybrid-Boot/create-winre-uefi.bat new file mode 100644 index 0000000..83bed1f --- /dev/null +++ b/doc/Hybrid-Boot/create-winre-uefi.bat @@ -0,0 +1,19 @@ +@echo off + +bcdedit /createstore winre-uefi.bcd + +bcdedit /store winre-uefi.bcd /create {bootmgr} +bcdedit /store winre-uefi.bcd /create {2f455257-0d58-11e9-8000-080027414449} /application osloader /d "Windows Recovery Environment" +bcdedit /store winre-uefi.bcd /create {2f564544-0d58-11e9-8000-080027414449} /device + +bcdedit /store winre-uefi.bcd /set {bootmgr} default {2f455257-0d58-11e9-8000-080027414449} +bcdedit /store winre-uefi.bcd /set {bootmgr} displayorder {default} + +bcdedit /store winre-uefi.bcd /set {default} device ramdisk=[C:]\Recovery\Winre.wim,{2f564544-0d58-11e9-8000-080027414449} +bcdedit /store winre-uefi.bcd /set {default} osdevice ramdisk=[C:]\Recovery\Winre.wim,{2f564544-0d58-11e9-8000-080027414449} +bcdedit /store winre-uefi.bcd /set {default} path \Windows\System32\winload.efi +bcdedit /store winre-uefi.bcd /set {default} systemroot \Windows +bcdedit /store winre-uefi.bcd /set {default} winpe yes + +bcdedit /store winre-uefi.bcd /set {2f564544-0d58-11e9-8000-080027414449} ramdisksdidevice partition=C: +bcdedit /store winre-uefi.bcd /set {2f564544-0d58-11e9-8000-080027414449} ramdisksdipath \Recovery\boot.sdi diff --git a/doc/Hybrid-Boot/winre-bios.bcd b/doc/Hybrid-Boot/winre-bios.bcd new file mode 100644 index 0000000000000000000000000000000000000000..3ca6d976fe7370d6fbbe2eaf952c9e69badb328d GIT binary patch literal 8192 zcmeHMO>7%Q6n^=&`6*4S3I%b%r-CXR*6Vd*7sPKOrL+oBgCK_p#j!Ue_%E`p{3r$a zgmOf1phpWKWQ9u)2$f3}2^A{fz=1=KIiXZYz>Qo`_`ca4XR}@7szpekeb#tp=gqu% z@0)LC*5j)E_Tu9r!t~Y9&H0Z$`>Ce~_LzbC0-272i_~cGd^Q{^*GJufXp22SJ4 z-$q?-xH>j!Vf=C-CWE6}S>AonObkiif9xVw#)T@C(?>pEVuep4cz$i+9XnUA$pPBT z!`K#bzkLMf#(`^<{$Tq-_??CQ%}n0Trbo?OJeAAmv-oNt=d;#7g2J%-0CO^K*K*b6mHKkUq0c_r78iSE zAAPA~jKpFO^{a)5>e~Pww9jxwehA|z;W_T+}jvAF&6H<`1qOYTkO5Ia)bFj3$b9$u8GxdLElF z#Cg1qSgGsA;}3u#$Du{+UCVmoGe%914Ti454_kz-_?S{gFcBJ;{k_gK_4_eD5PZm zL@*wAi~n`RLj2RfmH6xNo_}k zpULHe?7-%m>UKAeTirF>>&E0V?s;=~T18%!4b)8F_IDMns;DjFPT0n`+TOeFf4i7V z`c2oEYo7iMZ&IUH%CfrfW*4@Ki+w^)Y=Ud^hz)s)YlM3!$D=gS&c8pitrq%3Atu*g zOZ%tw-S(F~^wm565vZ7HIRFGi@G+6b@Na>ET{9(VloI&Z zl0hl$o&?l7WfN^J=q>fh2sQ>+xF1YnJdLCGoahu+G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{ zVx8iQk&9lx;W+0yMatho#>s-gh z21W-_e4t$G#}BMh8Wq20b*V2~c~sUs7PhX{<#FQ(Jen?#IxhIG8i&`!*Z>~gd0;SJ zD|m6y^~mcTJpbQ#{XM--K;tuMF1s~%~+V~xuw zcBv9}BpZ8E6l;$DvN?tQY7#3?7c~5~xfc%~+*_*acNOF1H?KJ66#8vC`>aX7rZTOv zfi;42tpeYPX$?Wov=g=%J8`@>u+19NZo^Q9aMN+>ecw53|4(2M^Ye>bQIub>jTfz5 zKB22nUmJgn(@xma{a+gVVwV^0C0bBT32nr&SNZj?|MRi`s54KZw0{frb(tPt)?G)x zwf@LK2T1Bwa=^q%JDW3oU literal 0 HcmV?d00001 diff --git a/doc/Multiboot-Guide.md b/doc/Multiboot-Guide.md deleted file mode 100644 index 29b52aa..0000000 --- a/doc/Multiboot-Guide.md +++ /dev/null @@ -1,136 +0,0 @@ -# Introduction - -This guide describes how to create a bootable medium -for the following purpose: - -* Boot in BIOS (Legacy/CSM) mode -* Boot in UEFI mode using Secure Boot -* Start Ubuntu or a Windows 7, 8, or 10 installation - -Set the following variables accordingly: - - FULLDEV=/dev/sdb - DEV=${FULLDEV}1 - MNT=/mnt - -# Preparation - -## Partition An Empty Medium - - parted "$FULLDEV" - mklabel msdos - mkpart pri fat32 1MiB -1s - set 1 boot on - quit - mkdosfs -F 32 -R 8 "$DEV" - -## Create Directory Structure - -See below for the config files `syslinux.cfg` and `grub.cfg` - - mount -o shortname=winnt "$DEV" "$MNT" - mkdir -p "$MNT"/boot/syslinux - mkdir -p "$MNT"/boot/grub - mkdir -p "$MNT"/efi/boot - cp syslinux.cfg "$MNT"/boot/syslinux - cp grub.cfg "$MNT"/boot/grub - -# BIOS - - syslinux -i -d boot/syslinux "$DEV" - cd /usr/lib/syslinux - for f in libutil libcom32 menu chain; do cp modules/bios/$f.c32 "$MNT"/boot/syslinux; done - sh -c "cat mbr/mbr.bin > $FULLDEV" - -Note: If a `Boot error` gets reported, try this: - -* Try a 3.xx version -* `mkdiskimage -4 $FULLDEV 0 64 32` - -# UEFI - - grub-install --target=x86_64-efi --uefi-secure-boot \ - --efi-directory="$MNT" --boot-directory="$MNT"/boot \ - --bootloader-id=boot --no-nvram "$DEV" - cp /usr/lib/shim/shim.efi.signed "$MNT"/efi/boot/bootx64.efi - -Note: Due to [a bug](https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1450783), -the config file needs to be in efi/ubuntu: - - mkdir -p "$MNT"/efi/ubuntu - cp -a "$MNT"/efi/boot/grub.cfg "$MNT"/efi/ubuntu - -# Copy OS files - -## Ubuntu - -Execute the following commands in the directory of the mounted ISO: - - rsync -Pa casper preseed "$MNT"/ - -## Windows - -Execute the following commands in the directory of the mounted ISO: - - rsync -Pa sources boot efi "$MNT"/ - rm "$MNT"/sources/ei.cfg # To enable Edition selection - cp bootmgr "$MNT"/boot - 7z e -o"$MNT"/efi/microsoft/boot sources/boot.wim 1/Windows/Boot/EFI/bootmgfw.efi - -When copying Windows 8, the default bootloader gets replaced. Install Shim again: - - cp /usr/lib/shim/shim.efi.signed "$MNT"/efi/boot/bootx64.efi - -# Config Files - -## syslinux.cfg - - default menu.c32 - prompt 0 - - menu title Select Operating System - - label ubuntu - menu default - menu label Start Ubuntu - kernel /casper/vmlinuz.efi - append initrd=/casper/initrd.lz file=/cdrom/preseed/ubuntu.seed boot=casper ignore_uuid maybe-ubiquity quiet splash -- - - label win7x64 - menu label Install Windows - com32 chain.c32 - append fs ntldr=/boot/bootmgr - -# grub.cfg - - insmod efi_gop - insmod efi_uga - insmod font - - menuentry "Start Ubuntu" { - set gfxmode=auto - set gfxpayload=keep - linux /casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed boot=casper ignore_uuid maybe-ubiquity quiet splash -- - initrd /casper/initrd.lz - } - - menuentry "Install Windows" { - insmod part_gpt - insmod chain - set root='(hd0,1)' - chainloader /efi/microsoft/boot/bootmgfw.efi - } - - menuentry "UEFI Setup" { - fwsetup - } - -# Recommended Disk Partitioning for Multiboot Systems - - parted /dev/sda - mklabel gpt - mkpart Boot fat32 1MiB 257MiB - mkpart SysUbuntu ext4 257MiB 12GiB - mkpart SysWin ntfs 12GiB 52GiB - mkpart Data ext4 52GiB -1s - set 1 esp on