add scripts to create an bootable USB stick with TinyLinux

This commit is contained in:
2024-01-16 17:52:04 +01:00
parent ca6c4f25cb
commit c354a0076b
2 changed files with 84 additions and 0 deletions

34
mktiny.sh Normal file
View File

@@ -0,0 +1,34 @@
# create a bootable USB stick for APU
# this part of the script needs root priv
if [ $# -ne 2 ] || [ $EUID != 0 ]
then
echo "Usage: sudo bash mktiny.sh <device name> <usb stick name>"
exit
fi
if [[ $(cat /sys/block/$1/removable) != "1" ]]; then
echo "/dev/$1 is not a removable disk"
exit
fi
DEVICE=/dev/$1
NAME=$2
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=mbr.bin of=${DEVICE}
parted ${DEVICE} set 1 boot on
mkdir -p /mnt/apusb
mount ${DEVICE}1 /mnt/apusb
echo "copy files ..."
cp files/* /mnt/apusb/
umount /mnt/apusb
rm -rf usbboot
echo "done."

50
mkusb.sh Normal file
View File

@@ -0,0 +1,50 @@
# name of the USB stick to be created
NAME=BOOT_TINY
echo "enter source for tinylinux files, e.g. zolliker@mpc1704:switchdrive/apu/usbboot"
read SRC
scp -r $SRC ./
cd usbboot
# create (overwrite) syslinux.cfg
cat > files/syslinux.cfg << "EOF"
SERIAL 0 115200
CONSOLE 0
default centos
ALLOWOPTIONS 0
TIMEOUT 600
label centos
kernel vmlinuz
append initrd=core.gz inst.stage2=hd:LABEL=USBNAME quiet console=ttyS0,115200n8
EOF
sed -i -- "s/USBNAME/$NAME/g" files/syslinux.cfg
ls files
# 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 (${DISKS[@]})?"
read DEVICE
if [[ " ${DISKS[@]} " =~ " $DEVICE " ]]; then
echo "create TinyLinux"
sudo bash ../mktiny.sh $DEVICE $NAME
else
echo "/dev/$DEVICE is not a removeable disk"
fi