move stuff from boxtools/tinylinux here

This commit is contained in:
zolliker committed 2026-10-26 13:18:46 +01:00
1 parent 58da349e76
commit fbe2ea0d6b
24 files changed
+254 -33

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
__pycache__
tmp
sticks
+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
+116
View File
@@ -0,0 +1,116 @@
#!/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
# 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=$STICKDIR/ssh
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 host keys from $KEYDIR"
if [ -d "$SSHDIR" ]; then
echo "stage $SSHDIR in /opt/ssh"
mkdir -p "$WORK/opt/ssh"
cp -a "$SSHDIR"/. "$WORK/opt/ssh/"
fi
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"
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."
-10
View File
@@ -1,10 +0,0 @@
sh tiny
HOST=l_samenv@linse-c
DIR=boxes/apuimages
IMGDAT=$(date +'%Y-%m-%d').lz4
read -p "image name to write to $HOST:$DIR [$IMGDAT]: " IMG
if [ -z "$IMG" ]; then
IMG=$IMGDAT
fi
echo "copy image to $HOST:$DIR/$IMG (takes about 5 min) ..."
dd if=/dev/sda bs=512k | lz4 | ssh $HOST "dd of=$DIR/$IMG bs=512k"
View File
File renamed without changes.
Executable
+86
View File
@@ -0,0 +1,86 @@
#!/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
[ "$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 [apu-boot]: " stickname
stickname=${stickname:-apu-boot}
else
stickname=$1
fi
# 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 $stickname"
if [ ! -d boot_tiny ] ; then
sudo --user l_samenv scp -r l_samenv@linse-c:boxes/boot_tiny ./
fi
STICKDIR=sticks/$stickname
if [ ! -d $STICKDIR ]; then
mkdir -p $STICKDIR
fi
if [ ! -f $STICKDIR/core.gz ]; then
bash build_core.sh $stickname
if [ ! -f $STICKDIR/core.gz ]; then
echo "no core.gz created -> build_core.sh failed"
exit
fi
fi
sudo --user l_samenv cp $STICKDIR/core.gz boot_tiny/core.gz
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 $stickname -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
echo "done."
else
echo "/dev/$DEVICE is not a removeable disk"
fi
-10
View File
@@ -1,10 +0,0 @@
echo -n "new hostname: "
read hostname
sudo hostname $hostname
echo "address of leftmost socket (eth0 for control box, recommended also for newer bare apus):"
ifconfig | grep eth0
echo " "
echo "address of rightmost socket (for legacy bare apu):"
ifconfig | grep eth3
echo " "
echo "register $hostname to packet fence and connect LAN to corresponding socket"
+10
View File
@@ -0,0 +1,10 @@
DESTHOST=l_samenv@linse-c
DESTDIR=boxes/apuimages
IMGDAT=$(date +'%Y-%m-%d').lz4
read -p "image name to write to $DESTHOST:$DESTDIR [$IMGDAT]: " IMG
if [ -z "$IMG" ]; then
IMG=$IMGDAT
fi
[[ $IMG == *.lz4 ]] || IMG+=.lz4
echo "copy image to ${DESTHOST}:$DESTDIR/$IMG ..."
dd if=/dev/sda bs=512k | lz4 | ssh l_samenv@linse-c "dd of=$DESTDIR/$IMG bs=512k"
File renamed without changes.
View File
File renamed without changes.
+3 -2
View File
@@ -1,10 +1,11 @@
sh tiny
BOXIMG=boxes/apuimages
echo ""
echo "images from l_samenv@linse-c:$BOXIMG:"
echo ""
ssh l_samenv@linse-c "cd $BOXIMG; ls *.lz4"
echo ""
echo "ARE YOU SURE: you will override the SSD of the box where this stick is inserted"
read -p "which image? " IMG
echo "write to ssd /dev/sda (takes 3 min)"
echo "write to ssd"
ssh l_samenv@linse-c "dd if=$BOXIMG/$IMG bs=512k" | lz4 -d | sudo dd of=/dev/sda bs=512k
BIN
View File
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
9a994075cedcc853c448cc9691c3fe38 lz4.tcz
BIN
View File
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
ncurses.tcz
+1
View File
@@ -0,0 +1 @@
ce9cf3b540095da2f62d958d85a15e2e nano.tcz
BIN
View File
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
234b09001894df7f888a5905067c9be3 ncurses.tcz
BIN
View File
Binary file not shown.
+2
View File
@@ -0,0 +1,2 @@
openssl.tcz
+1
View File
@@ -0,0 +1 @@
ad59211499d2b35c624b85eaec4ce53a openssh.tcz
BIN
View File
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
e7bfb084e3fbab7eae0a2a0f2cdef0ff openssl.tcz
-11
View File
@@ -1,11 +0,0 @@
tce-load -wi nano
tce-load -wi lz4
tce-load -wi openssh
sudo /usr/local/etc/init.d/openssh start
sudo chpasswd << EOF
tc:tc
root:root
EOF
cp -rf ssh ~/.ssh
sudo chmod go-r ~/.ssh/id_rsa
ifconfig | grep 'inet addr'