4.3. Förbereda filer för uppstart med USB-minne

To prepare the USB stick, we recommend to use a system where GNU/Linux is already running and where USB is supported. With current GNU/Linux systems the USB stick should be automatically recognized when you insert it. If it is not you should check that the usb-storage kernel module is loaded. When the USB stick is inserted, it will be mapped to a device named /dev/sdX, where the X is a letter in the range a-z. You should be able to see to which device the USB stick was mapped by running the command lsblk before and after inserting it. (The output of dmesg (as root) is another possible method for that.) To write to your stick, you may have to turn off its write protection switch.

[Varning] Varning

The procedures described in this section will destroy anything already on the device! Make very sure that you use the correct device name for your USB stick. If you use the wrong device the result could be that all information on, for example, a hard disk is lost.

4.3.1. Förbereder ett USB-minne med en hybrid CD/DVD-avbildning

Debian installation images for this architecture are created using the isohybrid technology; that means they can be written directly to a USB stick, which is a very easy way to make an installation media. Simply choose an image (such as the netinst, CD or DVD-1) that will fit on your USB stick. See Avsnitt 4.1, ”Officiella Debian GNU/Linux installationsavbildningar” to get an installation image.

Alternativt, för mycket små USB-pinnar, bara några få megabyte i storlek, kan du ladda ner mini.iso avbildningen från katalogen netboot (på den plats som nämns i Avsnitt 4.2.1, ”Var man får tag på installationsfiler”).

Den installationsbild du väljer ska skrivas direkt till USB-sticken och skriva över dess nuvarande innehåll. När du till exempel använder ett befintligt GNU / Linux-system kan bildfilen skrivas till ett USB-minne på följande sätt, efter att ha säkerställt att sticket är omonterat:

 #   cp  debian.iso  / dev /  sdX  
 #   sync 

Information om hur du gör detta på andra operativsystem finns i Debian CD FAQ .

[Viktigt] Viktigt

Bilden måste skrivas till hela diskenheten och inte till en partition, t.ex. / dev / sdb och inte / dev / sdb1. Använd inte verktyg som unetbootin som ändrar bilden.

[Viktigt] Viktigt

Att bara skriva installationsbilden till USB så här skulle fungera bra för de flesta användare. De andra alternativen nedan är mer komplexa, främst för personer med specialiserade behov.

Hybridbilden på pinnen upptar inte allt lagringsutrymme, så det kan vara värt att överväga att använda det fria utrymmet för att hålla firmwarefiler eller paket eller andra filer du väljer. Detta kan vara användbart om du bara har en pinne eller bara vill behålla allt du behöver på en enhet.

To do so, use cfdisk or any other partitioning tool to create an additional partition on the stick. Then create a (FAT) filesystem on the partition, mount it and copy or unpack the firmware onto it, for example with:

# mkdosfs -n FIRMWARE /dev/sdX3
# mount /dev/sdX3 /mnt
# cd /mnt
# tar zxvf /path/to/firmware.tar.gz
# cd /
# umount /mnt

Take care that you use the correct device name for your USB stick. The mkdosfs command is contained in the dosfstools Debian package.

[Notera] Notera

If you have chosen the mini.iso to be written to the USB stick, 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. Manuell kopiering av filer till USB-minnet

Prior to isohybrid technology being used for Debian installation images, the methods documented in the chapters below were used to prepare media for booting from USB devices. These have been superseded by the technique in Avsnitt 4.3.1, ”Förbereder ett USB-minne med en hybrid CD/DVD-avbildning”, but have been left here for educational and historical purposes and in case they are useful to some user.

An alternative to the method described in Avsnitt 4.3.1, ”Förbereder ett USB-minne med en hybrid CD/DVD-avbildning” is to manually copy the installer files, and also an installation image to the stick. Note that the USB stick should be at least 1 GB in size (smaller setups are possible using the files from netboot, following Avsnitt 4.3.3, ”Manuellt kopiera filerna till ett USB minne — det flexibla sättet”).

There is an all-in-one file hd-media/boot.img.gz which contains all the installer files (including the kernel) as well as syslinux and its configuration file.

