Archive for June, 2013

A generic rescue system should boot in bios mode and in (u)efi mode. It should boot from usb and it should use the same boot menu config file for bios and for efi boot mode. Grub2 has a nice boot menu and supports bios and efi boot mode.

Because the installation scripts of grub2 might have side effects and might affect installed systems, only grub images (=files) are created.
(Installation for efi boot, if secure boot is disabled: copy grub core image to EFI/BOOT; bios boot: chainload from syslinux + ldbsd.com.)

Steps to create such an usb stick using linux (e.g. ubuntu or opensuse): bios boot and efi boot with disabled secure boot

  • backup existing data because the usb stick will be repartitioned (erasing existing data)
  • run linux and use gdisk to create a gpt partition table with one fat32 partition
    (which will be marked bootable for bios boot). Run gdisk as root user:
    gdisk /dev/sdX (X=your usb stick; ensure that you use the intended usb stick – and not an existing hard disk)
    – p (prints existing partition table)
    – o (creates a new empty partition table)
    – n (create partition: use default start and end sectors, set type to 0700)
    – x (switch to expert menu)
    – a (add flags:  use 2 = “legacy BIOS bootable”)
    – w (writes the new partition table to the usb stick)
  •  format the new partition with fat32 (and set partition label name to SPB2; this label will be used by grub2 to identify the partition)
    mkfs.msdos -n SPB2 /dev/sdX1 (X=your usb stick)
  • mount the new partition and create some directories:
    – mkdir mnt
    – mount /dev/sdX1 mnt (X=your usb stick)
    – mkdir -p mnt/EFI/BOOT
    – mkdir -p mnt/grub/fonts
    – mkdir syslinux
    – mkdir mnt/grub/i386-pc (optionally for additional grub2 modules, bios mode)
    – mkdir mnt/grub/x86_64-efi (optionally for additional grub2 modules, efi mode)
  • install syslinux to the new partition /dev/sdX1 and copy the sylinux boot loader gptmbr.bin to /dev/sdX
    – umount /dev/sdX1 (X=your usb stick)
    – syslinux -d syslinux /dev/sdX1 (X=your usb stick)
    –  dd if=/usr/lib/syslinux/gptmbr.bin of=/dev/sdX
    or
    dd if=/usr/share/syslinux/gptmbr.bin of=/dev/sdX
    – mount /dev/sdX1 mnt
  • contents of configuration file for grub core image in bios boot mode embed.cfg:
    search.fs_label SPB2 root
    set prefix=($root)/grub
    configfile $prefix/grub.cfg
  • the  configuration file for grub core image in efi boot mode embed_efi.cfg currently has the same contents as embed.cfg.
  • both configuration files, embed.cfg and embed_efi.cfg are stored in mnt/grub/
  • install grub2 (needs installed grub2 packets for i386-pc and for x86_64-efi;
    e.g. apt-get install grub-pc and apt-get install grub-efi-amd64; debian based linux calls grub2 grub and grub-1.x grub-legacy).
    This step creates only grub image files (given by “-o”).
    – cp /usr/share/grub/unicode2.pf2 mnt/grub/fonts/
    or
    cp /usr/share/grub2/unicode.pf2 mnt/grub/fonts
    –  grub-mkimage -O i386-pc -p /grub -c mnt/grub/embed.cfg -o mnt/grub/core.img configfile fat part_gpt part_msdos biosdisk cat echo test search search_label search_fs_uuid boot chain linux reboot halt normal vbe font gfxterm
    or
    grub2-mkimage ….
    –  grub-mkimage -O x86_64-efi -p /grub -c mnt/grub/embed_efi.cfg -o mnt/EFI/BOOT/bootx64.efi configfile fat part_gpt part_msdos cat echo test search search_label search_fs_uuid boot chain linux reboot halt normal efi_gop efi_uga font gfxterm
    or
    grub2-mkimage ….
  • in bios boot mode syslinux is used to chainload core.img of grub2 (with an intermediate ldbsd.com from grml project)
    – contents of syslinux.cfg (to be copied to mnt/syslinux/syslinux.cfg):
    default grub2
    timeout 1
    totaltimeout 3
    label grub2
    say using bsd4grml/ldbsd.com as loader
    kernel ldbsd.com
    append echo Loading GRUB2…`machine exec grub /grub/core.img
    – unpack ldbsd.com.zip and copy ldbsd.com to mnt/syslinux/ldbsd.com
  • finally we need grub.cfg (to be stored in mnt/grub/):
    set menu_color_normal=white/black
    set menu_color_highlight=black/light-gray
    set default=0
    loadfont ($root)/grub/fonts/unicode.pf2
    if [ x$grub_platform = xefi ]; then
    set gfxmode=auto
    set gfxpayload=keep
    set boottype=efi
    else
    set gfxmode=800x600x16
    set gfxpayload=keep
    set boottype=bios
    fi
    terminal_output gfxterm
    menuentry “linux on sdb1 ($boottype; partition SPB2 on($root); $gfxmode)” {
    linux ($root)/vmlinuz root=/dev/sb1 …
    initrd ($root)/initrd
    }
  • the example assumes that linux kernel and ramdisk are copied to mnt/
    (that is, to the root directory of the usb stick)
  • both boot modes can be tested with virtualbox (>=4.2.12); system settings allow to switch to efi boot mode.
    Give access to usb device with
    VBoxManage internalcommands createrawvmdk -rawdisk /dev/sdX -filename raw_usb_sdX.vmdk