This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

Installieren von Gentoo auf einem bootfähigen USB Stick

From Gentoo Wiki (test)
Jump to:navigation Jump to:search
This page is a translated version of the page Install Gentoo on a bootable USB stick and the translation is 100% complete.

Das Booten von Gentoo auf einem USB Stick ist wirklich sehr einfach. Die Hauptherausforderung dabei ist, eine initiale Ramdisk zu erstellen und alle Treiber von den Geräten einzufügen, für welche man es verwenden möchte. Dieser Artikel soll beschreiben, wie man Gentoo auf einem USB Stick installieren kann, sodass es auf jedem Computer booten kann. Diese Installation wird wie eine normale Desktopinstallation sein und Änderungen werden bleiben.

Vorbereitung

Notiz
Diese Anleitung nimmt an, dass die verwendete Plattform Gentoo Linux ist. Die meisten Arbeitsschritte können allerdings bei jeder Distribution gemacht werden. Übersetze einfach die Art und Weise von Gentoo, bestimmte Dinge zu tuen, in die einer Anderen Distribution (wie z.B. das Installieren von Software)

Wir beginnen damit, einige notwendige Pakete zu installieren. Die wichtigsten von diesen sind der Kernel und das sys-kernel/genkernel Paket.

root #emerge --ask sys-kernel/gentoo-sources sys-kernel/genkernel

Um Paket-spezifische Useflags hinzuzufügen, erstelle folgende Datei /etc/portage/package.use/:

DATEI /etc/portage/package.use/sys-apps
sys-apps/busybox static

Als nächstes installiere sys-apps/busybox:

root #emerge --ask sys-apps/busybox

Kompilierung des Kernels

Mache die notwendigen Änderungen am Kernel und compiliere ihn. Schaue bitte bei Configuring the Linux kernel und kernel configuration guide nach, um mehr Details zu erhalten. Denke daran, dass eine generelle Kernel hier angebrachter ist, weil Gentoo dann auf mehr Maschinen booten wird.

Während der Konfiguration ist es möglich, Module zu compilieren und diese dann zu der initramfs hinzuzufügen und sie dadurch beim booten zu laden.

root #mkdir /tmp/boot
root #genkernel --firmware --busybox --disklabel --bootdir=/tmp/boot --no-symlink --all-ramdisk-modules --install all

Dieser Befehl wird einige Zeit in Anspruch nehmen, weil er den Ausgangskernel baut, eine Ramdisk erstellt und alle Dateien in /tmp/boot kopiert.

root #ls /tmp/boot/
initramfs-genkernel-x86_64-3.5.2-gentoo
kernel-genkernel-x86_64-3.5.2-gentoo
System.map-genkernel-x86_64-3.5.2-gentoo

Vorbereiten des USB Sticks

Create 2 partitions on the drive (assuming the installation will have a /boot and a / (root) partition). We assume that the USB stick is at /dev/sdb (run dmesg immediately after plugging in the USB stick to see which device is being used).

root #fdisk /dev/sdb
Command (m for help): d
Selected partition 1
 
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-4001759, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4001759, default 4001759): +100M
 
Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2):  
Using default value 2
First sector (206848-4001759, default 206848): 
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-4001759, default 4001759): 
Using default value 4001759
 
Command (m for help): a
Partition number (1-4): 1
 
Command (m for help): p
 
Disk /dev/sdb: 2048 MB, 2048901120 bytes
255 heads, 63 sectors/track, 249 cylinders, total 4001760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x001663df
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048      206847      102400   83  Linux
/dev/sdb2          206848     4001759     1897456   83  Linux
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.

Stelle sicher, dass die erste Partition bootfähig ist (ein Befehl wechselt das Bootflag)

Now format the new partitions. In the example we use the ext2 file system but another file system for the / partition can be used if it is supported in the kernel. Notice that during the formatting operation, a label is assigned to the partitions. This is important because it will be how the root file system is detected later as the USB stick can be booted on systems where the drive letter allocation is completely different. This is related to the --disklabel option of the genkernel command line earlier.

root #mkfs.ext2 -L GENTOO_USB_BOOT /dev/sdb1
root #mkfs.ext2 -L GENTOO_USB_ROOT /dev/sdb2

Gentoo stage 3 Installation

With the kernel, ramdisk and file systems ready, we now need the minimal installation to be performed. This includes a fresh stage3 as well as a Portage tree snapshot.

Für dieses Beispiel wird stage3-amd64-20120621.tar.bz2 und portage-latest.tar.xz genutzt. Das nächste Stück ist das Selbe wie in dem Handbuch zur Gentooinstallation beschrieben.

root #mount /dev/sdb2 /mnt/gentoo
root #cd /mnt/gentoo
root #tar -xpf ~/Download/stage3-amd64-20120621.tar.bz2
root #cd usr
root #tar -xpf ~/Download/portage-latest.tar.xz
root #mount /dev/sdb1 /mnt/gentoo/boot
root #cp /tmp/boot/* /mnt/gentoo/boot

