Motivation
Goal is to install a SystemRescueCD ISO file on a partition of an USB disk and to boot from this ISO. Booting need to be possible under BIOS/MBR and (U)EFI.
Preparation
- Running computer with Linux installed
- All commands need to be executed with root user privileges on this machine
# sudo -s
- Downloaded ISO file of SystemRescueCD. Here systemrescuecd-amd64-6.1.8.iso
- Connected USB harddisk > 1GB
In case the automounter has already mounted the USB disk, it must be first unmounted.
# umount /dev/sdX?
- Create mount points below /mnt
usb: For the USB disk with the root partition and the /boot folder. Later used for /dev/sdX3
efi: USB disk partition for the EFI filesystem. Later used for /dev/sdX2
iso: Mount point for the SystemRescueCD ISO file.
# mkdir /mnt/usb /mnt/efi /mnt/iso
- Mounting of the SystemRescueCD ISO file
# mount systemrescuecd-amd64-6.1.8.iso /mnt/iso/
Installation
Delete USB harddisk
Running this will destroy all data of the USB harddisk. If the harddisk has already the right partitions you can skip this step.
# sgdisk --zap-all /dev/sdX Creating new GPT entries in memory. GPT data structures destroyed! You may now partition the disk using fdisk or other utilities.
Create partition
The names do not matter. Other typecodes can be seen with sgdisk -L.
1: ef02 => BIOS boot partition, not formatted and without content, only necessary to store MBR bootloader.
2: ef00 => EFI filesystem
3: 8300 => Linux filesystem, here we store the ISO file. 1G for one single ISO is sufficient. For more ISO files the disk space need to be bigger.
# sgdisk --clear --new 1::+1M --typecode=1:ef02 --change-name=1:'BIOS' --new 2::+100M --typecode=2:ef00 --change-name=2:'EFI' --new 3::+1G --typecode=3:8300 --change-name=3:'Linux' /dev/sdX Creating new GPT entries in memory. Setting name! partNum is 0 Setting name! partNum is 1 Setting name! partNum is 2 The operation has completed successfully.
EFI partition needs to be vfat
# mkfs.vfat /dev/sdX2
Linux partitions can be also vfat or Windows data. Maybe also other formats will work.
-L boot is important and need to correspond to the entries img_label and archisolabel in grub.cfg.
# mkfs.ext4 -L boot /dev/sdX3
Mount partitions
# mount /dev/sdX2 /mnt/efi # mount /dev/sdX3 /mnt/usb
Copy and adapation of boot files
Copy necessary files
# cp -rp /mnt/iso/boot /mnt/usb/. # cp -rp /mnt/iso/EFI /mnt/efi/. # mkdir /mnt/usb/iso # cp systemrescuecd-amd64-6.1.8.iso /mnt/usb/iso/systemrescuecd.iso
Note: If the SystemRescueCD file gets updated, it can be changed just by copying it over the old one.
Install grub for MBR/BIOS
# grub-install --removable --boot-directory=/mnt/usb/boot --target=i386-pc /dev/sdX i386-pc wird für Ihre Plattform installiert. Installation beendet. Keine Fehler aufgetreten.
Install grub for EFI
# grub-install --removable --boot-directory=/mnt/usb/boot --efi-directory=/mnt/efi --target=x86_64-efi /dev/sdX x86_64-efi wird für Ihre Plattform installiert. Installation beendet. Keine Fehler aufgetreten.
Change the boot menu
# cd /mnt/usb/boot/grub/
grub needs the /boot/grub/grub.cfg file. Perhaps other filenames will work, too.
# mv grubsrcd.cfg grub.cfg
Edit grub.cfg and add the following
# vi grub.cfg ... menuentry "SystemRescueCD" { set gfxpayload=keep loopback loop /iso/systemrescuecd.iso linux (loop)/sysresccd/boot/x86_64/vmlinuz img_label=boot img_loop=/iso/systemrescuecd.iso archisobasedir=sysresccd archisolabel=boot copytoram initrd (loop)/sysresccd/boot/intel_ucode.img (loop)/sysresccd/boot/amd_ucode.img (loop)/sysresccd/boot/x86_64/sysresccd.img } ...
Unmount all and test it
# cd /mnt # umount usb efi # reboot
Ready
Issues and workarounds
Boot process stops at grub prompt
Sometimes the grub.cfg file is missing. This can be tested by loading the grubsrcd.cfg file manually.
grub> configfile (hd0,gpt3)/boot/grub/grubsrcd.cfg
hd0: First disk
gpt3: Third partition, the one with the ISO file and the /boot folder.
If it is working it is enough to rename /mnt/usb/boot/grub/grubsrcd.cfg to /mnt/usb/boot/grub/grub.cfg.
grub error messages not readable
If grub shows an boot error, but it is unreadable because it is to fast, than put the follwing entries into the grub.cfg file.
set pager=1 set debug=all
MBR/BIOS boot needs ages (>1 minute) to start OS.
-
- Reformat data partition to ext4
- If the data partition is vfat, changing the partition label to uppercases might help (not tested)
# mkfs.fat -F32 -n BOOT /dev/sdX3
grub-install has errors
Possible some grub packages are missing.
# apt install grub-efi-amd64 grub-efi-amd64-bin grub-pc grub-pc-bin
Further useful links
My thanks go to the authors of the following pages, without which it would have taken me longer than I already took 🙂
- https://www.system-rescue.org/manual/Installing_SystemRescue_on_the_disk/
- https://wiki.archlinux.org/index.php/Multiboot_USB_drive
- https://unix.stackexchange.com/questions/273329/can-i-install-grub2-on-a-flash-drive-to-boot-both-bios-and-uefi
- https://www.slivermetal.org/2016/09/18/how-to-create-an-hybrid-uefi-gpt-bios-gptmbr-boot-usb-disk/
- https://www.preining.info/blog/2014/05/usb-stick-tails-systemrescuecd/
- https://www.gnu.org/software/grub/manual/grub/grub.html#Installing-GRUB-using-grub_002dinstall
- https://www.linux.com/training-tutorials/how-rescue-non-booting-grub-2-linux/
Last words
Nobody is perfect or no one has ever stopped learning. And particular using Linux there are still more than one way to reach the target. Therefore please provide your ideas.
Question, corrections, comments and of course suggestions for improvement please use the comment function below.