ungleich-tools/debian-devuan-install-on-disk.sh

119 lines
2.6 KiB
Bash
Raw Normal View History

#!/bin/sh
# Nico Schottelius, 2019-12-09
set -e
set -x
if [ $# -ne 3 ]; then
echo $0 suite keyfile disk
echo suite: beowulf or similar
echo keyfile: file containing the ssh keys
echo disk: the block device
exit 1
fi
suite=$1; shift
keyfile=$1; shift
disk=$1; shift
case $disk in
/dev/sd*)
partition=${disk}1
;;
2021-08-19 13:32:17 +00:00
/dev/mmcblk*|/dev/nvme*|/dev/loop*)
partition=${disk}p1
;;
*)
echo "Unsupported disk - edit this script" >&2
exit 1
;;
esac
chroot_dir=$(mktemp -d)
date=$(date +%F)
################################################################################
# Disk preparation
# Clean the first 2M - getting rid of old things
# in the gap and also the paritition table
dd if=/dev/zero of=${disk} bs=1M count=2
# Partition disk with 1 Linux partition
sudo sfdisk "$disk" <<EOF
label: dos
,,L
EOF
partprobe "${disk}"
# For creation, if an existing filesystem is on the partitions
mkfs.ext4 -F ${partition}
mount ${partition} ${chroot_dir}
# Devuan: debootstrap beowulf /tmp/tmp.teGuJxytz0 http://packages.devuan.org/devuan
debootstrap "${suite}" "${chroot_dir}"
# need non-free for firmware-bnx2
echo "deb http://pkgmaster.devuan.org/merged ${suite} main contrib non-free" > ${chroot_dir}/etc/apt/sources.list
chroot ${chroot_dir} apt update
2021-08-19 13:50:23 +00:00
chroot ${chroot_dir} apt install -y openssh-server rdnssd linux-image-amd64 firmware-bnx2 ifenslave vlan grub-pc
echo "unconfigured-host" > ${chroot_dir}/etc/hostname
echo '* * * * * root ip -o -6 addr show | grep -E -v " lo |one" > /etc/issue' > ${chroot_dir}/etc/cron.d/ipv6addr
mkdir -p ${chroot_dir}/root/.ssh
cat ${keyfile} > ${chroot_dir}/root/.ssh/authorized_keys
# Fix possible permission issue from above
chmod -R og-rwx ${chroot_dir}/root/
################################################################################
# networking
# echo bonding
cat > ${chroot_dir}/etc/network/interfaces << EOF
auto lo
iface lo inet loopback
# I would like to have a generic block like this below
# But as long as interface
auto bond0
iface bond0 inet manual
bond-miimon 500
bond-mode 4
post-up /sbin/ip link set \$IFACE mtu 9000
bond-slaves none
auto eth0
iface eth0 inet manual
bond-master bond0
post-up /sbin/ip link set \$IFACE mtu 9000
auto eth1
iface eth1 inet manual
bond-master bond0
post-up /sbin/ip link set \$IFACE mtu 9000
EOF
for dir in dev sys proc; do
mount --bind /${dir} ${chroot_dir}/${dir}
done
chroot ${chroot_dir} grub-install ${disk}
for dir in dev sys proc; do
umount ${chroot_dir}/${dir}
done
umount ${chroot_dir}
sync
rmdir ${chroot_dir}