[Notera] Notera

Observera att, även om det är bekvämt, denna metod har en stor nackdel: den logiska storleken för enheten kommer att vara begränsad till 1 GB, även om kapaciteten för USB-minnet är större. Du kommer att behöva partitionera om USB-minnet och skapa nya filsystem för att få dess fullständiga kapacitet tillbaka om du någon gång vill använda det för andra ändamål.

Simply extract this image directly to your USB stick:

# 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; see Avsnitt 4.1, ”Officiella Debian GNU/Linux installationsavbildningar”) to it. Unmount the stick (umount /mnt) and you are done.

4.3.3. Manuellt kopiera filerna till ett USB minne — det flexibla sättet

Om du vill ha mer flexibilitet eller bara vill veta vad som händer så bör du använda följande metod att lägga in filerna på ditt minne. En fördel av att använda denna metod är att — om kapaciteten för ditt USB-minne är tillräckligt stort — du har alternativet att kopiera en vilken ISO-avbildning (även en DVD avbildning, till det.

4.3.3.1. Partitioning and adding a boot loader

Vi kommer nu att visa hur man ställer in USB-minnet att använda första partitionen, istället för hela enheten.

För att kunna starta kärnan efter uppstart från USB-minnet så lägger vi på en starthanterare på minnet. Även om valfri starthanterare bör fungera så är det bekvämt att använda syslinux, eftersom den använder en FAT16-partition och kan konfigureras om genom att redigera en textfil. Alla operativsystem som har stöd för FAT-filsystemet kan användas för att göra ändringar i konfigurationen av starthanteraren.

First, you need to install the syslinux and mtools packages on your system.

[Notera] Notera

Since most USB sticks come pre-configured with a single FAT16 partition, you probably won't have to repartition or reformat the stick. If you have to do that anyway, use cfdisk or any other partitioning tool to create a FAT16 partition now[3], and then install an MBR using:

# cat /usr/lib/syslinux/mbr/mbr.bin 
>/dev/sdX

Now create the filesystem using:

# mkdosfs /dev/sdX1

Take care that you use the correct device name for your USB stick. The mkdosfs command is contained in the dosfstools Debian package.

Having a correctly partitioned USB stick (now), you need to put syslinux on the FAT16 partition with:

# syslinux /dev/sdX1

Again, take care that you use the correct device name. The partition must not be mounted when starting syslinux. This procedure writes a boot sector to the partition and creates the file ldlinux.sys which contains the boot loader code.

4.3.3.2. Adding the installer files

There are two different installation variants to choose here: The hd-media variant needs an installation ISO file on the stick, to load installer modules and the base system from. The netboot installer however will load all that from a Debian mirror.

According to your choice, you have to download some installer files from the hd-media or netboot subdirectory of debian/dists/bullseye/main/installer-i386/current/images/ on any Debian mirror:

  • vmlinuz or linux (kernel binary)

  • initrd.gz (initial ramdisk image)

You can choose between either the text-based version of the installer (the files can be found directly in hd-media or netboot) or the graphical version (look in the respective gtk subdirectories).

Then mount the partition (mount /dev/sdX1 /mnt) and copy the downloaded files to the root directory of the stick.

Next you should create a text file named syslinux.cfg in the root directory of the stick as configuration file for syslinux, which at a bare minimum should contain the following line:

default vmlinuz initrd=initrd.gz

Change the name of the kernel binary to linux if you used files from netboot.

For the graphical installer (from gtk) you should add vga=788 at the end of the line. Other parameters can be appended as desired.

Lägg till en prompt 1-rad för att aktivera startprompt för att tillåta ytterligare parametertillägg.

If you used files from hd-media, you should now copy the ISO file of a Debian installation image onto the stick. (For the netboot variant this is not needed.)

You can use either a netinst or a full CD/DVD image (see Avsnitt 4.1, ”Officiella Debian GNU/Linux installationsavbildningar”). Be sure to select one that fits on your stick. Note that the netboot mini.iso image is not usable for this purpose.

When you are done, unmount the USB memory stick (umount /mnt).



[3] Don't forget to activate the bootable flag.