Skip to content

Instantly share code, notes, and snippets.

@Jip-Hop
Forked from dankrause/custom-tinycore.sh
Created April 25, 2021 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jip-Hop/6951c7e8c0262033d34774334a1cddcf to your computer and use it in GitHub Desktop.
Save Jip-Hop/6951c7e8c0262033d34774334a1cddcf to your computer and use it in GitHub Desktop.
Create a custom tinycore linux iso. Adjust the config at the beginning of the script, or supply a conf as the first arg. Requires xorriso.
#!/bin/bash
set -e
function cleanup() {
# clean up our temp folder
rm -rf "${TMPDIR}"
}
trap cleanup EXIT
# default config
URL="http://distro.ibiblio.org/tinycorelinux/6.x/x86_64/"
INPUTISO="CorePure64-6.1.iso"
OUTPUTISO="tinycore-custom.iso"
ROOTFS="rootfs"
VOLUMEID="tinycore-custom"
EXTENSIONS=""
BOOTARGS=""
# optionally load user config
[ ! -z $1 ] && . "$1"
# create our working folders
TMPDIR="$(mktemp -d --tmpdir=$(pwd) 'iso.XXXXXX')"
chmod 755 "${TMPDIR}"
mkdir -p dist/{iso,tcz,dep} "${TMPDIR}/cde/optional"
# downloads a file, only if it's not already cached
function cachefile() {
[ -f "dist/${2}/${1}" ] || wget "${URL}/${3}/${1}" -O "dist/${2}/${1}" \
|| [[ ${2} == dep ]] && touch "dist/${2}/${1}"
}
# download the ISO
cachefile "${INPUTISO}" iso release
# get the contents of the iso
xorriso -osirrox on -indev "dist/iso/${INPUTISO}" -extract / "${TMPDIR}"
# install extensions and dependencies
while [ -n "${EXTENSIONS}" ] ; do
DEPS=""
for EXTENSION in ${EXTENSIONS} ; do
cachefile "${EXTENSION}" tcz tcz
cachefile "${EXTENSION}.dep" dep tcz
cp "dist/tcz/${EXTENSION}" "${TMPDIR}/cde/optional"
DEPS=$(echo ${DEPS} | cat - "dist/dep/${EXTENSION}.dep" | sort -u)
done
EXTENSIONS=$DEPS
done
# set extensions to start on boot
pushd ${TMPDIR}/cde/optional
ls | tee ../onboot.lst > ../copy2fs.lst
popd
# alter isolinux config to use our changes
ISOLINUX_CFG="${TMPDIR}/boot/isolinux/isolinux.cfg"
sed -i 's/prompt 1/prompt 0/' "${ISOLINUX_CFG}"
sed -i "s/append/append cde ${BOOTARGS}/" "${ISOLINUX_CFG}"
# build the rootfs and place it on the iso
if [ -d ${ROOTFS} ] ; then
sed -i "/^\tinitrd/ s/$/,\/boot\/overlay.gz/" "${ISOLINUX_CFG}"
chmod -R u+w "${TMPDIR}/boot"
pushd "${ROOTFS}"
find | cpio -o -H newc | gzip -2 > "${TMPDIR}/boot/overlay.gz"
popd
fi
# build a new iso
xorriso -as mkisofs -iso-level 3 -full-iso9660-filenames -volid "${VOLUMEID}" \
-eltorito-boot boot/isolinux/isolinux.bin -boot-load-size 4 \
-eltorito-catalog boot/isolinux/boot.cat -boot-info-table \
-no-emul-boot -output "${OUTPUTISO}" "${TMPDIR}/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment