From 370896170ada506a3ee72c632500a3055e095d5e Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Tue, 16 Jan 2024 18:17:27 +0100 Subject: [PATCH] simplify mkusb.sh --- README.md | 17 +++++++++-------- mktiny.sh | 34 ---------------------------------- mkusb.sh | 36 +++++++++++++++++++++++++++++------- 3 files changed, 38 insertions(+), 49 deletions(-) delete mode 100644 mktiny.sh diff --git a/README.md b/README.md index a9216d5..835e245 100644 --- a/README.md +++ b/README.md @@ -95,9 +95,9 @@ it is a matter of convenience. In this case omit ``| pv `` in the commands -## install image by means of an USB stick +## install image by means of the USB stick BOOT_TINY -The stick has TinyLinux and on it and some additional scripts +The stick has TinyLinux on it and some additional scripts If you do not have one, you may create it logging to an other box as root @@ -105,13 +105,11 @@ If you do not have one, you may create it logging to an other box as root to verify that /dev/sdb is your stick, use the following command before and after plugging the stick ``` -apu> ls /dev/sdb -``` +apu> cd aputools +apu> bash mkusb.sh -copy the stick image to the stick (32 GB should be enough) +... you are asked to give the device name from a list (typically sdb) ... -``` -mac> dd if=apuinstall.lz4 bs=512k | pv | ssh root@ "lz4 -d | dd of=/dev/sdb bs=512k" ``` ### b) mount with TinyLinux from USB stick @@ -125,7 +123,7 @@ mac> screen /dev/tty.usbserial-130 115200 Do not yet connect LAN, plug USB stick and start the box, wait for prompt 'tc@box:' ``` -apu> cd /media/CENTOS7_APU (or /media/CENTOS_APU) +apu> cd /media/BOOT_TINY (or /media/CENTOS_APU) apu> sh reg ``` @@ -145,6 +143,9 @@ Use the displayed ip address for the following step. ### c) Copy Image to APU SSD + +Note that the images are not part of the git repo. + ``` mac> cd ~/switchdrive/apu/images mac> dd if=apumaster.lz4 bs=512k | pv | ssh root@192.168.1.43 "lz4 -d | dd of=/dev/sda bs=512k" diff --git a/mktiny.sh b/mktiny.sh deleted file mode 100644 index 2459f33..0000000 --- a/mktiny.sh +++ /dev/null @@ -1,34 +0,0 @@ -# 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 " - 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." diff --git a/mkusb.sh b/mkusb.sh index 668dc13..7200e08 100644 --- a/mkusb.sh +++ b/mkusb.sh @@ -1,15 +1,13 @@ # name of the USB stick to be created NAME=BOOT_TINY -echo "enter source for tinylinux files, e.g. zolliker@mpc1704:switchdrive/apu/usbboot" +echo "enter source for tinylinux files, e.g. zolliker@mpc1704:switchdrive/apu/boot_tiny" read SRC scp -r $SRC ./ -cd usbboot - # create (overwrite) syslinux.cfg -cat > files/syslinux.cfg << "EOF" +cat > boot_tiny/syslinux.cfg << "EOF" SERIAL 0 115200 CONSOLE 0 default centos @@ -19,9 +17,9 @@ 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 +sed -i -- "s/USBNAME/$NAME/g" boot_tiny/syslinux.cfg -ls files +ls boot_tiny # list removeable disks DISKS=() @@ -43,7 +41,31 @@ read DEVICE if [[ " ${DISKS[@]} " =~ " $DEVICE " ]]; then echo "create TinyLinux" - sudo bash ../mktiny.sh $DEVICE $NAME + + 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=mbr.bin of=${DEVICE} + parted ${DEVICE} set 1 boot on + + mkdir -p /mnt/apusb + mount ${DEVICE}1 /mnt/apusb + echo "copy files ..." + cp boot_tiny/* /mnt/apusb/ + umount /mnt/apusb + + rm -rf boot_tiny + echo "done." else echo "/dev/$DEVICE is not a removeable disk" fi