diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ae6198b..5ef0725 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: debian:latest +image: debian:stretch build: stage: build @@ -7,12 +7,13 @@ build: - DEBIAN_FRONTEND=noninteractive apt-get -o Acquire::Retires=10 install --no-install-recommends -qq libguestfs-tools busybox linux-image-amd64 gnupg1 openssh-client - ssh-keygen -q -N '' -f ~/.ssh/id_rsa script: - - 'LIBGUESTFS_BACKEND=direct virt-builder --gpg /usr/bin/gpg1 --arch x86_64 debian-9 -o debian.raw --root-password password:root --ssh-inject root --install wget,ca-certificates --firstboot-command "dpkg-reconfigure openssh-server"' + - curl -fOL https://cdimage.debian.org/cdimage/cloud/buster/latest/debian-10-nocloud-amd64.qcow2 + - 'LIBGUESTFS_BACKEND=direct virt-customize -a debian-10-nocloud-amd64.qcow2 --root-password password:root --ssh-inject root --install wget,ca-certificates --firstboot-command "dpkg-reconfigure -f noninteractive openssh-server"' after_script: - mv ~/.ssh/id_rsa id_rsa cache: paths: - - debian.raw + - debian-10-nocloud-amd64.qcow2 - id_rsa policy: push @@ -25,15 +26,38 @@ build: - mkdir ~/.ssh - mv id_rsa ~/.ssh/id_rsa - printf '%s\n\t' 'Host *' 'ServerAliveInterval 15' 'UserKnownHostsFile /dev/null' 'StrictHostKeyChecking no' 'CheckHostIP no' > ~/.ssh/config - - qemu-system-x86_64 -m 256 -daemonize -drive file=debian.raw,if=virtio -net nic -net user,hostfwd=tcp::10022-:22 -display none -vga none - - sleep 60 + - qemu-system-x86_64 -m 256 -daemonize -drive file=debian-10-nocloud-amd64.qcow2,if=virtio -net nic -net user,hostfwd=tcp::10022-:22 -display none -vga none -serial file:/tmp/serial + - 'tail -f /tmp/serial &' + - sleep 120 - scp -P 10022 vps2arch root@127.0.0.1:vps2arch - ssh -p 10022 root@127.0.0.1 "chmod +x vps2arch" dependencies: - build cache: paths: - - debian.raw + - debian-10-nocloud-amd64.qcow2 + - id_rsa + policy: pull + +.tests_uefi: + retry: 1 + stage: test + before_script: + - apt-get update -y + - DEBIAN_FRONTEND=noninteractive apt-get -o Acquire::Retires=10 install --no-install-recommends -qq qemu-system-x86 openssh-client ovmf sshpass + - mkdir ~/.ssh + - mv id_rsa ~/.ssh/id_rsa + - printf '%s\n\t' 'Host *' 'ServerAliveInterval 15' 'UserKnownHostsFile /dev/null' 'StrictHostKeyChecking no' 'CheckHostIP no' > ~/.ssh/config + - qemu-system-x86_64 -m 256 -daemonize -bios /usr/share/OVMF/OVMF_CODE.fd -drive file=debian-10-nocloud-amd64.qcow2,if=virtio -net nic -net user,hostfwd=tcp::10022-:22 -display none -vga none -serial file:/tmp/serial + - 'tail -f /tmp/serial &' + - sleep 120 + - scp -P 10022 vps2arch root@127.0.0.1:vps2arch + - ssh -p 10022 root@127.0.0.1 "chmod +x vps2arch" + dependencies: + - build + cache: + paths: + - debian-10-nocloud-amd64.qcow2 - id_rsa policy: pull @@ -57,3 +81,10 @@ test_syslinux: - 'ssh -p 10022 root@127.0.0.1 "./vps2arch -b syslinux && sync ; reboot -f" || true' - sleep 600 - sshpass -proot ssh -p 10022 root@127.0.0.1 test -f /etc/arch-release + +test_default_uefi: + extends: .tests_uefi + script: + - 'ssh -p 10022 root@127.0.0.1 "./vps2arch && sync ; reboot -f" || true' + - sleep 600 + - sshpass -proot ssh -p 10022 root@127.0.0.1 test -f /etc/arch-release diff --git a/vps2arch b/vps2arch index 9f4a655..952b6a8 100755 --- a/vps2arch +++ b/vps2arch @@ -77,6 +77,7 @@ download_and_extract_bootstrap() { # FIXME support multiple partitions mount --bind / "/root.$cpu_type/mnt" findmnt /boot >/dev/null && mount --bind /boot "/root.$cpu_type/mnt/boot" + findmnt /boot/efi >/dev/null && mount --bind /boot/efi "/root.$cpu_type/mnt/boot/efi" # Workaround for Debian mkdir -p "/root.$cpu_type/run/shm" # Workaround for OpenVZ @@ -97,7 +98,7 @@ configure_chroot() { if ! is_openvz && ! pidof haveged >/dev/null; then # Disable signature check, install and launch haveged and re-enable signature checks. sed -i.bak "s/^[[:space:]]*SigLevel[[:space:]]*=.*$/SigLevel = Never/" "/root.$cpu_type/etc/pacman.conf" - chroot_exec 'pacman --noconfirm -Sy haveged && haveged' + chroot_exec 'pacman --needed --noconfirm -Sy haveged && haveged' mv "/root.$cpu_type/etc/pacman.conf.bak" "/root.$cpu_type/etc/pacman.conf" fi chroot_exec 'pacman-key --init && pacman-key --populate archlinux' @@ -134,6 +135,11 @@ install_packages() { [ "$bootloader" != "none" ] && packages="$packages $bootloader" # XXX Install gptdisk for syslinux. To be removed then FS#45029 will be closed [ "$bootloader" = "syslinux" ] && packages="$packages gptfdisk" + [ -f /sys/firmware/efi/fw_platform_size ] && packages="$packages efibootmgr" + [ "$network" = "netctl" ] && packages="$packages netctl" + while read -r _ mountpoint filesystem _; do + [ "$mountpoint" = "/" -a "$filesystem" = "xfs" ] && packages="$packages xfsprogs" + done < /proc/mounts # Black magic! "/root.$cpu_type/usr/lib"/ld-*.so --library-path "/root.$cpu_type/usr/lib" \ "/root.$cpu_type/usr/bin/chroot" "/root.$cpu_type" /usr/bin/pacstrap -M /mnt $packages @@ -142,7 +148,7 @@ install_packages() { restore_root_pass() { # If the root password is not set, use vps2arch - if egrep -q '^root:.?:' "/root.$cpu_type/root.passwd"; then + if egrep -q '^root:[^$]' "/root.$cpu_type/root.passwd"; then echo "root:vps2arch" | chpasswd else sed -i '/^root:/d' /etc/shadow @@ -157,10 +163,13 @@ cleanup() { } configure_bootloader() { - local root_dev=$(findmnt -no SOURCE /) root_devs= tmp= needs_lvm2=0 + local root_dev=$(findmnt -no SOURCE /) root_devs= tmp= needs_lvm2=0 uefi=0 case $root_dev in /dev/mapper/*) needs_lvm2=1 ;; esac + if [ -f /sys/firmware/efi/fw_platform_size ]; then + uefi=$(cat /sys/firmware/efi/fw_platform_size) + fi if [ $needs_lvm2 -eq 1 ]; then # Some distro doesn't use lvmetad by default @@ -187,9 +196,16 @@ configure_bootloader() { *) root_devs="${root_devs:+$root_devs }$tmp" ;; esac done - for root_dev in $root_devs; do - grub-install --target=i386-pc --recheck --force "$root_dev" - done + case $uefi in + 0) + for root_dev in $root_devs; do + grub-install --target=i386-pc --recheck --force "$root_dev" + done + ;; + 64) + grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB + ;; + esac grub-mkconfig > /boot/grub/grub.cfg elif [ "$bootloader" = "syslinux" ]; then # If you are still using eth* as interface name, disable "strange" ifnames