#!/bin/bash # based on https://www.tuicool.com/articles/7jaAZj # but works with GPT (3TB disks) and auto-inherits IP from rescue host. set -e DEVS='/dev/sda /dev/sdb' ROOT=${ROOT:-/mnt} ROOT_DEV=${ROOT_DEV:-/dev/md0} HOST=${HOST:-void-linux} REPO=${REPO:-https://repo.voidlinux.eu/current} BASE_PACKAGES=' base-system bash util-linux procps-ng tzdata openssh dhcpcd iputils parted go nginx postfix perl firejail strace grub mdadm iptables vim inetutils-ifconfig chrony dcron metalog' PARTED="parted -a optimal" for d in $DEVS; do wipefs -a $d $PARTED $d mktable gpt $PARTED $d mkpart grub ext2 1 2 $PARTED $d set 1 bios_grub on $PARTED $d mkpart EFI fat32 2 512M $PARTED $d set 2 boot on $PARTED $d mkpart root ext4 512M 80G $PARTED $d set 3 raid on $PARTED $d disk_set pmbr_boot on done sleep 4 # give kernel some time to rescan devices. RD="" for d in $DEVS; do mkfs.fat -F32 ${d}2 RD+="${d}3 " done mdadm --create --verbose --level=1 --raid-devices=2 --metadata=0.9 $ROOT_DEV $RD mkfs.ext4 -q -L root $ROOT_DEV mount $ROOT_DEV $ROOT mkdir $ROOT/dev $ROOT/proc $ROOT/sys mount --rbind /dev $ROOT/dev mount --rbind /proc $ROOT/proc mount --rbind /sys $ROOT/sys curl https://repo.voidlinux.eu/static/xbps-static-latest.x86_64-musl.tar.xz | tar xJ ./usr/bin/xbps-install -r $ROOT -R $REPO -Sy $BASE_PACKAGES cat /etc/resolv.conf > $ROOT/etc/resolv.conf chroot $ROOT /bin/bash <>/etc/default/libc-locales xbps-reconfigure -f glibc-locales echo "# inheriting current IPv4 config" IP=$(ip addr show eth0 | grep -w inet | awk '{print $2}') ROUTE=$(ip route | grep ^default | awk '{print $3}') echo "ip link set dev eth0 up" >> /etc/rc.local echo "ip addr add \$IP brd + dev eth0" >> /etc/rc.local echo "ip route add default via \$ROUTE" >> /etc/rc.local # fix interface? sed -i 's/eth0/enp4s0/' /etc/rc.local echo "# generating mdraid.confg" mdadm --detail --scan >> /etc/mdadm.conf echo mdadmconf=yes > /etc/dracut.conf.d/mdadmconf.conf sed -i 's/\(GRUB_CMDLINE_LINUX_DEFAULT=.*\)"/\1 rd.md=1 rd.auto=1"/' /etc/default/grub echo "# installing GRUB bootloader on $DEVS" for d in $DEVS; do echo "# -> installing grub on \$d" grub-install \$d done echo "# reconfiguring installed kernel..." xbps-query -l|grep linux4|awk '{print "xbps-reconfigure -f " \$2}' | sh ls -l /boot/grub/grub.cfg passwd EOF