Logo

Tiny Core: Duplicate script 

Duplicate Script

Overview

In checking out Thin Clients I have a number of USB flash drives with the latest version of Tiny Core installed on them. The flash drives are of various sizes (eg 1GB/4GB/8GB) and some are set up with small(!) 1GB boot partitions. In setting up the flash drives the process is:

  • Maybe partition the flash drive.
  • Use LiLi to install the latest version of Tiny Core.
  • Rename the 'tce' directory from cde to tce.
  • Edit syslinux.cfg to add kmap=qwerty/uk.
  • Boot the flash drive.
  • Run the App Browser and download and install a variety of utilities such as lspci.
  • Some further configuration/customisation.

Although I don't always do it, it is useful to include the command line parameter tce=UUID="1234-5678". This is because, left to its own devices, Tiny Core will search for the tce directory to use. If you boot the flash drive on a system which already has Tiny Core installed on it, Tiny Core will end up using the directory on sda1 (internal drive) rather than the one on sdb1 (external USB flash drive). By specifying the UUID of the boot device you can avoid this.

The Concept

The idea now is that I only have to go through the full rigmarole once to set up a 'reference' flash drive. Thereafter the process is:

  • Use LiLi to produce a bootable flash drive from the latest iso image.
  • Run a script to align the contents of the flash drive to match the 'reference' flash drive.

The Script

I'm no shell script expert, but this apparently works.

Usage is:

dupe_ref.sh [src drive] [dest drive]

So:

dupe_ref.sh sdb1 sdc1

will copy what's necessary from /mnt/sdb1 to update /mnt/sdc1.

What it does:

  • Checks source and destination are given.
  • Checks the specified drives are mounted.
  • Uses rsync to copy over new and changed files.
  • Runs sed to set the right UUIDs in syslinux.cfg
#!/bin/sh
# Script to update a bog-standard Tiny Core USB pen drive
# to match a configured and running pen drive.
# It also patches syslinux.cfg file with correct UUID

usage() {
  echo "Usage: dupe_ref.sh [src drive] [dest drive]."
  echo "eg: dupe_ref.sh sdb1 sdc1"
  exit
}

mount_check() {
  if ! grep -qs "$1" /etc/mtab ; then
   echo "$1 partition isn't mounted"
   exit
  fi
}

if [ "$1" == "" ] ; then usage; fi
if [ "$2" == "" ] ; then usage; fi

src_m="/mnt/$1"
src_d="/dev/$1"
dest_m="/mnt/$2"
dest_d="/dev/$2"

mount_check $src_m
mount_check $dest_m

while true; do
    read -p "Update $dest_d from $src_d?" yn
    case $yn in
        [Yy]* ) break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
done

mv $dest_m/cde $dest_m/tce

echo "Updating files..."
rsync -avprc --exclude "System Volume*" $src_m/* $dest_m

blkid=$(blkid $dest_d | sed 's/.* UUID="\([^"]*\)".*/\1/')
echo setting blkid to $blkid in $dest_m/boot/syslinux/syslinux.cfg
sed  -Ein 's/UUID="[^"]*/UUID="'$blkid'/' $dest_m/boot/syslinux/syslinux.cfg

 


Any comments? email me. Added April 2020