4.3. 为从 U 盘引导准备文件

为了准备 U 盘,您需要一台运行的支持 USB 的 GNU/Linux 系统。当前的 GNU/Linux 系统会在您插入 U 盘的时候自动识别。如果没有,您应该确认 usb-storage 内核模块是否已经被加载。U 盘插入后,它将被映射到名为 /dev/sdX 的设备,其中的 X 是 a-z 的字母。您可以通过运行 dmesg 在插入 U 盘后确认是否被正确映射。要写入信息,请要先打开它上面的写保护开关。

[警告] 警告

采用这种方法将销毁设备上已有的任何内容!请确认您使用了正确的 U 盘设备名。如果搞错,比如写成硬盘,将造成该设备上的所有信息丢失。

4.3.1. Preparing a USB stick using a hybrid CD/DVD image

Debian installation images can now be written directly to a USB stick, which is a very easy way to make a bootable USB stick. Simply choose an image (such as the netinst, CD, DVD-1, or netboot) that will fit on your USB stick. See 第 4.1 节 “Official Debian GNU/Linux installation images” to get an installation image.

另外,对于只有几 M 的小容量 U 盘,您可以从 netboot 目录下载 mini.iso 映像(位于 第 4.2.1 节 “在哪里能找到安装映像”)。

The installation image you choose should be written directly to the USB stick, overwriting its current contents. For example, when using an existing GNU/Linux system, the image file can be written to a USB stick as follows, after having made sure that the stick is unmounted:

# cp debian.iso /dev/sdX
# sync

Information about how to do this on other operating systems can be found in the Debian CD FAQ.

[重要] 重要

The image must be written to the whole-disk device and not a partition, e.g. /dev/sdb and not /dev/sdb1. Do not use tools like unetbootin which alter the image.

[重要] 重要

Simply writing the installation image to USB like this should work fine for most users. The other options below are more complex, mainly for people with specialised needs.

The hybrid image on the stick does not occupy all the storage space, so it may be worth considering using the free space to hold firmware files or packages or any other files of your choice. This could be useful if you have only one stick or just want to keep everything you need on one device.

Create a second, FAT partition on the stick, mount the partition and copy or unpack the firmware onto it. For example:

# mount /dev/sdX2 /mnt
# cd /mnt
# tar zxvf /path/to/firmware.tar.gz
# cd /
# umount /mnt

You might have written the mini.iso to the USB stick. In this case the second partition doesn't have to be created as, very nicely, it will already be present. Unplugging and replugging the USB stick should make the two partitions visible.

4.3.2. 手动复制文件到 U 盘。

An alternative way to set up your USB stick is to manually copy the installer files, and also an installation image to it. Note that the USB stick should be at least 1 GB in size (smaller setups are possible if you follow 第 4.3.3 节 “手动复制文件到 U 盘 — 灵活的方法”).

有一个文件合集 hd-media/boot.img.gz 包含所有的安装程序文件(包括内核) 以及 syslinux 和对应的配置文件

需要注意的是,虽然方便,但该方法有一个主要缺点:即使 U 盘容量更大,该设备的逻辑尺寸还是限制在 1 GB。如果您要该 U 盘作其他用途,需要为它重新分区,为剩余容量创建一个新的文件系统。

使用该映象只须将它直接解压到 U 盘:

# zcat boot.img.gz > /dev/sdX

After that, mount the USB memory stick (mount /dev/sdX /mnt), which will now have a FAT filesystem on it, and copy a Debian ISO image (netinst or full CD/DVD) to it. Unmount the stick (umount /mnt) and you are done.

4.3.3. 手动复制文件到 U 盘 — 灵活的方法

If you like more flexibility or just want to know what's going on, you should use the following method to put the files on your stick. One advantage of using this method is that — if the capacity of your USB stick is large enough — you have the option of copying any ISO image, even a DVD image, to it.

4.3.3.1. 给 U 盘分区

我们将展示如何使用 U 盘的第一个分区,而不是整个设备。

[注意] 注意

由于大多数 U 盘预先设置了一个单独的 FAT16 分区,您可能不需要重新分区或者格式化 U 盘。如果必须要做,请使用 cfdisk 或者其他的分区工具来创建一个 FAT16 分区[3],安装 MBR 使用:

# install-mbr /dev/sdX

其中 install-mbr 命令包含在 mbr Debian 软件包内。然后建立文件系统:

# mkdosfs /dev/sdX1

注意,请使用 U 盘正确的设备名称。mkdosfs 命令包含在 dosfstools Debian 软件包内。

为了在 U 盘引导后启动内核,我们要在 U 盘上放入一个 boot loader。尽管任何 boot loader (比如 lilo)都应该可以胜任,不过还是使用 syslinux 更方便。主要原因是它可以使用 FAT16 分区,而且只需要编辑一个文本文件就能对其进行配置。任何支持 FAT 文件系统的操作系统都可以用来改变 boot loader 的配置文件。

为了把 syslinux 放到 U 盘的 FAT16 分区上,请在您的系统中安装 syslinuxmtools 软件包,然后执行:

# syslinux /dev/sdX1

再提醒一次,请确认您使用的是正确的设备名称。启动 syslinux 的时候该分区不能被挂载,因为该过程会向分区的引导扇区写入数据,并且创建包含 boot loader 代码的 ldlinux.sys 文件。

4.3.3.2. 添加安装程序映像

Mount the partition (mount /dev/sdX1 /mnt) and copy the following installer image files to the stick:

  • vmlinuz or linux (kernel binary)

  • initrd.gz (initial ramdisk image)

You can choose between either the text-based or the graphical version of the installer. The latter can be found in the gtk subdirectory. If you want to rename the files, please note that syslinux can only process DOS (8.3) file names.

Next you should create a syslinux.cfg configuration file, which at a bare minimum should contain the following line (change the name of the kernel binary to linux if you used a netboot image):

default vmlinuz initrd=initrd.gz

For the graphical installer you should add vga=788 to the line. Other parameters can be appended as desired.

添加 prompt 1 一行,使得引导提示符可以允许附加参数。

If you used an hd-media image, you should now copy the ISO file of a Debian ISO image[4] onto the stick. When you are done, unmount the USB memory stick (umount /mnt).



[3] 别忘记设置 bootable 引导标记。

[4] You can use either a netinst or a full CD/DVD image (see 第 4.1 节 “Official Debian GNU/Linux installation images”). Be sure to select one that fits. Note that the netboot mini.iso image is not usable for this purpose.