- BootDev
- grub.cfg (кликните на кнопку «Copy» для копирования)
- Multiboot USB drive
- Using GRUB and loopback devices
- Preparation
- Installing GRUB
- Simple installation
- Hybrid UEFI GPT + BIOS GPT/MBR boot
- Configuring GRUB
- Using a template
- Manual configuration
- Boot entries
- Arch Linux monthly release
- MemTest86+
- Archboot
- Using Syslinux and memdisk
- Preparation
- Install the memdisk module
- Configuration
- Automated tools
- See also
BootDev
И так, после того как мы сконфигурировали загрузчик Grub4Dos, в первой части данного материала, перейдем к загрузчику GRUB2.
Первое что необходимо сказать о данном загрузчике, EFI версия GRUB2 отличается от BIOS версии. GRUB2 EFI построен на 64/32 битной архитектуре, и загрузка некоторых элементов в нем невозможна. То есть, запустить Grub4Dos из GRUB2 EFI не удастся, так же, как и не удастся использовать MEMDISK из загрузчика SYSLINUX. Кроме того, EFI версия загрузчика не поддерживает загрузку MBR дисков. Хотя, в BIOS версии GRUB2 это все сделать можно.
О поддержке ISO файлов в GRUB2. Подключать их можно только монтированием, для просмотра и последующей загрузки его содержимого. Нет возможности загрузить ISO образ целиком в память, или загрузить его с первого сектора, как, к примеру, это умеет делать Grub4Dos.
Напомню, содержимое флешки представленное в первой части статьи:
В виду указанных выше особенностей загрузчика GRUB2 в EFI исполнении, не удалось загрузить следующие LiveCD:
Hiren’s BootCD — не удалось запустить вообще. В GRUB2 EFI отсутствует команда ntldr.
Dr.Web LiveDisk — Запуск данного диска возможен при распаковке содержимого образа диска, в корень раздела флешки, но только для файловой системы FAT32. Мы используем NTFS, поэтому запуск данного LiveCD не удался.
Ultimate Boot CD — из набора программ данного диска, удалось запустить только PartedMagic. Остальные приложения отказались грузиться, так как представляли собой образы дисков.
Перейдем к конфигурационному файлу загрузчика GRUB2. Открываем файл grub.cfg в любимом текстовом редакторе (рекомендую Notepad++), так же удаляем его содержимое и вставляем следующий код.
grub.cfg (кликните на кнопку «Copy» для копирования)
insmod part_gpt insmod part_msdos insmod efi_gop insmod efi_uga insmod gfxterm insmod loopback insmod all_video insmod gzio insmod ext2 insmod fat insmod iso9660 insmod ntfs loadfont "$/fonts/unicode.pf2" GRUB_GFXMODE=1024x768 gfxmode=1024x768 if terminal_output --append gfxterm then terminal_output --remove console fi color_normal=black/black menu_color_normal=white/cyan menu_color_highlight=yellow/light-magenta background_color gray set timeout=60 set default=0 set pager=1 echo -e "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" echo "http://www.BootDev.ru/" echo -n "Загрузка. " sleep --interruptible -v 5 menuentry "(1) SystemRescueCd" --hotkey="1" < loopback loop /ISO/systemrescuecd-x86-4.7.1.iso linux (loop)/isolinux/rescue32 isoloop=/ISO/systemrescuecd-x86-4.7.1.iso setkmap=us docache dostartx initrd (loop)/isolinux/initram.igz >menuentry "(2) PartetMagic из образа Ultimate Boot CD" --hotkey="2" < loopback loop /ISO/ubcd535.iso linux (loop)/pmagic/bzImage edd=on vga=normal vmalloc=384MiB iso_filename=/ISO/ubcd535.iso initrd (loop)/pmagic/initrd.img >menuentry "(3) Rescatux" --hotkey="3" < loopback loop /ISO/rescatux-0.40b5.iso linux (loop)/live/vmlinuz1 boot=live config boot=live config quiet splash selinux=1 security=selinux enforcing=0 locales=en_US.UTF-8 boot=live config quiet splash selinux=1 security=selinux enforcing=0 locales=en_US.UTF-8 findiso=/ISO/rescatux-0.40b5.iso initrd (loop)/live/initrd1.img >menuentry "(4) Super Grub2 Disk - BIOS функции не работают!" --hotkey="4" < loopback loop /ISO/super_grub2_disk_hybrid_2.02s2-beta1.iso set root=(loop) set prefix=(loop)/boot/grub/ configfile /boot/grub/grub.cfg >menuentry "(5) MemTest86 от PassMark" --hotkey="5" < chainloader /ISO/memtest.efi boot >menuentry "" < echo " " >menuentry "(F1) Инфо о дисках системы и текущем видео режиме" --hotkey="f1" < echo " www.BootDev.ru" echo "" echo "[---------------- Информация о дисках системы ----------------]" ls -l echo "[---------------- Информация о видео режимах ----------------]" videoinfo echo "" echo "Нажмите клавишу ESC для возврата в главное меню. " sleep --interruptible 9999 >menuentry "" < echo " " >menuentry "(r) Перезагрузить компьютер" --hotkey="r" < reboot >menuentry "(h) Выключить компьютер" --hotkey="r"
В меню добавлен MemTest86 от PassMark. Для работоспособности соответствующего пункта, скачайте файл memtest.efi и скопируйте его в папку ISO.
Проверим полученный результат в виртуальной машине. Для этого воспользуемся VirtualBox’ом. О том, как загрузиться c флешки в VirtualBox читаем здесь.
Multiboot USB drive
A multiboot USB flash drive allows booting multiple ISO files from a single device. The ISO files can be copied to the device and booted directly without unpacking them first. There are multiple methods available, but they may not work for all ISO images.
Using GRUB and loopback devices
This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.
- only a single partition required
- all ISO files are found in one directory
- adding and removing ISO files is simple
- not all ISO images are compatible
- the original boot menu for the ISO file is not shown
- it can be difficult to find a working boot entry
Preparation
This article or section needs expansion.
Create at least one partition and a filesystem supported by GRUB on the USB drive. See Partitioning and File systems#Create a file system. Choose the size based on the total size of the ISO files that you want to store on the drive, and plan for extra space for the bootloader.
Installing GRUB
Simple installation
Mount the filesystem located on the USB drive:
Create the directory /boot:
Install GRUB on the USB drive:
# grub-install --target=i386-pc --recheck --boot-directory=/mnt/boot /dev/sdX
In case you want to boot ISOs in UEFI mode, you have to install grub for the UEFI target:
# grub-install --target=x86_64-efi --removable --boot-directory=/mnt/boot --efi-directory=/mnt
For UEFI, the partition has to be the first one in an MBR partition table and formatted with FAT32.
Hybrid UEFI GPT + BIOS GPT/MBR boot
This configuration is useful for creating a universal USB key, bootable everywhere. First of all you must create a GPT partition table on your device. You need at least 3 partitions:
- A BIOS boot partition (gdisk type code EF02 ). This partition must be 1 MiB in size
- An EFI System partition (gdisk type code EF00 with a FAT32 filesystem). This partition can be as small as 50 MiB.
- Your data partition (use a filesystem supported by GRUB). This partition can take up the rest of the space of your drive.
Next you must create a hybrid MBR partition table. Without it, a BIOS MBR based system will not boot. It will not find the partitions it expects to find.
Hybrid MBR partition table creation example using gdisk:
Command (? for help): r Recovery/transformation command (? for help): h WARNING! Hybrid MBRs are flaky and dangerous! If you decide not to use one, just hit the Enter key at the below prompt and your MBR partition table will be untouched. Type from one to three GPT partition numbers, separated by spaces, to be added to the hybrid MBR, in sequence: 1 2 3 Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N): N Creating entry for GPT partition #1 (MBR partition #1) Enter an MBR hex code (default EF): Set the bootable flag? (Y/N): N Creating entry for GPT partition #2 (MBR partition #2) Enter an MBR hex code (default EF): Set the bootable flag? (Y/N): N Creating entry for GPT partition #3 (MBR partition #3) Enter an MBR hex code (default 83): Set the bootable flag? (Y/N): Y Recovery/transformation command (? for help): x Expert command (? for help): h Expert command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): Y
Do not forget to format the partitions :
# mkfs.fat -F32 /dev/sdX2 # mkfs.ext4 /dev/sdX3
You can now install GRUB to support both EFI + GPT and BIOS + GPT/MBR. The GRUB configuration (—boot-directory) can be kept in the same place.
First, you need to mount the EFI system partition and the data partition of your USB drive.
An example of this would be as follows:
# mount /dev/sdX3 /mnt # mkdir /mnt/boot /mnt/efi # mount /dev/sdX2 /mnt/efi
Then, you can install GRUB for UEFI with:
In most cases EFI_MOUNTPOINT will correspond to the /mnt/efi directory on your mounted USB disk. DATA_MOUNTPOINT is where your data partition is mounted. In this example it would be the mount point of sdX3, /mnt .
# grub-install --target=x86_64-efi --recheck --removable --efi-directory=/EFI_MOUNTPOINT --boot-directory=/DATA_MOUNTPOINT/boot
# grub-install --target=i386-pc --recheck --boot-directory=/DATA_MOUNTPOINT/boot /dev/sdX
As an additional fallback, you can also install GRUB on your MBR-bootable data partition:
# grub-install --target=i386-pc --recheck --boot-directory=/DATA_MOUNTPOINT/boot /dev/sdX3
Configuring GRUB
Using a template
There are some git projects which provide some pre-existing GRUB configuration files, and a nice generic grub.cfg which can be used to load the other boot entries on demand, showing them only if the specified ISO files — or folders containing them — are present on the drive.
Manual configuration
For the purpose of multiboot USB drive it is easier to edit grub.cfg by hand instead of generating it. Alternatively, make the following changes in /etc/grub.d/40_custom or /mnt/boot/grub/custom.cfg and generate /mnt/boot/grub/grub.cfg using grub-mkconfig.
As it is recommend to use a persistent name instead of /dev/sdxY to identify the partition on the USB drive where the image files are located, define a variable for convenience to hold the value. If the ISO images are on the same partition as GRUB, use the following to read the UUID at boot time:
# path to the partition holding ISO images (using UUID) probe -u $root --set=rootuuid set imgdevpath="/dev/disk/by-uuid/$rootuuid"
Or specify the UUID explicitly:
# path to the partition holding ISO images (using UUID) set imgdevpath
Alternatively, use the device label instead of UUID:
# path to the partition holding ISO images (using labels) set imgdevpath
The necessary UUID or label can be found using lsblk -f . Do not use the same label as the Arch ISO for the USB device, otherwise the boot process will fail.
To complete the configuration, a boot entry for each ISO image has to be added below this header, see the next section for examples.
Boot entries
It is assumed that the ISO images are stored in the boot/iso/ directory on the same filesystem where GRUB is installed. Otherwise it would be necessary to prefix the path to ISO file with device identification when using the loopback command, for example loopback loop (hd1,2)$isofile . As this identification of devices is not persistent, it is not used in the examples in this section.
One can use persistent block device naming like so. Replace the UUID according to your ISO filesystem UUID.
# define globally (i.e outside any menuentry) insmod search_fs_uuid search --no-floppy --set=isopart --fs-uuid 123-456 # later use inside each menuentry instead loopback loop ($isopart)$isofile
Tip: For a list of kernel parameters, see the kernel’s command-line parameter documentation. For more examples of boot entries, see the GRUB upstream documentation or the documentation for the distribution you wish to boot.
Arch Linux monthly release
menuentry '[loopback]archlinux-2020.10.01-x86_64.iso' < set isofile='/boot/iso/archlinux-2020.10.01-x86_64.iso' loopback loop $isofile linux (loop)/arch/boot/x86_64/vmlinuz-linux img_dev=$imgdevpath img_loop=$isofile earlymodules=loop initrd (loop)/arch/boot/intel-ucode.img (loop)/arch/boot/amd-ucode.img (loop)/arch/boot/x86_64/initramfs-linux.img >
See README.bootparams for archiso options supported in kernel command line.
MemTest86+
MemTest86+ is included in the monthly ISO.
menuentry '[loopback]archlinux-2023.03.01-x86_64.iso MemTest86+' < set isofile='/boot/iso/archlinux-2023.03.01-x86_64.iso' loopback loop $isofile linux (loop)/boot/memtest86+/memtest.efi >
Archboot
menuentry '[loopback]archlinux-2014.11-1-archboot' < set isofile='/boot/iso/archlinux-2014.11-1-archboot.iso' loopback loop $isofile linux (loop)/boot/vmlinuz_x86_64 iso_loop_dev=$imgdevpath iso_loop_path=$isofile initrd (loop)/boot/initramfs_x86_64.img >
Using Syslinux and memdisk
Using the memdisk module, the ISO image is loaded into memory, and its bootloader is loaded. Make sure that the system that will boot this USB drive has sufficient amount of memory for the image file and running operating system.
Preparation
Make sure that the USB drive is properly partitioned and that there is a partition with file system supported by Syslinux, for example fat32 or ext4. Then install Syslinux to this partition, see Syslinux#Installation on BIOS.
Install the memdisk module
The memdisk module was not installed during Syslinux installation, it has to be installed manually. Mount the partition where Syslinux is installed to /mnt/ and copy the memdisk module to the same directory where Syslinux is installed:
# cp /usr/lib/syslinux/bios/memdisk /mnt/boot/syslinux/
Configuration
After copying the ISO files on the USB drive, edit the Syslinux configuration file and create menu entries for the ISO images. The basic entry looks like this:
LABEL some_label LINUX memdisk INITRD /path/to/image.iso APPEND iso
See memdisk on Syslinux wiki for more configuration options.
Automated tools
- GRUB2 Live ISO Multiboot (GLIM) — A set of GRUB configuration files to turn a VFAT formatted USB memory stick with GNU/Linux distribution ISO images into a multiboot USB drive.
- liveusb-builder — A script suite to create multiboot USB stick for GNU/Linux distributions
- MultiBootUSB — A cross platform Python software with CLI and GUI interfaces which allows you to install and remove multiple live Linux images on a USB stick.
- Ventoy — An open source tool to create bootable USB drive for ISO/WIM/IMG/VHD(x)/EFI files. You do not need to format the disk over and over, you just need to copy the files to the USB drive and boot them directly.