From b2f4774044dab2e8f76b8bc97a4736653d78c954 Mon Sep 17 00:00:00 2001 From: Megver83 Date: Wed, 20 Feb 2019 01:45:40 +0000 Subject: [PATCH 1/8] Pass --needed when installing pkgs with pacman --- vps2arch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vps2arch b/vps2arch index 717c1c0..92f08e3 100755 --- a/vps2arch +++ b/vps2arch @@ -86,11 +86,11 @@ 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' - chroot_exec 'pacman --noconfirm -Sy awk' + chroot_exec 'pacman --needed --noconfirm -Sy awk' # Generate fstab chroot_exec 'genfstab /mnt >> /etc/fstab' From f8d673dc7a1e6ef28f19af3674c77ba99dc20cd7 Mon Sep 17 00:00:00 2001 From: Timothy Redaelli Date: Mon, 2 Aug 2021 17:05:21 +0200 Subject: [PATCH 2/8] Install xfsprogs when rootfs is xfs Currently when rootfs is xfs and lvm2 is enabled, `mkinitcpio -p linux` returns 1 when fsck.xfs is missing which fails the whole installation. --- vps2arch | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vps2arch b/vps2arch index 5e25067..392a070 100755 --- a/vps2arch +++ b/vps2arch @@ -124,6 +124,9 @@ 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" + 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 From c88d7ce0b5ff615d33987b7e19d49e54f0bccbea Mon Sep 17 00:00:00 2001 From: Timothy Redaelli Date: Wed, 4 Aug 2021 16:20:40 +0200 Subject: [PATCH 3/8] Add support for UEFI (Oracle Cloud) --- vps2arch | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/vps2arch b/vps2arch index 392a070..71635af 100755 --- a/vps2arch +++ b/vps2arch @@ -66,6 +66,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 @@ -124,6 +125,7 @@ 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" while read -r _ mountpoint filesystem _; do [ "$mountpoint" = "/" -a "$filesystem" = "xfs" ] && packages="$packages xfsprogs" done < /proc/mounts @@ -150,10 +152,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 @@ -180,9 +185,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 From 2c894d01a97555070b152a425b1390b4ba9a38d2 Mon Sep 17 00:00:00 2001 From: Timothy Redaelli Date: Wed, 4 Aug 2021 19:18:07 +0200 Subject: [PATCH 4/8] In some cases (like Oracle Cloud) the root account is disabled --- vps2arch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vps2arch b/vps2arch index ef772f4..2dba63d 100755 --- a/vps2arch +++ b/vps2arch @@ -137,7 +137,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 From 01ee93e1f02a4e9f2edcd69396606102679080fe Mon Sep 17 00:00:00 2001 From: Timothy Redaelli Date: Thu, 5 Aug 2021 17:16:23 +0200 Subject: [PATCH 5/8] Install netctl if needed --- vps2arch | 1 + 1 file changed, 1 insertion(+) diff --git a/vps2arch b/vps2arch index 2dba63d..cc8dfcc 100755 --- a/vps2arch +++ b/vps2arch @@ -126,6 +126,7 @@ install_packages() { # 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 From 8b78932af70fae7040f38470e9a7fa17cd191b06 Mon Sep 17 00:00:00 2001 From: Timothy Redaelli Date: Thu, 5 Aug 2021 17:16:54 +0200 Subject: [PATCH 6/8] Revert "Use mirrors.kernel.org as first mirror" This reverts commit 664dcd02c3f6171d3444ff4da629f61a664d20cc. --- vps2arch | 1 - 1 file changed, 1 deletion(-) diff --git a/vps2arch b/vps2arch index cc8dfcc..844f953 100755 --- a/vps2arch +++ b/vps2arch @@ -26,7 +26,6 @@ else fi get_worldwide_mirrors() { - echo "http://mirrors.kernel.org/archlinux" _download 'https://www.archlinux.org/mirrorlist/?country=all&protocol=http&protocol=https&ip_version=4' | awk '/^## /{if ($2 == "Worldwide") { flag=1 } else { flag=0 } } /^#Server/ { if (flag) { sub(/\/\$repo.*/, ""); print $3 } }' } From 78234c8bb61fbdb78883cb52a282318601a88dfc Mon Sep 17 00:00:00 2001 From: Timothy Redaelli Date: Thu, 5 Aug 2021 17:33:14 +0200 Subject: [PATCH 7/8] Use mirror.pkgbuild.com as first mirror and use only https mirrors --- vps2arch | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vps2arch b/vps2arch index 844f953..1f2f224 100755 --- a/vps2arch +++ b/vps2arch @@ -26,7 +26,8 @@ else fi get_worldwide_mirrors() { - _download 'https://www.archlinux.org/mirrorlist/?country=all&protocol=http&protocol=https&ip_version=4' | awk '/^## /{if ($2 == "Worldwide") { flag=1 } else { flag=0 } } /^#Server/ { if (flag) { sub(/\/\$repo.*/, ""); print $3 } }' + echo "https://mirror.pkgbuild.com" + _download 'https://www.archlinux.org/mirrorlist/?country=all&protocol=https&ip_version=4' | awk '/^## /{if ($2 == "Worldwide") { flag=1 } else { flag=0 } } /^#Server/ { if (flag) { sub(/\/\$repo.*/, ""); print $3 } }' } cpu_type=$(uname -m) From 43a1d7d58ddf6cd424a7aa919807aa91eb247e00 Mon Sep 17 00:00:00 2001 From: Timothy Redaelli Date: Thu, 5 Aug 2021 17:17:51 +0200 Subject: [PATCH 8/8] Fix CI and test UEFI too --- .gitlab-ci.yml | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) 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