Multiboot USB drive (简体中文) - ArchWiki

Jump to content

本文或本节需要翻译。要贡献翻译，请访问简体中文翻译团队。

附注： Partial translation, started 2022-09-30（在 Talk:Multiboot USB drive (简体中文)# 中讨论）
翻译状态：本文是 Multiboot USB drive 的翻译。上次翻译日期：2022-09-30。如果英文版本有所更改，则您可以帮助同步翻译。

Related articles

- GRUB
- Syslinux
- Archiso

多引导USB启动盘可以从单个设备引导多个ISO镜像文件。ISO镜像文件可以不需要解压复制到U盘上就可以启动。以下有多种可用的方案，但不一定兼容所有ISO镜像。

## GRUB引导器及loopback devices实现

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Reason: multiple style issues (Discuss in Talk:Multiboot USB drive (简体中文))

优点:

- 仅需要一个分区
- 所有ISO文件镜像可在同一个文件夹下被检测到
- 易于添加或移除ISO镜像文件

缺点:

- 并非所有镜像兼容
- the original boot menu for the ISO file is not shown
- it can be difficult to find a working boot entry

### 准备

This article or section needs expansion.

Reason: How much extra space is needed for the bootloader? (Discuss in Talk:Multiboot USB drive (简体中文))

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.

### 安装 GRUB引导器

#### 简单安装

挂载U盘:

    # mount /dev/sdXY /mnt

U盘上创建 /boot文件夹:

    # mkdir /mnt/boot

安装GRUB到U盘:

    # grub-install --target=i386-pc --recheck --boot-directory=/mnt/boot /dev/sdX

如果以UEFI启动镜像, 你需要按UEFI方式安装GRUB:

    # 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.

#### 混合 UEFI GPT + BIOS GPT/MBR 启动

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:

1. A BIOS boot partition (gdisk type code `EF02`). This partition must be 1 MiB in size
2. An EFI System partition (gdisk type code `EF00` with a FAT32 filesystem). This partition can be as small as 50 MiB.
3. 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:

    # gdisk /dev/sdX

    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 -p /mnt/boot/EFI
    # mount /dev/sdX2 /mnt/boot/EFI

Then, you can install GRUB for UEFI with:

In most cases `EFI_MOUNTPOINT` will correspond to the `/mnt/boot/EFI` subdirectory on your mounted USB disk.

    # grub-install --target=x86_64-efi --recheck --removable --efi-directory=/EFI_MOUNTPOINT --boot-directory=/DATA_MOUNTPOINT/boot

And for BIOS with:

    # 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

### 配置 GRUB

#### 参考模板

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.

Multiboot USB: https://github.com/hackerncoder/multibootusb

GLIM (GRUB2 Live ISO Multiboot): https://github.com/thias/glim

#### 手动配置

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:

    /mnt/boot/grub/grub.cfg

    # 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:

    /mnt/boot/grub/grub.cfg

    # path to the partition holding ISO images (using UUID)
    set imgdevpath="/dev/disk/by-uuid/UUID_value"

Alternatively, use the device label instead of UUID:

    /mnt/boot/grub/grub.cfg

    # path to the partition holding ISO images (using labels)
    set imgdevpath="/dev/disk/by-label/label_value"

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.

### 启动项

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

Also see archiso.

    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-2020.10.01-x86_64.iso' {
    	set isofile='/boot/iso/archlinux-2020.10.01-x86_64.iso'
    	loopback loop $isofile
    	linux16 (loop)/arch/boot/memtest
    }

#### archboot

See Archboot Homepage.

    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
    }

## Syslinux和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.

### 准备

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.

### 安装 memdisk 模块

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/

### 配置

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:

    boot/syslinux/syslinux.cfg

    LABEL some_label
        LINUX memdisk
        INITRD /path/to/image.iso
        APPEND iso

See memdisk on Syslinux wiki for more configuration options.

## 自动制作工具实现(开源软件)

- 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.

  https://github.com/thias/glim || not packaged? search in AUR

- liveusb-builder — A script suite to create multiboot USB stick for GNU/Linux distributions

  https://github.com/mytbk/liveusb-builder || liveusb-builder-gitAUR

- MultiBootUSB — 一个具有CLI和GUI界面的跨平台Python软件，可添加或删除多个Linux LIVE映像环境到U盘。

  https://github.com/mbusb/multibootusb || multibootusbAUR

- MultiSystem — 一个图形化工具，可添加或删除多个Linux LIVE映像环境到U盘。

  http://liveusb.info/dotclear/ || multisystemAUR

- Ventoy — 一个开源工具，为ISO/WIM/IMG/VHD(x)/EFI文件创建可引导的USB驱动器。不需要一遍又一遍格式化磁盘，只需要复制文件到U盘即可启动。

  https://www.ventoy.net/ || ventoy-binAUR

## 更多参考

- GRUB:
  - https://help.ubuntu.com/community/Grub2/ISOBoot/Examples
  - https://help.ubuntu.com/community/Grub2/ISOBoot
  - GRUB Live ISO Multiboot - GRUB configurations for booting ISO images
- Syslinux:
  - Boot an ISO image

Category:

- Installation process (简体中文)

Hidden categories:

- Pages or sections flagged with Template:Translateme (简体中文)
- Pages or sections flagged with Template:Style
- Pages or sections flagged with Template:Expansion
- Pages with broken section links
- Pages with missing package links