Implement preos

This commit is contained in:
Darko Poljak 2019-09-20 07:15:37 +02:00
commit 799ec72369
95 changed files with 9997 additions and 4 deletions

32
hacking/preos-sh/init Normal file
View file

@ -0,0 +1,32 @@
#!/bin/sh
for pkg in \
file \
linux-image-amd64 \
lsb-release \
openssh-server curl \
pxelinux syslinux-common grub2 \
gdisk util-linux lvm2 mdadm \
btrfs-tools e2fsprogs jfsutils reiser4progs xfsprogs; do
__package $pkg --state present
done
# initramfs requires /init
__link /init --source /sbin/init --type symbolic
__file /etc/network/interfaces --source - --mode 0644 << eof
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
eof
# Steven found this out - coyping it 1:1
# fix the bloody 'stdin: is not a tty' problem
__line /root/.profile --line 'mesg n' --state absent
__hostname --name preos

31
hacking/preos-sh/preos.sh Normal file
View file

@ -0,0 +1,31 @@
#!/bin/sh
TARGET_DIR="$1"
PXE_BOOT_DIR="$2"
debootstrap --include=openssh-server --arch=amd64 stable $TARGET_DIR
chroot $TARGET_DIR /usr/bin/apt-get update
# Configure the OS
cdist config -i init --remote-exec remote-exec.sh --remote-copy remote-exec.sh $TARGET_DIR
# Cleanup chroot
chroot $TARGET_DIR /usr/bin/apt-get autoclean
chroot $TARGET_DIR /usr/bin/apt-get clean
chroot $TARGET_DIR /usr/bin/apt-get autoremove
# Output pxe files
cp $TARGET_DIR/boot/vmlinuz-* $PXE_BOOT_DIR/kernel
cd $TARGET_DIR
find . -print0 | cpio --null -o --format=newc | gzip -9 > $PXE_BOOT_DIR/initramfs
cat << EOF > $PXE_BOOT_DIR/pxelinux.cfg/default
DEFAULT preos
LABEL preos
KERNEL kernel
INITRD initramfs
EOF
cp $TARGET_DIR/usr/lib/PXELINUX/pxelinux.0 $PXE_BOOT_DIR/pxelinux.0
cp $TARGET_DIR/usr/lib/syslinux/modules/bios/ldlinux.c32 $PXE_BOOT_DIR/ldlinux.c32

View file

@ -0,0 +1,8 @@
#!/bin/sh
# echo $@
# set -x
src=$1; shift
dst=$1; shift
real_dst=$(echo $dst | sed 's,:,,')
cp -L "$src" "$real_dst"

View file

@ -0,0 +1,24 @@
#!/bin/sh
# echo $@
# set -x
chroot="$1"; shift
script=$(mktemp "${chroot}/tmp/chroot-${0##*/}.XXXXXXXXXX")
trap cleanup INT TERM EXIT
cleanup() {
[ $__cdist_debug ] || rm "$script"
}
echo "#!/bin/sh -l" > "$script"
echo "$@" >> "$script"
chmod +x "$script"
relative_script="${script#$chroot}"
# ensure PATH is setup
export PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin
# run in chroot
chroot "$chroot" "$relative_script"