You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
3.4 KiB
Bash
126 lines
3.4 KiB
Bash
#!/bin/bash
|
|
# Prepare diskless NFS Debian Buster with tmpfs overlay
|
|
# The idea is just to boot a node and expose SSH
|
|
# NFS export is /home/nfsboot
|
|
# TFTP root is /home/tftp
|
|
|
|
set -e -x
|
|
|
|
SERVER=172.31.1.5
|
|
SUBNET=172.31.1.0/24
|
|
|
|
CFG=`dirname $0`/debian_nfs.conf
|
|
[ -f "$CFG" ] && . $CFG
|
|
|
|
apt-get -y install pxelinux syslinux-common nfs-kernel-server dnsmasq
|
|
|
|
mkdir -p /home/tftp
|
|
cp /usr/lib/PXELINUX/pxelinux.0 /home/tftp
|
|
cp /usr/lib/syslinux/modules/bios/ldlinux.c32 /home/tftp
|
|
|
|
cat >/etc/dnsmasq.conf <<EOF
|
|
port=0
|
|
log-dhcp
|
|
enable-tftp
|
|
tftp-root=/home/tftp
|
|
dhcp-boot=pxelinux.0
|
|
pxe-service=x86PC,"Network Boot",pxelinux
|
|
dhcp-range=${SUBNET%%/*},proxy
|
|
#dhcp-host=70:85:C2:CE:B5:43,net:allow
|
|
#dhcp-ignore=tag:!known
|
|
EOF
|
|
|
|
service dnsmasq restart
|
|
|
|
mkdir -p /home/nfsboot
|
|
((grep -v /home/nfsboot /etc/exports || true); echo "/home/nfsboot $SUBNET(ro,no_root_squash)") > /etc/exports1
|
|
mv /etc/exports1 /etc/exports
|
|
exportfs -r
|
|
|
|
#debootstrap buster /home/nfsboot
|
|
|
|
[ -d /home/overlayroot ] || git clone https://github.com/chesty/overlayroot /home/overlayroot
|
|
mkdir -p /home/nfsboot/etc/initramfs-tools/hooks
|
|
mkdir -p /home/nfsboot/etc/initramfs-tools/scripts/init-bottom
|
|
cp /home/overlayroot/hooks-overlay /home/nfsboot/etc/initramfs-tools/hooks/
|
|
cp /home/overlayroot/init-bottom-overlay /home/nfsboot/etc/initramfs-tools/scripts/init-bottom/
|
|
|
|
mkdir -p /home/nfsboot/root/.ssh
|
|
cp `dirname $0`/authorized_keys /home/nfsboot/root/.ssh
|
|
|
|
# Copy installation script
|
|
cp `dirname $0`/install.sh /home/nfsboot/root/
|
|
cp `dirname $0`/install-legacy.sh /home/nfsboot/root/
|
|
|
|
chroot /home/nfsboot <<EOF
|
|
|
|
echo net-client > /etc/hostname
|
|
|
|
ln -s /proc/mounts /etc/mtab
|
|
|
|
echo 'deb http://http.debian.net/debian buster main contrib non-free' > /etc/apt/sources.list
|
|
echo 'APT::Install-Recommends "false";' > /etc/apt/apt.conf
|
|
echo 'APT::Install-Suggests "false";' >> /etc/apt/apt.conf
|
|
echo en_US.UTF-8 UTF-8 > /etc/locale.gen
|
|
echo ru_RU.UTF-8 UTF-8 >> /etc/locale.gen
|
|
|
|
apt-get update
|
|
apt-get install -y network-manager mc less git wget ca-certificates linux-cpupower iperf3 \
|
|
zip unzip curl smartmontools hdparm fio pciutils usbutils python3 bzip2 dosfstools grub-efi-amd64 \
|
|
xz-utils file debootstrap ethtool nvme-cli openssh-server locales nfs-common sudo \
|
|
linux-image-amd64 firmware-linux firmware-linux-nonfree \
|
|
firmware-amd-graphics firmware-realtek firmware-bnx2 firmware-bnx2x busybox
|
|
|
|
echo '/dev/nfs / nfs tcp,nolock,ro,soft 0 0' > /etc/fstab
|
|
echo 'tmpfs /tmp tmpfs defaults 0 0' >> /etc/fstab
|
|
rm -rf /var/tmp
|
|
ln -s /tmp /var/tmp
|
|
|
|
if ! grep -q "^overlay" /etc/initramfs-tools/modules; then
|
|
echo overlay >> /etc/initramfs-tools/modules
|
|
fi
|
|
|
|
cat >/etc/initramfs-tools/initramfs.conf <<EE
|
|
MODULES=netboot
|
|
BUSYBOX=auto
|
|
KEYMAP=n
|
|
COMPRESS=gzip
|
|
DEVICE=
|
|
NFSROOT=auto
|
|
BOOT=nfs
|
|
EE
|
|
|
|
update-initramfs -u -k all
|
|
|
|
rm -f /etc/ssh/ssh_host*
|
|
|
|
cat >/etc/rc.local <<EE
|
|
#!/bin/bash
|
|
|
|
ssh-keygen -A
|
|
systemctl restart ssh
|
|
exit 0
|
|
EE
|
|
chmod 755 /etc/rc.local
|
|
|
|
EOF
|
|
|
|
cp /home/nfsboot/boot/vmlinuz-* /home/tftp
|
|
cp /home/nfsboot/boot/initrd.img-* /home/tftp
|
|
cd /home/tftp
|
|
VMLINUZ=`ls -t vmlinuz-*|head -n1`
|
|
INITRD=`ls -t initrd.img-*|head -n1`
|
|
mkdir -p pxelinux.cfg
|
|
cat >pxelinux.cfg/default <<EOF
|
|
# boot diskless debian
|
|
default menu.c32
|
|
prompt 0
|
|
menu title pc-client
|
|
ontimeout debian_buster
|
|
timeout 5
|
|
label debian_buster
|
|
menu label $VMLINUZ debian buster
|
|
kernel $VMLINUZ
|
|
append root=/dev/nfs initrd=$INITRD nfsroot=$SERVER:/home/nfsboot ro nomodeset ipv6.disable=1
|
|
EOF
|