BASH code for re-mastering SUSE Studio ISO images

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

BASH code for re-mastering SUSE Studio ISO images

Lietukas

I would like to share some BASH code, if you need to remaster your ISO. If you need UEFI boot support, make sure to install correct version of mkisofs (for me works mkisofs from mkisofs package from
multimedia:apps repository). Note: xorriso fails to replace mkisofs here, because it write ApplianceID incorrectly. I hope this will help for someone!

# !/bin/bash

APPLIANCE_NAME="MyAppliance"
APPLIANCE_VERSION_MIN=0
OPENSUSE_VERSION=42.1
APPLIANCE_VERSION=${OPENSUSE_VERSION}.${APPLIANCE_VERSION_MIN}
#ISO_ORIGINAL="/home/user/Documents/Original_ISO/${APPLIANCE_NAME}.i686-${APPLIANCE_VERSION}.iso"
ISO_ORIGINAL="/home/user/Documents/Original_ISO/${APPLIANCE_NAME}.x86_64-${APPLIANCE_VERSION}.iso"

# Directory with some additional files
OVERLAY="/home/user/Documents/AppendFilesToISO/"

# Directory, where you want to store re-mastered ISO
ISO_OUTPUT_DIR="/home/user/Documents/NewISO/"

# Name of remastered ISO
APPLIANCE_ISO="${APPLIANCE_NAME}_${APPLIANCE_VERSION}.iso"

# Temporary directory, where you can edit content at some point
TMP_DIR="/tmp/MyNewISOcontent/" 

# Temporary mount point of original ISO
MNT_ISO="$(mktemp -d)"

clean_directories () {
echo " "
if [ -d ${TMP_DIR} ] ; then
  echo "Cleaning..."
  rm -f -r ${TMP_DIR}* ;
  umount ${TMP_DIR} || true ;
  rmdir ${TMP_DIR}
fi;
}

remaster_my_appliance () {
echo " "
echo "Prepare...";
echo " ${TMP_DIR}" ;
clean_directories ;
mkdir ${TMP_DIR} ;
# Comment next line, if you have low amount of RAM, but have enough space in disk
mount -t ramfs -o size=2048m ramfs ${TMP_DIR} ;
cp -f -r ${OVERLAY}* ${TMP_DIR}
echo " "
echo "Remaster ISO..."
echo " ${ISO_ORIGINAL}"
if [ -z "$(echo "${ISO_ORIGINAL}" | grep x86_64 )" ] ; then
  ARCH="i386"   ; BIT="32" ;
else
  ARCH="x86_64" ; BIT="64" ;
fi;
mount "${ISO_ORIGINAL}" ${MNT_ISO}
cp -r ${MNT_ISO}/* ${TMP_DIR}
sync ;
BOOT_ID=$(ls "${TMP_DIR}boot/" | grep 0x) ;
echo BOOT_ID=${BOOT_ID}

# Comment next two lines, if don't want to check or manually edit content before writing new ISO
echo "Now you can check ${TMP_DIR} before creating ISO."
read -n1 -r -p "Press any key to continue..." key

sync ;
if [ -f "${TMP_DIR}boot/${ARCH}/efi" ] ; then
  echo "Booting with UEFI"
  echo "$boot/${ARCH}/efi"
  SORT_LIST=$(mktemp) ;
  echo ${TMP_DIR}boot/${ARCH}/efi 1000001 >> ${SORT_LIST} ;
  echo ${TMP_DIR}glump 1000000  >> ${SORT_LIST} ;
  mkisofs -r -pad -f -J -joliet-long -p "${APPLIANCE_NAME}" -publisher "${APPLIANCE_NAME}" -A ${BOOT_ID}  -sysid Linux -V ""${APPLIANCE_NAME}"${APPLIANCE_VERSION:0:7}" -sort ${SORT_LIST} -no-emul-boot -boot-load-size 4 -boot-info-table -b boot/${ARCH}/loader/isolinux.bin -c boot/${ARCH}/boot.catalog -hide boot/${ARCH}/boot.catalog -hide-joliet boot/${ARCH}/boot.catalog -eltorito-alt-boot -eltorito-platform efi -no-emul-boot -boot-load-size 1 -eltorito-boot boot/${ARCH}/efi -eltorito-alt-boot -eltorito-boot boot/${ARCH}/efi -no-emul-boot -joliet-long -hide glump -hide-joliet glump -o "${ISO_OUTPUT_DIR}${APPLIANCE_ISO}" "${TMP_DIR}" ;
  isohybrid --uefi  "${ISO_OUTPUT_DIR}${APPLIANCE_ISO}" || true ;
else
  echo "Booting without UEFI"
  mkisofs -r -pad -f -J -joliet-long -p "${APPLIANCE_NAME}" -publisher "${APPLIANCE_NAME}" -A ${BOOT_ID}  -sysid Linux -V ""${APPLIANCE_NAME}"${APPLIANCE_VERSION:0:7}" -no-emul-boot -boot-load-size 4 -boot-info-table -b boot/${ARCH}/loader/isolinux.bin -c boot/${ARCH}/boot.catalog -hide boot/${ARCH}/boot.catalog -hide-joliet boot/${ARCH}/boot.catalog -joliet-long -hide glump -hide-joliet glump -o "${ISO_OUTPUT_DIR}${APPLIANCE_ISO}" "${TMP_DIR}" ;
  isohybrid "${ISO_OUTPUT_DIR}${APPLIANCE_ISO}" || true ;
fi;
# If you use UEFI, you should see EFI as PlatformID in dumpet output
dumpet -i "${ISO_OUTPUT_DIR}${APPLIANCE_ISO}" || true ;
isoinfo -d -i "${ISO_OUTPUT_DIR}${APPLIANCE_ISO}"  || true ;
clean_directories ;
umount ${MNT_ISO} || true
}

remaster_my_appliance

read -n1 -r -p "Done. Press any key..." key
exit 0
Reply | Threaded
Open this post in threaded view
|

Re: BASH code for re-mastering SUSE Studio ISO images

Juan Luis
Hi!

Your script its functional?