Wie richte ich Xen mit dom 0 Alpine Linux, LUKS LVM und GRUB auf einer UEFI-Plattform ein?

593
Marco Boom

Ich möchte folgendes Setup haben: ein System im UEFI-Modus mit einer Festplatte mit GPT-Partitionen. Die Festplatte sollte eine (unverschlüsselte) EFI-Systempartition, eine verschlüsselte Bootpartition und eine verschlüsselte LVM-Partition enthalten. GRUB sollte der Bootloader sein und obendrein möchte ich den Xen-Kernel und Alpine Linux als Dom 0.

Um Alpine Linux ohne Xen installieren zu können, habe ich das ISO-Image heruntergeladen und mit Rufus auf ein USB-Laufwerk gebrannt (GPT, Iso-Modus). Dann boote ich von einem USB-Laufwerk im UEFI-Modus und ich kann Alpine erfolgreich installieren.

Um Alpine Linux mit den angepassten Partitionen zu installieren, führe ich die folgenden Befehle aus:

Alpine Linux einrichten:

setup-keymap us us-intl setup-hostname -n localhost hostname=$(cat $ROOT/etc/hostname 2>/dev/null) setup-interfaces -i <<EOF auto lo iface lo inet loopback  auto eth0 iface eth0 inet dhcp hostname $hostname  auto eth1 iface eth1 inet dhcp hostname $hostname EOF /etc/init.d/networking --quiet start >/dev/null passwd setup-timezone -z Europe/Amsterdam setup-proxy none setup-apkrepos -f setup-sshd -c none setup-ntp -c chrony 

Tools installieren:

apk update apk add cryptsetup e2fsprogs grub-efi haveged lvm2 parted rc-service haveged start # optionally: only needed to wipe disks 

Festplattenpartitionen erstellen:

parted --script /dev/sda mklabel gpt parted --script --align=optimal /dev/sda mkpart fat32 0% 538MB parted --script /dev/sda set 1 esp on parted --script --align=optimal /dev/sda mkpart non-fs 538MB 748MB parted --script --align=optimal /dev/sda mkpart non-fs 748MB 100% parted --script /dev/sda set 3 LVM on  # optionally: wiping disks, but this takes too much time for test setups haveged -n 0 | dd of=/dev/sda1 haveged -n 0 | dd of=/dev/sda2 haveged -n 0 | dd of=/dev/sda3 

Dateisysteme erstellen:

mkfs.vfat /dev/sda1 # fat32 for ESP  cryptsetup luksFormat --type luks /dev/sda2 cryptsetup open --type luks /dev/sda2 bootcrypt mkfs.ext4 /dev/mapper/bootcrypt # encrypted boot partition with ext4  cryptsetup luksFormat --type luks2 /dev/sda3 cryptsetup open --type luks2 /dev/sda3 lvmcrypt pvcreate /dev/mapper/lvmcrypt # encrypted lvm partition vgcreate vg0 /dev/mapper/lvmcrypt lvcreate -L 512M vg0 -n swap lvcreate -l 100%FREE vg0 -n root lvscan # check lvm partitions mkfs.ext4 /dev/vg0/root # ext4 on lvm root partition (alias /dev/mapper/vg0-root) mkswap /dev/vg0/swap # swap lvm partition (alias /dev/mapper/vg0-swap) 

Mounts und Ordner erstellen, Alpine Linux installieren:

mount -t ext4 /dev/vg0/root /mnt/ mkdir -p /mnt/boot/ mount -t ext4 /dev/mapper/bootcrypt /mnt/boot/ mkdir -p /mnt/boot/efi/ mount -t vfat /dev/sda1 /mnt/boot/efi/ USE_EFI=1 # seems to be ignored by the setup-disk script, can be removed setup-disk -m sys /mnt/ 

Konfiguration aktualisieren:

