tinylinux improvements

- move this stuff to the tinylinux subdirectory
- convert name to uppercase with optional underscore for label
- convert to lowercase with optional dash for host name
- remove ssh things from repo(s), now on linse-c:boxes/ssh_for_boxes
This commit is contained in:
zolliker committed 2026-10-26 11:07:20 +01:00
1 parent e4feb3112d
commit f8155b0928
19 files changed
+266 -67

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
current
startup_display.txt
__pycache__
tmp
sticks
+2 -1
View File
@@ -1,6 +1,7 @@
[BOX]
type=bare-apu
MAC=00:0d:b9:5f:ba:48
version=1
[NETWORK]
; please refer to README.md for help
@@ -11,4 +12,4 @@ eth3=192.168.127.254
[ROUTER]
; please refer to README.md for help
3001=192.168.127.254:3001
2000=192.168.2.2:2000
-66
View File
@@ -1,66 +0,0 @@
#!/bin/bash
# create an USB stick with TinyLinux on it
# name of the USB stick to be created
NAME=BOOT_TINY
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# list removeable disks
DISKS=()
while read LINE
do
ARR=($LINE)
if [[ ${ARR[@]:0:2} == "1 disk" ]]; then
DISKS+=(${ARR[@]:2:1})
printf "%-7s %7s " ${ARR[@]:2:2}
echo ${ARR[@]:4}
elif [[ ${ARR[@]:0:2} == "1 part" ]]; then
printf " %7s " ${ARR[@]:3:1}
echo ${ARR[@]:4}
fi
done < <(lsblk -l --output RM,TYPE,NAME,SIZE,LABEL,VENDOR,MODEL)
echo "which device? should be one of: ${DISKS[@]}"
read DEVICE
if [ -z $DEVICE ] ; then
exit
fi
if [[ " ${DISKS[@]} " =~ " $DEVICE " ]]; then
echo "create TinyLinux"
if [ ! -d boot_tiny ] ; then
sudo --user l_samenv git clone --depth 1 https://gitea.psi.ch/linse/boot_tiny.git
fi
if [[ $(cat /sys/block/$DEVICE/removable) != "1" ]]; then
echo "/dev/$DEVICE is not a removable disk"
exit
fi
DEVICE=/dev/$DEVICE
umount ${DEVICE}1
dd if=/dev/zero of=${DEVICE} count=1 conv=notrunc
echo -e "o\nn\np\n1\n\n\nw" | fdisk ${DEVICE}
mkfs.vfat -n $NAME -I ${DEVICE}1
syslinux -i ${DEVICE}1
dd conv=notrunc bs=440 count=1 if=boot_tiny/mbr.bin of=${DEVICE}
parted ${DEVICE} set 1 boot on
mkdir -p /mnt/apusb
mount ${DEVICE}1 /mnt/apusb
echo "copy files ..."
cp -r boot_tiny/* /mnt/apusb/
umount /mnt/apusb
rm -rf boot_tiny
echo "done."
else
echo "/dev/$DEVICE is not a removeable disk"
fi
+27
View File
@@ -0,0 +1,27 @@
#!/bin/sh
# /opt/bootlocal.sh - run as root at the end of boot (called by tc-config).
# Everything needed is already inside core.gz: no network, no tce-load.
# do what tce-load does after it has mounted an extension
ldconfig 2> /dev/null
for f in /usr/local/tce.installed/*; do
[ -x "$f" ] && "$f"
done
# passwords (delete these two lines if only key login is wanted)
echo "tc:tc" | chpasswd
echo "root:root" | chpasswd
# ssh files for user tc, staged in /opt/ssh by build_core.sh
if [ -d /opt/ssh ]; then
rm -rf /home/tc/.ssh
cp -a /opt/ssh /home/tc/.ssh
chown -R tc:staff /home/tc/.ssh
chmod 700 /home/tc/.ssh
chmod -R go-rwx /home/tc/.ssh
fi
/usr/local/etc/init.d/openssh start
# marker so that you can see on the box that this script ran
echo "bootlocal.sh finished $(date)" > /tmp/bootlocal.log
+129
View File
@@ -0,0 +1,129 @@
#!/bin/bash
# Build a custom core.gz for the BOOT_TINY stick:
# - nano, lz4, openssh (and their dependencies) are built in, so no
# network and no tce-load are needed at boot
# - /opt/bootlocal.sh starts sshd and sets up ~/.ssh
# - the ssh/ directory (authorized_keys, id_rsa, ...) is staged in /opt/ssh
# - the stick gets a hostname and its own, fixed ssh host keys
#
# Needs: root, cpio, gzip, unsquashfs (package squashfs-tools), ssh-keygen
#
# Put these next to this script:
# core.gz.orig the original, unmodified core.gz (keep it, never overwrite)
# tcz/*.tcz extensions fetched on the Tiny Core box with
# "tce-load -w nano lz4 openssh", copied from tce/optional
# ssh/ files for ~/.ssh of user tc (authorized_keys, ...)
# bootlocal.sh
# sticks/<name>/hostkeys/ ssh host keys of the stick called <name>. Used if it
# exists, created (and filled with new keys) if it does not.
# Keep it, then a rebuilt stick keeps its identity.
# Result: sticks/<name>/core.gz (copy it into boot_tiny/ and commit it)
set -e
cd "$(dirname "$0")"
ORIG=core.gz.orig
[ "$EUID" -eq 0 ] || { echo "Please run as root"; exit 1; }
for f in "$ORIG" bootlocal.sh; do
[ -f "$f" ] || { echo "missing $f"; exit 1; }
done
ls tcz/*.tcz > /dev/null 2>&1 || { echo "no tcz/*.tcz found"; exit 1; }
for c in cpio gzip unsquashfs ssh-keygen; do
command -v $c > /dev/null || { echo "need $c"; exit 1; }
done
file "$ORIG" | grep -q gzip || { echo "$ORIG is not gzip compressed:"; file "$ORIG"; exit 1; }
if [ -z "$1" ]; then
read -p "stick name [apu-boot]: " stickname
stickname=${stickname:-apu-boot}
else
stickname=$1
fi
label=${stickname//-/_}
label=${label^^}
# the name ends up in a directory name and in a script: allow only safe characters
case "$stickname" in
*[!A-Za-z0-9-]*|.*) echo "invalid hostname '$stickname' (use letters, digits and dash only)"; exit 1 ;;
esac
# ssh host keys: use hostkeys_<name> if present, create missing keys otherwise
STICKDIR=$PWD/sticks/$stickname
KEYDIR=$STICKDIR/hostkeys
SSHDIR=$PWD/tmp/ssh_for_boxes
if [ -d "$KEYDIR" ]; then
echo "using ssh host keys from $KEYDIR"
else
echo "creating $KEYDIR with new ssh host keys"
mkdir -p "$KEYDIR"
fi
for t in dsa rsa ecdsa ed25519; do
if [ ! -f "$KEYDIR/ssh_host_${t}_key" ]; then
echo " generate $t key"
rm -f "$KEYDIR/ssh_host_${t}_key.pub"
ssh-keygen -q -t $t -N '' -f "$KEYDIR/ssh_host_${t}_key"
fi
done
cat << EOF > $STICKDIR/bootsync.sh
#!/bin/sh
# put other system startup commands here, the boot process will wait until they complete.
# Use bootlocal.sh for system startup commands that can run in the background
# and therefore not slow down the boot process.
/usr/bin/sethostname $stickname
/opt/bootlocal.sh &
EOF
WORK=$(mktemp -d)
TMP=$(mktemp -d)
trap 'rm -rf "$WORK" "$TMP"' EXIT
echo "unpack $ORIG"
zcat "$ORIG" | (cd "$WORK" && cpio -idm --quiet)
for t in tcz/*.tcz; do
echo "add $t"
rm -rf "$TMP/x"
unsquashfs -d "$TMP/x" "$t" > /dev/null
cp -a "$TMP/x/." "$WORK/"
done
echo "add ssh files from $SSHDIR for user tc host"
if [ -d "$SSHDIR" ]; then
echo "stage $SSHDIR in /opt/ssh"
mkdir -p "$WORK/opt/ssh"
cp -a "$SSHDIR"/. "$WORK/opt/ssh/"
fi
echo "add ssh host keys from $KEYDIR"
mkdir -p "$WORK/usr/local/etc/ssh"
for k in "$KEYDIR"/ssh_host_*_key; do
install -m 600 -o root -g root "$k" "$WORK/usr/local/etc/ssh/"
install -m 644 -o root -g root "$k.pub" "$WORK/usr/local/etc/ssh/"
done
install -m 755 -o root -g root bootlocal.sh "$WORK/opt/bootlocal.sh"
install -m 755 -o root -g root $STICKDIR/bootsync.sh "$WORK/opt/bootsync.sh"
# commands whose scripts live on the stick: small wrappers in /usr/local/bin
STICKCMDS="clone write_to_ssd"
mkdir -p "$WORK/usr/local/bin"
for c in $STICKCMDS; do
printf '#!/bin/sh\ncd %s && exec bash ./%s "$@"\n' "/media/$label" "$c" > "$WORK/usr/local/bin/$c"
chmod 755 "$WORK/usr/local/bin/$c"
done
OUT=core.gz
echo "pack $STICKDIR/$OUT"
(cd "$WORK" && find . | cpio -o -H newc --quiet) | gzip -9 > "${OUT}.new"
mv "${OUT}.new" $STICKDIR/$OUT
# change ownership of generated files to the owner of the current directory
chown -R --reference=. $STICKDIR
ls -l "$STICKDIR/$OUT"
echo "done."
Binary file not shown.
+98
View File
@@ -0,0 +1,98 @@
#!/bin/bash
# create an USB stick with TinyLinux on it
# name of the USB stick to be created
BOOT_TINY_SRC=l_samenv@linse-c:boxes/boot_tiny
SSH_BOXES_SRC=l_samenv@linse-c:boxes/ssh_for_boxes
[ "$EUID" -eq 0 ] || { echo "Please run as root"; exit 1; }
# list removeable disks
DISKS=()
while read LINE
do
ARR=($LINE)
if [[ ${ARR[@]:0:2} == "1 disk" ]]; then
DISKS+=(${ARR[@]:2:1})
printf "%-7s %7s " ${ARR[@]:2:2}
echo ${ARR[@]:4}
elif [[ ${ARR[@]:0:2} == "1 part" ]]; then
printf " %7s " ${ARR[@]:3:1}
echo ${ARR[@]:4}
fi
done < <(lsblk -l --output RM,TYPE,NAME,SIZE,LABEL,VENDOR,MODEL)
echo "which device? should be one of: ${DISKS[@]}"
read DEVICE
if [ -z $DEVICE ] ; then
exit
fi
if [[ " ${DISKS[@]} " =~ " $DEVICE " ]]; then
if [[ $(cat /sys/block/$DEVICE/removable) != "1" ]]; then
echo "/dev/$DEVICE is not a removable disk"
exit
fi
if [ -z "$1" ]; then
read -p "name for stick name [apu-boot]: " name
name=${name:-apu-boot}
else
name=$1
fi
stickname=${name//_/-}
stickname=${stickname,,}
label=${name//-/_}
label=${label^^}
# allow only letters and digits
case "$stickname" in
*[!A-Za-z0-9-]*|.*) echo "invalid hostname '$stickname' (use letters, digits and dash only)"; exit 1 ;;
esac
echo "create TinyLinux stick $label (host name $stickname)"
rm -rf tmp
sudo --user l_samenv mkdir tmp
sudo --user l_samenv scp -r $BOOT_TINY_SRC tmp/
sudo --user l_samenv scp -r $SSH_BOXES_SRC tmp/
STICKDIR=sticks/$stickname
if [ ! -d $STICKDIR ]; then
mkdir -p $STICKDIR
fi
bash build_core.sh $stickname
if [ ! -f $STICKDIR/core.gz ]; then
echo "no core.gz created -> build_core.sh failed"
exit
fi
sudo --user l_samenv cp $STICKDIR/core.gz tmp/boot_tiny/scripts/
DEVICE=/dev/$DEVICE
umount ${DEVICE}1
dd if=/dev/zero of=${DEVICE} count=1 conv=notrunc
echo -e "o\nn\np\n1\n\n\nw" | fdisk ${DEVICE}
mkfs.vfat -n $label -I ${DEVICE}1
syslinux -i ${DEVICE}1
dd conv=notrunc bs=440 count=1 if=tmp/boot_tiny/mbr.bin of=${DEVICE}
parted ${DEVICE} set 1 boot on
mkdir -p /mnt/apusb
mount ${DEVICE}1 /mnt/apusb
echo "copy files ..."
cp -r tmp/boot_tiny/scripts/* /mnt/apusb/
umount /mnt/apusb
echo "done."
echo "--------------------------------------------------------------------"
echo "stick into a box, reboot and wait 2 minutes, then:"
echo ""
echo "nslookup $stickname"
echo ""
echo "if found ip start with 129.129., you can login as tc@$stickname"
echo "ip start with 10., the box has first to be registered to PacketFence"
else
echo "/dev/$DEVICE is not a removeable disk"
fi
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
9a994075cedcc853c448cc9691c3fe38 lz4.tcz
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
ncurses.tcz
+1
View File
@@ -0,0 +1 @@
ce9cf3b540095da2f62d958d85a15e2e nano.tcz
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
234b09001894df7f888a5905067c9be3 ncurses.tcz
Binary file not shown.
+2
View File
@@ -0,0 +1,2 @@
openssl.tcz
+1
View File
@@ -0,0 +1 @@
ad59211499d2b35c624b85eaec4ce53a openssh.tcz
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
e7bfb084e3fbab7eae0a2a0f2cdef0ff openssl.tcz