Der nächste Teil beinhaltet die Stücke einer Gentooinstallation, welche speziell für die Installation auf einem USB Stick sind. Es wird geraten, das Gentoo handbook zugleich mit dem beachten dieser Informationen zu nutzen.

Bootloader

Um das neue System zu booten, muss der Bootloader auf dem USB Stick installiert werden.

The below sections give example configurations for lilo and syslinux.

Lilo

Emerge lilo (from within the chroot):

(chroot) #emerge sys-boot/lilo

Bearbeite etc/lilo.conf, sodass es die richtigen Informationen enthält.

Warnung
Diese Einstellungen sind sehr wichtig und werden nun Zeile für Zeile betrachtet.
DATEI /etc/lilo.confConfigure lilo.conf
boot=/dev/sdb              # The location of the USB Stick (currently)
lba32                      # use lba32 addressing (ignore)
compact                    # boot quickly by loading lots of blocks
                           # remove when there are problems with booting
prompt                     # Prompt for user input
timeout=20                 # Time to wait before default selection
default="Gentoo-352"       # Default selection after timeout
  
image=/boot/kernel-genkernel-x86_64-3.5.2-gentoo
	label="Gentoo-352"
	read-only
	root=/dev/ram0
	append="real_root=LABEL=GENTOO_USB_ROOT scandelay=5"
	initrd=/boot/initramfs-genkernel-x86_64-3.5.2-gentoo

Die Zeilen nach image sind alle einfach, aber die angefügte Zeile enthält interessante Informationen.

  • real_root=LABEL=GENTOO_USB_ROOT will use the label of the disk instead of /dev/sdb2 which is important because these device numbers move around depending on the number of hard disks in the computer or number of USB disk drives.
  • Also important for USB booting is the scandelay option, as USB devices need a little time to be detected by the kernel; that is what this option is for. When there are lots of modules booting takes a long time so it probably does not matter, but if there are only a few modules loaded then it is important, because the system could have booted before the kernel detects the USB device. Also, on newer machines with USB3 controllers it is necessary to add the xhci_hcd driver (built into the kernel or as a module).

Installiere nun LILO (mit der Konfiguration) auf dem USB Stick:

(chroot) #lilo
Warning: /dev/sdb is not on the first disk
Warning: The initial RAM disk is too big to fit between the kernel and
   the 15M-16M memory hole.  It will be loaded in the highest memory as
   though the configuration file specified "large-memory" and it will
   be assumed that the BIOS supports memory moves above 16M.
Added Gentoo-352 ? *
2 warnings were issued.

Die erste Warnung ist, weil wir den Bootloader nicht auf der Hautpartition des Computers installieren, sondern auf dem USB Stick. Die zweite ist nur ein Problem, wenn man alte Geräte verwendet; wenn das ein Problem ist, entferne Module von dem Kernel.

Syslinux

Warnung
Syslinux funktioniert im Moment nur mit ext{2,3,4}, btrfs, ntfs und dem fat Dateisystem.
(chroot) #emerge syslinux

Schiebe den Bootsektor auf das USB Stick.

(chroot) #dd bs=440 count=1 conv=notrunc if=/usr/share/syslinux/mbr.bin of=/dev/sdb

Konfiguriere nun den Bootloader.

(chroot) #mkdir /boot/syslinux
(chroot) #nano -w /boot/syslinux/syslinux.cfg
DATEI /boot/syslinux/syslinux.cfg
PROMPT 1
TIMEOUT 50
DEFAULT gentoo
 
LABEL gentoo
        LINUX ../kernel-genkernel-x86_64-3.5.2-gentoo
        APPEND root=LABEL=GENTOO_USB_ROOT scandelay=3 ro
        INITRD ../initramfs-genkernel-x86_64-3.5.2-gentoo
Notiz
Das ro in der APPEND Zeile bestimmt, das die Partition nur zum lesen, nicht aber zum schreiben eingehangen wird (was auf einem USB Stick empfohlen wird). Ersetze ro mit rw um zu erlauben, dass das System nach dem Booten verändert wird (sodass der Nutzer nicht erst eine andere Partition zum Speichern usw. einhängen muss).

Installiere als nächstes Syslinux auf dem USB Stick. Die --device /dev/sdb1 Option ist nicht unbedingt notwendig.

(chroot) #extlinux --device /dev/sdb1 --install /boot/syslinux

fstab

DATEI /etc/fstabConfigure the fstab file to work with labels
LABEL=GENTOO_USB_BOOT   /boot           ext2            noauto,noatime  1 2
LABEL=GENTOO_USB_ROOT   /               ext2            noatime         0 1
/dev/SWAP               none            swap            sw              0 0
/dev/cdrom              /mnt/cdrom      auto            noauto,ro       0 0
/dev/fd0                /mnt/floppy     auto            noauto          0 0

Tipps und Tricks

Trotzdem ist es auch möglich einfach ein Standard Gentoosystem zu nutzen, es ist erstrebenswert binäre Pakete auf einem Host zu compilieren und sie dann auf dem USB Stick zu installieren. Wenn die Maschine genug Speicher hat, kann man auch einfach /var/tmp in tmpfs einhängen und dadurch wird die Kompilierung auch wesentlich schneller.