boot_UUID=$(blkid | awk "\$1 == \"/dev/sda2:\" { print \$2 }" | cut -d'"' -f2) lvm_UUID=$(blkid | awk "\$1 == \"/dev/sda3:\" { print \$2 }" | cut -d'"' -f2) root_UUID=$(blkid | awk "\$1 == \"/dev/mapper/vg0-root:\" { print \$2 }" | cut -d'"' -f2) swap_UUID=$(blkid | awk "\$1 == \"/dev/mapper/vg0-swap:\" { print \$2 }" | cut -d'"' -f2)  printf "target='bootcrypt'\n" >> /mnt/etc/conf.d/dmcrypt printf "source=UUID=\"$boot_UUID\"\n" >> /mnt/etc/conf.d/dmcrypt #chroot /mnt rc-update add dmcrypt boot (there seems to be a bug in openrc: https://github.com/OpenRC/openrc/issues/243) chroot /mnt ln -s /etc/init.d/dmcrypt /etc/runlevels/boot/dmcrypt # temporary workaround printf "UUID=$swap_UUID\tswap\tswap\tdefault\t0 0\n" >> /mnt/etc/fstab printf 'features="ata base ide scsi usb virtio ext4 lvm cryptsetup"\n' > /mnt/etc/mkinitfs/mkinitfs.conf mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)  mkdir -p /mnt/boot/grub/ mkdir -p /etc/default/ cat > /mnt/boot/grub/grub.cfg <<EOF set timeout=2 insmod all_video menuentry "Alpine Linux" { linux /boot/vmlinuz-vanilla modules=sd-mod,usb-storage,ext4 cryptroot=UUID=$lvm_UUID cryptdm=lvmcrypt root=UUID=$root_UUID nomodeset quiet rootfstype=ext4 initrd /boot/initramfs-vanilla } EOF cat >> /etc/default/grub <<EOF GRUB_ENABLE_CRYPTODISK=y EOF grub-install --target=x86_64-efi --bootloader-id=alpine --boot-directory=/mnt/boot --efi-directory=/mnt/boot/efi --recheck --no-nvram install -D /mnt/boot/efi/EFI/alpine/grubx64.efi /mnt/boot/efi/EFI/boot/bootx64.efi 

Auf diese Weise fragt GRUB nach dem Passwort der Bootpartition, initramfs (oder dem Kernel oder etwas anderem?) Fragt nach dem Passwort der lvm-Partition und schließlich fragt OpenRC nach dem Passwort der Bootpartition (Internet stellt genügend Quellen bereit, weshalb die Bootpartition zweimal entschlüsselt werden muss). .

Einrichtung abschließen:

umount /mnt/boot/efi/ umount /mnt/boot/ umount /mnt/ swapoff -a vgchange -a n cryptsetup luksClose lvmcrypt cryptsetup luksClose bootcrypt  reboot 

Zu diesem Zeitpunkt habe ich also das System im UEFI-Modus mit GPT-Partitionen, LUKS, LVM, GRUB und Alpine Linux. Ich kann Alpine Linux erwartungsgemäß verwenden und scheint keine Probleme zu haben.

Nun möchte ich Xen installieren und folgende Befehle ausführen:

for mod in xen_netback xen_blkback xenfs xen_pciback xen_wdt tun; do if modprobe $mod; then grep -q -q $mod /etc/modules || echo $mod >> /etc/modules fi done  apk add xen xen-hypervisor  for svc in xenstored xenconsoled xendomains xenqemu; do rc-update add $svc default done  grubcfg=$(cat /boot/grub/grub.cfg) cat > /boot/grub/grub.cfg <<EOF menuentry "Xen Alpine Linux" { multiboot2 /boot/xen.gz placeholder smt=1 module2 /boot/vmlinuz-vanilla placeholder modules=sd-mod,usb-storage,ext4 cryptroot=UUID=$lvm_UUID cryptdm=lvmcrypt root=UUID=$root_UUID nomodeset quiet rootfstype=ext4 module2 /boot/initramfs-vanilla }  $grubcfg EOF 

Wenn ich Xen Alpine Linux aus den Startoptionen auswähle, scheint Xen fehlerfrei zu starten, aber nachdem die Konsole aufgegeben wurde, bekam ich einen schwarzen Bildschirm und die Tastatur reagiert nicht mehr. Dasselbe passiert, wenn ich die leise Kernel-Option von grub.cfg entferne. Es werden keine zusätzlichen Informationen ausgegeben. Wie kann ich dieses Problem beheben oder wird dieses Setup nicht unterstützt?

Ich habe bemerkt, dass, wenn ich multiboot und module anstelle von multiboot2 und module2 benutze, Xen den Fehler "(XEN) ACPI-Fehler (tbxfroot-8217): Ein gültiger RSDP wurde nicht gefunden wurde [20070126]" und ACPI deaktiviert, diesmal jedoch danach Wenn die Konsole aufgegeben wird, werden Sie nach dem Kennwort der LVM-Partition gefragt. Das Problem hierbei ist jedoch, dass die Tastatur nicht reagiert und ich das Kennwort nicht eingeben und den Startvorgang fortsetzen kann.

0

0 Antworten auf die Frage