Created
August 23, 2021 14:08
-
-
Save ulfox/9ac60e8be7725c2c8327b460d427ab5c to your computer and use it in GitHub Desktop.
Simple script for migrating a debian-like OS to Arch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -e | |
| if [[ "${1}" == "bootstrap" ]]; then | |
| # Create an arch bootstrap system | |
| apt install -y vim curl zstd git | |
| cd /mnt | |
| git clone https://github.com/tokland/arch-bootstrap.git | |
| install -m 0755 arch-bootstrap/arch-bootstrap.sh /usr/local/bin/arch-bootstrap | |
| arch-bootstrap bootstrap | |
| mount --rbind /dev /mnt/bootstrap/dev | |
| mount --rbind /sys /mnt/bootstrap/sys | |
| mount --make-rslave /mnt/bootstrap/dev | |
| mount --make-rslave /mnt/bootstrap/sys | |
| mount --rbind /tmp /mnt/bootstrap/tmp | |
| mount -t proc /proc /mnt/bootstrap/proc | |
| cp /etc/resolv.conf /mnt/bootstrap/etc/resolv.conf | |
| cp /etc/fstab /mnt/bootstrap/etc/fstab | |
| chroot /mnt/bootstrap /bin/bash <<EOF | |
| pacman -Syu base arch-install-scripts --noconfirm | |
| EOF | |
| umount -R /mnt/bootstrap/{dev,sys,proc,tmp} | |
| elif [[ "${1}" == "migrate" ]]; then | |
| # Migrate step A | |
| ## Repace current root with bootstrap | |
| mkdir -vp /sysfs | |
| curl -L https://busybox.net/downloads/binaries/1.31.0-i686-uclibc/busybox -o /sysfs/busybox | |
| chmod +x /sysfs/busybox | |
| export PATH=/sysfs | |
| busybox rm -rf /usr /var/* /srv /opt /'lost+found' /sbin /etc /media /bin /cdrom /lib* /tmp | |
| busybox cp -Pr /mnt/bootstrap/{etc,usr,opt,srv,tmp} / | |
| busybox cp -Pr /mnt/bootstrap/run/* /run/ | |
| busybox cp -Pr /mnt/bootstrap/var/{cache,db,empty,games,lib,local,log,opt,spool,tmp} /var/ | |
| busybox ln -sf /run /var/run | |
| busybox ln -sf /run/lock /var/lock | |
| busybox ln -sf /var/spool/mail /var/mail | |
| busybox ln -sf /var/lib/dbus/machine-id /etc/machine-id | |
| busybox ln -sf /usr/bin /bin | |
| busybox ln -sf /usr/bin /sbin | |
| busybox ln -sf /usr/lib /lib | |
| busybox ln -sf /usr/lib /lib64 | |
| export PATH="${PATH}:/bin" | |
| # Migrate step B | |
| ## Create a new arch root with pacstrap and make that the default | |
| mkdir -v /mnt/arch | |
| pacstrap /mnt/arch base linux linux-firmware openssh vim grub | |
| cp /etc/resolv.conf /mnt/arch/etc/resolv.conf | |
| cp /etc/fstab /mnt/arch/etc/fstab | |
| set +e | |
| busybox rm -rf /usr /var /srv /opt /'lost+found' /sbin /etc /media /bin /cdrom /lib* /tmp /var /run/* | |
| set -e | |
| busybox cp -Pr /mnt/arch/{etc,usr,opt,srv,tmp,var} / | |
| busybox ln -sf /usr/bin /bin | |
| busybox ln -sf /usr/bin /sbin | |
| busybox ln -sf /usr/lib /lib | |
| busybox ln -sf /usr/lib /lib64 | |
| rm -f /boot/initrd* /boot/vmlinuz* | |
| cp -P /mnt/arch/boot/* /boot/ | |
| mkinitcpio -P | |
| echo 'ulfox' >/etc/hostname | |
| passwd <<PSWD | |
| ulfox | |
| ulfox | |
| PSWD | |
| grub-mkconfig -o /boot/grub/grub.cfg | |
| systemctl enable --now sshd | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment