前回はUEFIがGPT形式のHDDからOSを起動する仕組みを解説し、
従来のSystem BIOSではHDDの起動順序等の設定はBIOSのメニュー画面からしか操作できなかったのに対し、
一方、
すなわち、
USBメモリからUEFI起動
前回紹介したように、
前回紹介したように、
$ ls -l /usr/lib64/grub/x86_64-efi/ 合計 20,307,968 -rw-r--r-- 1 root root 16,432 10月 30日 17:11 acpi.mod -rwxr-xr-x 1 root root 102,088 10月 30日 17:11 acpi.module* -rw-r--r-- 1 root root 1,928 10月 30日 17:11 adler32.mod -rwxr-xr-x 1 root root 13,328 10月 30日 17:11 adler32.module* -rw-r--r-- 1 root root 8,272 10月 30日 17:11 affs.mod -rwxr-xr-x 1 root root 48,344 10月 30日 17:11 affs.module* -rw-r--r-- 1 root root 9,016 10月 30日 17:11 afs.mod -rwxr-xr-x 1 root root 57,488 10月 30日 17:11 afs.module* ...
grubがブートローダとして機能するためには、
骨組みだけしかないgrubコアにgrub.
そのような場合のために用意されているのがgrub-mkimageコマンドです。このコマンドは、
$ grub-mkimage --help 使い方: grub-mkimage [OPTION...] [OPTION]... [MODULES] Make a bootable image of GRUB. -c, --config=FILE embed FILE as an early config -C, --compression=(xz|none|auto) choose the compression to use for core image -d, --directory=DIR use images and modules under DIR [default=/usr/lib64/grub/<platform>] -k, --pubkey=FILE embed FILE as public key for signature checking -m, --memdisk=FILE embed FILE as a memdisk image Implies `-p (memdisk)/boot/grub' and overrides any prefix supplied previously, but the prefix itself can be overridden by later options -n, --note add NOTE segment for CHRP IEEE1275 -o, --output=FILE output a generated image to FILE [default=stdout] -O, --format=FORMAT generate an image in FORMAT available formats: i386-coreboot, i386-multiboot, i386-pc, i386-pc-pxe, i386-pc-eltorito, i386-efi, i386-ieee1275, i386-qemu, x86_64-efi, i386-xen, ...
grubには250近いモジュールが用意されており、
$ grub-mkimage -v -p '' -o bootx64.efi -O x86_64-efi fat part_msdos iso9660 gzio \ all_video gfxterm font terminal normal linux echo test search configfile cpuid minicmd grub-mkimage: 情報: the total module size is 0x6ffb8. grub-mkimage: 情報: reading /usr/lib64/grub/x86_64-efi/kernel.img. grub-mkimage: 情報: locating the section .text at 0x0. grub-mkimage: 情報: locating the section .rodata at 0x9600. grub-mkimage: 情報: locating the section .rodata.str1.1 at 0x9798. ... grub-mkimage: 情報: kernel_img=0x7fcad3119010, kernel_size=0x18200. grub-mkimage: 情報: the core size is 0x881b8. grub-mkimage: 情報: writing 0x89400 bytes.
今回組み込んだモジュールは、
-p ''は起動時に必要なファイルを探すディレクトリを変更するための指定で、
grub-mkimageはgrubコアにこれらのモジュールを組み込み、
$ ls -lh bootx64.efi -rw-r--r-- 1 kojima users 549K 2月 23日 23:12 bootx64.efi $ file bootx64.efi bootx64.efi: PE32+ executable (EFI application) x86-64 (stripped to external PDB), for MS Windows
次に、
1: menuentry "UEFI Plamo Linux install from USB memory" {
2: linux (hd0)/isolinux/vmlinuz root=/dev/ram0 rw nomodeset vga16 unicon=eucjp vt.default_utf8=0 kbd=usbkbd
3: initrd (hd0)/isolinux/initrd.gz
4: }
2行目が読み込むカーネルと起動時のオプションの指定、(hd0)
の部分が(hd0,msdos1)
のようになります。
こうして作成したbootx64.

DVDからのUEFI起動
USBメモリは小さなHDDと見なせるのでUEFIへの対応は比較的簡単なものの、
さてどうしたものか、
UEFIから起動する場合、
El Torito用のブートイメージは仮想的なFDとして作成するので、
$ dd if=/dev/zero of=efiboot.img bs=1k count=1440 $ /usr/sbin/mkfs.msdos -F 12 -M 0xf8 efiboot.img mkfs.fat 3.0.26 (2014-03-07) $
次にこのefiboot.
$ mkdir /tmp/loop $ sudo mount efiboot.img /tmp/loop -o loop $ sudo mkdir -p /tmp/loop/EFI/BOOT $ sudo cp bootx64.efi /tmp/loop/EFI/BOOT $ sudo umount /tmp/loop
DVDイメージはmkisofsを用いて作成します。mkisofsは指定したディレクトリにある全てのファイルをDVDイメージに書き込むので、
$ mkdir DVD_contents $ cp -av /mnt2/Plamo-6.x/x86_64/isolinux ./DVD_contents/ $ cp efiboot.img ./DVD_contents/isolinux/
今回利用しているbootx64.
$ mkdir -p ./DVD_contents/EFI/BOOT $ cat << 'EOF' > ./DVD_contents/EFI/BOOT/grub.cfg menuentry "UEFI Plamo Linux install from DVD" { linux (cd0)/isolinux/vmlinuz root=/dev/ram0 rw nomodeset vga16 unicon=eucjp vt.default_utf8=0 kbd=usbkbd initrd (cd0)/isolinux/initrd.gz } EOF
必要なファイルが揃ったのでmkisofsを実行します。最初の2行がデフォルト
$ sudo mkisofs -v -J -r -b isolinux/isolinux.bin -c isolinux/boot.cat \ -no-emul-boot -boot-load-size 4 -boot-info-table \ -eltorito-alt-boot -eltorito-platform efi -eltorito-boot isolinux/efiboot.img \ -V UEFI-test -o UEFI-test.iso DVD_contents Setting input-charset to 'UTF-8' from locale. 3.01 (x86_64-unknown-linux-gnu) Scanning DVD_contents Scanning DVD_contents/isolinux Excluded by match: DVD_contents/isolinux/boot.cat Writing: Initial Padblock Start Block 0 Done with: Initial Padblock Block(s) 16 ... 75.29% done, estimate finish Wed Feb 24 16:29:21 2016 94.12% done, estimate finish Wed Feb 24 16:29:21 2016 Total translation table size: 2048 Total rockridge attributes bytes: 1690 Total directory bytes: 4096 Path table size(bytes): 26 Done with: The File(s) Block(s) 26390 Writing: Ending Padblock Start Block 26425 Done with: Ending Padblock Block(s) 150 Max brk space used 0 26575 extents written (51 MB) $
なお、
$ ls DVD_cotents/isolinux/ System.map efiboot.img isolinux.bin ldlinux.c32 libutil.c32 plamo61.lss vesamenu.c32 boot.cat initrd.gz isolinux.cfg libcom32.c32 plamo41.lss sample.msg vmlinuz
こうして作ったDVDイメージ


今回紹介したような形で、