From 2cd33428a5e676d52b6d86174d7f630850f80452 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Wed, 19 Feb 2025 18:22:26 +0000 Subject: [PATCH 01/23] Halt if multiple GLIM partitions are found --- glim.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/glim.sh b/glim.sh index 65f5e5c..81e264c 100755 --- a/glim.sh +++ b/glim.sh @@ -30,7 +30,7 @@ if [[ ! -f ${GRUB2_CONF}/grub.cfg ]]; then fi # -# Find GLIM device (use the first if multiple found, you've asked for trouble!) +# Find GLIM device # # Sanity check : blkid command @@ -38,12 +38,15 @@ if ! which blkid &>/dev/null; then echo "ERROR: blkid command not found." exit 1 fi -USBDEV1=`blkid -L GLIM | head -n 1` +USBDEV1=`blkid -L GLIM` # Sanity check : we found one partition to use with matching label if [[ -z "$USBDEV1" ]]; then echo "ERROR: no partition found with label 'GLIM', please create one." exit 1 +elif [[ "$(echo "$USBDEV1" | wc -l)" -gt 1 ]]; then + echo "ERROR: multiple partitions found with label 'GLIM', please disconnect/rename the unwanted ones." + exit 1 fi echo "Found partition with label 'GLIM' : ${USBDEV1}" From 5bae09138e803555a0fedc411eb30ef6d3f585da Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Wed, 19 Feb 2025 18:23:25 +0000 Subject: [PATCH 02/23] Actually check GLIM is the first partition. Warn rather than error if there are more partitions. --- glim.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/glim.sh b/glim.sh index 81e264c..26c3b3a 100755 --- a/glim.sh +++ b/glim.sh @@ -50,16 +50,19 @@ elif [[ "$(echo "$USBDEV1" | wc -l)" -gt 1 ]]; then fi echo "Found partition with label 'GLIM' : ${USBDEV1}" -# Sanity check : our partition is the first and only one on the block device +# Sanity check : our partition is the first one on the block device +if [[ ! "${USBDEV1}" == *[a-z]1 ]]; then + echo "ERROR: $USBDEV1 is not the first partition on the block device." + exit 1 +fi USBDEV=${USBDEV1%1} if [[ ! -b "$USBDEV" ]]; then echo "ERROR: ${USBDEV} block device not found." exit 1 fi echo "Found block device where to install GRUB2 : ${USBDEV}" -if [[ `ls -1 ${USBDEV}* | wc -l` -ne 2 ]]; then - echo "ERROR: ${USBDEV1} isn't the only partition on ${USBDEV}" - exit 1 +if [[ `ls -1 ${USBDEV}* | wc -l` -gt 2 ]]; then + echo "WARNING: There is more than one partition on ${USBDEV}" fi # Sanity check : our partition is mounted From f59e3fa2babd59074852fb9cd2732e76af3376c8 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Wed, 19 Feb 2025 18:45:55 +0000 Subject: [PATCH 03/23] Fix script to handle spaces in $USBMNT --- glim.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/glim.sh b/glim.sh index 26c3b3a..343abac 100755 --- a/glim.sh +++ b/glim.sh @@ -70,7 +70,7 @@ if ! grep -q -w ${USBDEV1} /proc/mounts; then echo "ERROR: ${USBDEV1} isn't mounted" exit 1 fi -USBMNT=`grep -w ${USBDEV1} /proc/mounts | cut -d ' ' -f 2` +USBMNT="$(grep -w ${USBDEV1} /proc/mounts | cut -d ' ' -f 2)" if [[ -z "$USBMNT" ]]; then echo "ERROR: Couldn't find mount point for ${USBDEV1}" exit 1 @@ -130,17 +130,17 @@ fi # Install GRUB2 if [[ $BIOS == true ]]; then GRUB_TARGET="--target=i386-pc" - echo "Running ${GRUB2_INSTALL} ${GRUB_TARGET} --boot-directory=${USBMNT}/boot ${USBDEV} (with sudo) ..." - sudo ${GRUB2_INSTALL} ${GRUB_TARGET} --boot-directory=${USBMNT}/boot ${USBDEV} + echo "Running ${GRUB2_INSTALL} ${GRUB_TARGET} --boot-directory '${USBMNT}/boot' ${USBDEV} (with sudo) ..." + sudo ${GRUB2_INSTALL} ${GRUB_TARGET} --boot-directory "${USBMNT}/boot" ${USBDEV} if [[ $? -ne 0 ]]; then echo "ERROR: ${GRUB2_INSTALL} returned with an error exit status." exit 1 fi fi if [[ $EFI == true ]]; then - GRUB_TARGET="--target=x86_64-efi --efi-directory=${USBMNT} --removable" - echo "Running ${GRUB2_INSTALL} ${GRUB_TARGET} --boot-directory=${USBMNT}/boot ${USBDEV} (with sudo) ..." - sudo ${GRUB2_INSTALL} ${GRUB_TARGET} --boot-directory=${USBMNT}/boot ${USBDEV} + GRUB_TARGET="--target=x86_64-efi --removable" + echo "Running ${GRUB2_INSTALL} ${GRUB_TARGET} --efi-directory '${USBMNT}' --boot-directory '${USBMNT}/boot' ${USBDEV} (with sudo) ..." + sudo ${GRUB2_INSTALL} ${GRUB_TARGET} --efi-directory "${USBMNT}" --boot-directory "${USBMNT}/boot" ${USBDEV} if [[ $? -ne 0 ]]; then echo "ERROR: ${GRUB2_INSTALL} returned with an error exit status." exit 1 @@ -155,16 +155,16 @@ else fi # Copy GRUB2 configuration -echo "Running rsync -rt --delete --exclude=i386-pc --exclude=x86_64-efi --exclude=fonts ${GRUB2_CONF}/ ${USBMNT}/boot/${GRUB2_DIR} ..." -${CMD_PREFIX} rsync -rt --delete --exclude=i386-pc --exclude=x86_64-efi --exclude=fonts ${GRUB2_CONF}/ ${USBMNT}/boot/${GRUB2_DIR} +echo "Running rsync -rt --delete --exclude=i386-pc --exclude=x86_64-efi --exclude=fonts -- ${GRUB2_CONF}/ '${USBMNT}/boot/${GRUB2_DIR}' ..." +${CMD_PREFIX} rsync -rt --delete --exclude=i386-pc --exclude=x86_64-efi --exclude=fonts -- ${GRUB2_CONF}/ "${USBMNT}/boot/${GRUB2_DIR}" if [[ $? -ne 0 ]]; then echo "ERROR: the rsync copy returned with an error exit status." exit 1 fi # Be nice and pre-create the directory, and mention it -[[ -d ${USBMNT}/boot/iso ]] || ${CMD_PREFIX} mkdir ${USBMNT}/boot/iso -echo "GLIM installed! Time to populate the boot/iso/ sub-directories." +[[ -d "${USBMNT}/boot/iso" ]] || ${CMD_PREFIX} mkdir "${USBMNT}/boot/iso" +echo "GLIM installed! Time to populate the '${USBMNT}/boot/iso' sub-directories." # Now also pre-create all supported sub-directories since empty are ignored args=( @@ -173,6 +173,6 @@ args=( ) for DIR in $(sed "${args[@]}" "$(dirname "$0")"/README.md); do - [[ -d ${USBMNT}/boot/iso/${DIR} ]] || ${CMD_PREFIX} mkdir ${USBMNT}/boot/iso/${DIR} + [[ -d "${USBMNT}/boot/iso/${DIR}" ]] || ${CMD_PREFIX} mkdir "${USBMNT}/boot/iso/${DIR}" done From a302c78505632761f14dc6ff476370f9206efa58 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:17:38 +0000 Subject: [PATCH 04/23] Make harder to accidentally accept 'Ready to install GLIM' by changing default from Y to N, and putting a blank line before it. Allow all Y/N answers to be case insensitive. --- glim.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/glim.sh b/glim.sh index 343abac..d20bf84 100755 --- a/glim.sh +++ b/glim.sh @@ -94,9 +94,9 @@ fi if [[ $BIOS == true ]]; then # Set the target read -n 1 -s -p "Install for EFI in addition to standard BIOS? (Y/n) " EFI - if [[ "$EFI" == "n" ]]; then - EFI=false - echo "n" + if [[ "$EFI" == "n" || "$EFI" == "N" ]]; then + EFI=false + echo "n" else EFI=true echo "y" @@ -119,12 +119,13 @@ fi # # Sanity check : human will read the info and confirm -read -n 1 -s -p "Ready to install GLIM. Continue? (Y/n) " PROCEED -if [[ "$PROCEED" == "n" ]]; then +echo "" +read -n 1 -s -p "Ready to install GLIM. Continue? (y/N) " PROCEED +if [[ "$PROCEED" == "y" || "$PROCEED" == "Y" ]]; then + echo "y" +else echo "n" exit 2 -else - echo "y" fi # Install GRUB2 From d6db6f64222fb3721add058e489fc0c2c8a19a34 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:20:12 +0000 Subject: [PATCH 05/23] Warn that Grub needs a BIOS Boot Partition if GPT is used. Allow installing EFI without BIOS in case they don't have a BIOS Boot Partition. --- glim.sh | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/glim.sh b/glim.sh index d20bf84..1b50e9c 100755 --- a/glim.sh +++ b/glim.sh @@ -87,19 +87,42 @@ else EFI=true fi +# Check disk's partition table type +echo "Running fdisk -l ${USBDEV} (with sudo) to check if using GPT or MBR..." +PartType="$(sudo fdisk -l ${USBDEV} | grep -iPo "Disklabel type:\s\K.*")" +if [[ $? -ne 0 ]]; then + PartType="dos" # Error, so assume the best case so don't give spurious warnings +elif [[ "$PartType" == "gpt" ]]; then + echo "The ${USBDEV} block device uses GPT, which means you can only install for EFI (not BIOS) unless it has a 1MB BIOS Boot partition for Grub." +else + echo "The ${USBDEV} block device uses GPT, which means Grub can install for both EFI & BIOS." +fi + # # EFI or regular? # if [[ $BIOS == true ]]; then # Set the target - read -n 1 -s -p "Install for EFI in addition to standard BIOS? (Y/n) " EFI + read -n 1 -s -p "Install for EFI? (Y/n) " EFI if [[ "$EFI" == "n" || "$EFI" == "N" ]]; then EFI=false echo "n" else EFI=true echo "y" + + if [[ "$PartType" == "gpt" ]]; then + BiosBootPartWarning="(Grub needs a BIOS Boot Partition) " + fi + read -n 1 -s -p "Also install for standard BIOS? $BiosBootPartWarning(y/N) " BIOS + if [[ "$BIOS" == "y" || "$BIOS" == "Y" ]]; then + BIOS=true + echo "y" + else + BIOS=false + echo "n" + fi fi fi From 5cf7b158598b7bd43083ae568bb313e1f3728ffb Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:21:57 +0000 Subject: [PATCH 06/23] Print 'Finished' so users knows the script completed successfully (rather than silently failing). Ensure sensible behaviour if fdisk has unexpected output. --- glim.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/glim.sh b/glim.sh index 1b50e9c..549cd9c 100755 --- a/glim.sh +++ b/glim.sh @@ -95,6 +95,7 @@ if [[ $? -ne 0 ]]; then elif [[ "$PartType" == "gpt" ]]; then echo "The ${USBDEV} block device uses GPT, which means you can only install for EFI (not BIOS) unless it has a 1MB BIOS Boot partition for Grub." else + PartType="dos" # Ensure script behaves sensibly if fdisk doesn't output "gpt" or "dos" echo "The ${USBDEV} block device uses GPT, which means Grub can install for both EFI & BIOS." fi @@ -200,3 +201,4 @@ for DIR in $(sed "${args[@]}" "$(dirname "$0")"/README.md); do [[ -d "${USBMNT}/boot/iso/${DIR}" ]] || ${CMD_PREFIX} mkdir "${USBMNT}/boot/iso/${DIR}" done +echo "Finished!" From e21f1782dcea2191bf9a9d00d64c5f0629e3a3e6 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:24:21 +0000 Subject: [PATCH 07/23] Allow ISOs to be stored on a separate partition (e.g. ext4) to support >4GB ISOs --- glim.sh | 56 ++++++++++++++++++++++++++++++++++++++++++-------- grub2/grub.cfg | 22 +++++++++++++++++--- 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/glim.sh b/glim.sh index 549cd9c..2e458ca 100755 --- a/glim.sh +++ b/glim.sh @@ -61,11 +61,27 @@ if [[ ! -b "$USBDEV" ]]; then exit 1 fi echo "Found block device where to install GRUB2 : ${USBDEV}" -if [[ `ls -1 ${USBDEV}* | wc -l` -gt 2 ]]; then - echo "WARNING: There is more than one partition on ${USBDEV}" +if [[ `ls -1 ${USBDEV}* | wc -l` -gt 3 ]]; then + echo "WARNING: There are more than two partitions on ${USBDEV}" fi -# Sanity check : our partition is mounted +# Look for second partition +USBDEV2=`blkid -L GLIMISO` +if [[ -z "$USBDEV2" ]]; then + echo "Did NOT find a second partition with label 'GLIMISO', so assuming ISO files will be stored on the main 'GLIM' partition." +elif [[ "$(echo "$USBDEV2" | wc -l)" -gt 1 ]]; then + echo "ERROR: multiple partitions found with label 'GLIMISO', please disconnect/rename the unwanted ones." + exit 1 +else + if [[ "$USBDEV2" != "${USBDEV}2" ]]; then + USBDEV2="" + echo "WARNING: Ignored 'GLIMISO' partition ${USBDEV2} because it is not the second partition on the block device." + else + echo "Found partition with label 'GLIMISO' : ${USBDEV2}" + fi +fi + +# Sanity check : our GLIM partition is mounted if ! grep -q -w ${USBDEV1} /proc/mounts; then echo "ERROR: ${USBDEV1} isn't mounted" exit 1 @@ -75,9 +91,26 @@ if [[ -z "$USBMNT" ]]; then echo "ERROR: Couldn't find mount point for ${USBDEV1}" exit 1 fi -echo "Found mount point for filesystem : ${USBMNT}" +echo "Found 'GLIM' mount point for filesystem : ${USBMNT}" + +# Sanity check : our GLIMISO partition is mounted (if exists) +if [[ -z "$USBDEV2" ]]; then + # (no second partition for ISOs) + USBMNTISO="${USBMNT}" + #USBMNTISO="${USBMNT}/boot" # have ISOs where GLIM used to put them +else + if ! grep -q -w ${USBDEV2} /proc/mounts; then + echo "ERROR: ${USBDEV2} isn't mounted" + exit 1 + fi + USBMNTISO="$(grep -w ${USBDEV2} /proc/mounts | cut -d ' ' -f 2)" + if [[ -z "$USBMNTISO" ]]; then + echo "ERROR: Couldn't find mount point for ${USBDEV2}" + exit 1 + fi + echo "Found 'GLIMISO' mount point for filesystem : ${USBMNTISO}" +fi -BIOS=true # Check BIOS support if [[ -d /usr/lib/grub/i386-pc ]]; then BIOS=true @@ -93,7 +126,7 @@ PartType="$(sudo fdisk -l ${USBDEV} | grep -iPo "Disklabel type:\s\K.*")" if [[ $? -ne 0 ]]; then PartType="dos" # Error, so assume the best case so don't give spurious warnings elif [[ "$PartType" == "gpt" ]]; then - echo "The ${USBDEV} block device uses GPT, which means you can only install for EFI (not BIOS) unless it has a 1MB BIOS Boot partition for Grub." + echo "The ${USBDEV} block device uses GPT, which means you can only install for EFI (not BIOS) unless it has a 1MB BIOS Boot partition for Grub. GLIM needs this after the GLIMISO partition (if there is one)." else PartType="dos" # Ensure script behaves sensibly if fdisk doesn't output "gpt" or "dos" echo "The ${USBDEV} block device uses GPT, which means Grub can install for both EFI & BIOS." @@ -178,6 +211,11 @@ if [[ -w "${USBMNT}" ]]; then else CMD_PREFIX="sudo" fi +if [[ -w "${USBMNTISO}" ]]; then + ISOCMD_PREFIX="" +else + ISOCMD_PREFIX="sudo" +fi # Copy GRUB2 configuration echo "Running rsync -rt --delete --exclude=i386-pc --exclude=x86_64-efi --exclude=fonts -- ${GRUB2_CONF}/ '${USBMNT}/boot/${GRUB2_DIR}' ..." @@ -188,8 +226,8 @@ if [[ $? -ne 0 ]]; then fi # Be nice and pre-create the directory, and mention it -[[ -d "${USBMNT}/boot/iso" ]] || ${CMD_PREFIX} mkdir "${USBMNT}/boot/iso" -echo "GLIM installed! Time to populate the '${USBMNT}/boot/iso' sub-directories." +[[ -d "${USBMNTISO}/iso" ]] || ${ISOCMD_PREFIX} mkdir "${USBMNTISO}/iso" +echo "GLIM installed! Time to populate the '${USBMNTISO}/iso' sub-directories." # Now also pre-create all supported sub-directories since empty are ignored args=( @@ -198,7 +236,7 @@ args=( ) for DIR in $(sed "${args[@]}" "$(dirname "$0")"/README.md); do - [[ -d "${USBMNT}/boot/iso/${DIR}" ]] || ${CMD_PREFIX} mkdir "${USBMNT}/boot/iso/${DIR}" + [[ -d "${USBMNTISO}/iso/${DIR}" ]] || ${ISOCMD_PREFIX} mkdir "${USBMNTISO}/iso/${DIR}" done echo "Finished!" diff --git a/grub2/grub.cfg b/grub2/grub.cfg index a434e20..b8ecfe4 100644 --- a/grub2/grub.cfg +++ b/grub2/grub.cfg @@ -5,6 +5,7 @@ # WHERE IT MATTERS. In particular `for .. in "$@"` loops should be wrapped in # `if [ $# -gt 0 ] .. fi` +# Enable reg-ex insmod regexp # Required for GUI and to prevent "No video mode set" error @@ -17,17 +18,32 @@ set gfxpayload=keep # Enable GUI terminal_output gfxterm +# Set how menu looks loadfont unicode - insmod png set theme=${prefix}/themes/invader/theme.txt -set isopath=/boot/iso +# Find UUID of GRUB's boot partition probe --set rootuuid --fs-uuid $root + +# Detect which partition the ISOs are stored on +set isopath=/iso +insmod part_msdos +insmod part_gpt +insmod ext2 +insmod ntfs +if [ -e (hd0,gpt2)${isopath} ]; then + set root="(hd0,gpt2)" +elif [ -e (hd0,msdos2)${isopath} ]; then + set root="(hd0,msdos2)" +#else +# set isopath=/boot/iso +fi + # Required to have these available in other configfile files -export isopath export rootuuid export theme +export isopath function use { echo "Using $1 ..." From c87898989670dfcc7b587a340f7edd049afe6e4d Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:25:03 +0000 Subject: [PATCH 08/23] Don't print errors if user runs GLIM on an existing GLIM installation --- glim.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glim.sh b/glim.sh index 2e458ca..3981e56 100755 --- a/glim.sh +++ b/glim.sh @@ -226,7 +226,7 @@ if [[ $? -ne 0 ]]; then fi # Be nice and pre-create the directory, and mention it -[[ -d "${USBMNTISO}/iso" ]] || ${ISOCMD_PREFIX} mkdir "${USBMNTISO}/iso" +[[ -d "${USBMNTISO}/iso" ]] || ${ISOCMD_PREFIX} mkdir -p "${USBMNTISO}/iso" echo "GLIM installed! Time to populate the '${USBMNTISO}/iso' sub-directories." # Now also pre-create all supported sub-directories since empty are ignored @@ -236,7 +236,7 @@ args=( ) for DIR in $(sed "${args[@]}" "$(dirname "$0")"/README.md); do - [[ -d "${USBMNTISO}/iso/${DIR}" ]] || ${ISOCMD_PREFIX} mkdir "${USBMNTISO}/iso/${DIR}" + [[ -d "${USBMNTISO}/iso/${DIR}" ]] || ${ISOCMD_PREFIX} mkdir -p "${USBMNTISO}/iso/${DIR}" done echo "Finished!" From e31577a8ff502faf16d120605d6f44cee3f2b093 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:26:24 +0000 Subject: [PATCH 09/23] Updated README for optional second partition. Explain that GPT needs extra BIOS Boot partition if installing for BIOS. --- README.md | 80 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0ae6838..963da6f 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ https://github.com/thias/glim | http://glee.thias.es/GLIM Overview -------- -GLIM is a set of grub configuration files to turn a simple VFAT formatted USB -memory stick with many GNU/Linux distribution ISO images into a neat device -from which many different Live environments can be used. +GLIM is a set of grub configuration files to turn a simple VFAT or FAT32 +formatted USB memory stick containing many GNU/Linux distribution ISO images +into a neat device from which many different Live environments can be used. Advantages over extracting files or using special Live USB creation tools : @@ -22,12 +22,12 @@ Disadvantages : * There is no persistence overlay for distributions which normally support it * Setting up isn't as easy as a simple cat from the ISO image to a block device -My experience has been that the safest filesystem to use is FAT32 -(surprisingly!), though it will mean that ISO images greater than 4GB won't be -supported. Other filesystems supported by GRUB2 also work, such as ext3/ext4, -NTFS and exFAT, but the boot of the distributions must also support it, which -isn't the case for many with NTFS (Ubuntu does, Fedora doesn't) and exFAT -(Ubuntu doesn't, Fedora does). So FAT32 stays the safe bet. +As modern Linux ISOs often exceed the 4GB file size limit of FAT32, GLIM now +supports a second partition using other filesystems supported by GRUB2, such as +ext3/ext4, NTFS or exFAT - but the distribution must also support booting from +it, which isn't the case for many with NTFS (Ubuntu does, Fedora doesn't) and +exFAT (Ubuntu doesn't, Fedora does). Ext4 is a safe bet for the second +partition. Screenshots @@ -37,18 +37,64 @@ Screenshots ![Ubuntu Submenu](https://github.com/thias/glim/raw/master/screenshots/GLIM-3.0-shot2.png) +Recent changes +-------------- + +* GLIM now easily supports ISO files >4GB through the use of a second partition, +although you can still use a single partition if you want. + +* The ISO folder has been moved from `boot/iso/` to just `iso/`, so that it's +easier to find, and also is in the same location whether you use one or two +partitions. + + +Requirements +------------ + +You need a USB memory stick (or external hard drive!) partitioned & formatted +one of the following ways: + +1. A single partition formatted as FAT32 with the filesystem label `GLIM`. +It doesn't matter if it uses MBR or GPT. + +or + +2. Two partitions. The first partition must be formatted as FAT32 with the +filesystem label `GLIM`. The second partition should be formatted as Ext4 with +the filesystem label `GLIMISO`. It's best if the USB stick uses MBR, but if it +uses GPT (as GNOME's Disks utility does) then GRUB only supports installing for +EFI (not BIOS) - unless you add a third BIOS Boot partition. GLIM needs the +BIOS Boot partition to come after the other two partitions. + +See the link below for details on how to create a BIOS Boot partition: + +https://wiki.archlinux.org/title/GRUB#GUID_Partition_Table_(GPT)_specific_instructions + +But basically create an unformatted 1MB partition at the end of the disk, then +change it's partition type to "BIOS Boot" (which has the +GUID `21686148-6449-6E6F-744E-656564454649`). You can do this with GNOME's +Disks utility, without resorting to the terminal! + + Installation ------------ -Once you have your USB memory with a single partition formatted as FAT32 with -the filesystem label 'GLIM', mount it, clone this git repository and just run -(as a normal user) : +Mount the GLIM partition (and the GLIMISO partition if present) on your USB +memory stick (or external hard drive). + +Then clone this git repository: + + git clone git@github.com:thias/glim.git + +And just run the script (as a normal user) : ./glim.sh -Once finished, you may change the filesystem label to anything you like. +Once finished, you may change the filesystem label to anything you like. +The script will have created an `iso` folder, inside of which you will see an +empty folder for each supported Linux distro. -The supported `boot/iso/` sub-directories (in alphabetical order) are : +The supported `iso` sub-directories (in alphabetical order) are : [//]: # (distro-list-start) @@ -97,13 +143,13 @@ The supported `boot/iso/` sub-directories (in alphabetical order) are : [//]: # (distro-list-end) Any unpopulated directory will have the matching boot menu entry automatically -disabled, so to skip any distribution, just don't copy any files into it. +hidden, so to skip any distribution, just don't copy any files into it. Download the right ISO image(s) to the matching directory. If you require boot parameter tweaks, edit the appropriate `boot/grub2/inc-*.cfg` file. Items order in the menu ------------- +----------------------- Menu items for a distro are ordered by modification time of the iso files starting from the most recent ones. If some iso files have the same mtime, their @@ -221,6 +267,8 @@ create a GitHub pull request which includes : --- Copyleft 2012-2023 Matthias Saou http://matthias.saou.eu/ +Copyleft 2025 Chris Handley https://github.com/cshandley-uk + All configuration files included are public domain. Do what you want with them. The invader logo was made by me, so unless the exact shape is covered by copyright somewhere, do what you want with it. From 79975b6a9b42f23f5d6814807b25ce87bb01429a Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:36:07 +0000 Subject: [PATCH 10/23] Fix indentation --- glim.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glim.sh b/glim.sh index 3981e56..031b1bd 100755 --- a/glim.sh +++ b/glim.sh @@ -147,7 +147,7 @@ if [[ $BIOS == true ]]; then echo "y" if [[ "$PartType" == "gpt" ]]; then - BiosBootPartWarning="(Grub needs a BIOS Boot Partition) " + BiosBootPartWarning="(Grub needs a BIOS Boot Partition) " fi read -n 1 -s -p "Also install for standard BIOS? $BiosBootPartWarning(y/N) " BIOS if [[ "$BIOS" == "y" || "$BIOS" == "Y" ]]; then From 4aad6d9b8abb8f2b75200d3962f1426a29f5f7e1 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Thu, 20 Feb 2025 08:28:52 +0000 Subject: [PATCH 11/23] Small improvement to README --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 963da6f..9ef7120 100644 --- a/README.md +++ b/README.md @@ -59,12 +59,13 @@ It doesn't matter if it uses MBR or GPT. or -2. Two partitions. The first partition must be formatted as FAT32 with the -filesystem label `GLIM`. The second partition should be formatted as Ext4 with -the filesystem label `GLIMISO`. It's best if the USB stick uses MBR, but if it -uses GPT (as GNOME's Disks utility does) then GRUB only supports installing for -EFI (not BIOS) - unless you add a third BIOS Boot partition. GLIM needs the -BIOS Boot partition to come after the other two partitions. +2. Two partitions. The small first partition must be formatted as FAT32 with +the filesystem label `GLIM`, I suggest 100MB in size. The second partition +should be formatted as Ext4 with the filesystem label `GLIMISO`. It's best if +the USB stick uses MBR, but if it uses GPT (as GNOME's Disks utility does) then +GRUB only supports installing for EFI (not BIOS) - unless you add a third BIOS +Boot partition. GLIM needs the BIOS Boot partition to come after the other two +partitions. See the link below for details on how to create a BIOS Boot partition: From ba2522ed20776006ab56e9dcd38bf5b19694bdb5 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Thu, 20 Feb 2025 21:08:15 +0000 Subject: [PATCH 12/23] Handle cases where partition table entries are not in disk order --- glim.sh | 19 ++++++++++--------- grub2/grub.cfg | 16 +++++++++------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/glim.sh b/glim.sh index 031b1bd..055f544 100755 --- a/glim.sh +++ b/glim.sh @@ -51,15 +51,18 @@ fi echo "Found partition with label 'GLIM' : ${USBDEV1}" # Sanity check : our partition is the first one on the block device -if [[ ! "${USBDEV1}" == *[a-z]1 ]]; then - echo "ERROR: $USBDEV1 is not the first partition on the block device." - exit 1 -fi -USBDEV=${USBDEV1%1} +USBDEV="${USBDEV1/%[0-9]/}" # This will fail if there are more than 9 partitions on the device, but seems unlikely & will work with NVMe partitions like /dev/nvme0n1p2 if [[ ! -b "$USBDEV" ]]; then echo "ERROR: ${USBDEV} block device not found." exit 1 fi +echo "Running fdisk -l ${USBDEV} (with sudo) ..." +FDisk="$(sudo fdisk -l ${USBDEV})" +mapfile -t PartOrder < <(echo "$FDisk" | grep -E ^${USBDEV} | sort -nk2,2 | awk '{ print $1 }') +if [[ "${USBDEV1}" != "${PartOrder[0]}" ]]; then + echo "ERROR: $USBDEV1 is not the first partition on the block device." + exit 1 +fi echo "Found block device where to install GRUB2 : ${USBDEV}" if [[ `ls -1 ${USBDEV}* | wc -l` -gt 3 ]]; then echo "WARNING: There are more than two partitions on ${USBDEV}" @@ -73,7 +76,7 @@ elif [[ "$(echo "$USBDEV2" | wc -l)" -gt 1 ]]; then echo "ERROR: multiple partitions found with label 'GLIMISO', please disconnect/rename the unwanted ones." exit 1 else - if [[ "$USBDEV2" != "${USBDEV}2" ]]; then + if [[ "$USBDEV2" != "${PartOrder[1]}" ]]; then USBDEV2="" echo "WARNING: Ignored 'GLIMISO' partition ${USBDEV2} because it is not the second partition on the block device." else @@ -97,7 +100,6 @@ echo "Found 'GLIM' mount point for filesystem : ${USBMNT}" if [[ -z "$USBDEV2" ]]; then # (no second partition for ISOs) USBMNTISO="${USBMNT}" - #USBMNTISO="${USBMNT}/boot" # have ISOs where GLIM used to put them else if ! grep -q -w ${USBDEV2} /proc/mounts; then echo "ERROR: ${USBDEV2} isn't mounted" @@ -121,8 +123,7 @@ else fi # Check disk's partition table type -echo "Running fdisk -l ${USBDEV} (with sudo) to check if using GPT or MBR..." -PartType="$(sudo fdisk -l ${USBDEV} | grep -iPo "Disklabel type:\s\K.*")" +PartType="$(echo "$FDisk" | grep -iPo "Disklabel type:\s\K.*")" if [[ $? -ne 0 ]]; then PartType="dos" # Error, so assume the best case so don't give spurious warnings elif [[ "$PartType" == "gpt" ]]; then diff --git a/grub2/grub.cfg b/grub2/grub.cfg index b8ecfe4..a89a2ed 100644 --- a/grub2/grub.cfg +++ b/grub2/grub.cfg @@ -32,13 +32,15 @@ insmod part_msdos insmod part_gpt insmod ext2 insmod ntfs -if [ -e (hd0,gpt2)${isopath} ]; then - set root="(hd0,gpt2)" -elif [ -e (hd0,msdos2)${isopath} ]; then - set root="(hd0,msdos2)" -#else -# set isopath=/boot/iso -fi +for i in 0 1 2 3 4 5 6 7 8 9; do + if [ -e (hd0,gpt$i)${isopath} ]; then + set root="(hd0,gpt$i)" + break + elif [ -e (hd0,msdos$i)${isopath} ]; then + set root="(hd0,msdos$i)" + break + fi +done # Required to have these available in other configfile files export rootuuid From 73d53cb93d8737de37e6cda018ff496cf749a410 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Thu, 20 Feb 2025 21:51:37 +0000 Subject: [PATCH 13/23] Fix typo --- glim.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glim.sh b/glim.sh index 055f544..3e757a1 100755 --- a/glim.sh +++ b/glim.sh @@ -130,7 +130,7 @@ elif [[ "$PartType" == "gpt" ]]; then echo "The ${USBDEV} block device uses GPT, which means you can only install for EFI (not BIOS) unless it has a 1MB BIOS Boot partition for Grub. GLIM needs this after the GLIMISO partition (if there is one)." else PartType="dos" # Ensure script behaves sensibly if fdisk doesn't output "gpt" or "dos" - echo "The ${USBDEV} block device uses GPT, which means Grub can install for both EFI & BIOS." + echo "The ${USBDEV} block device uses MBR, which means Grub can install for both EFI & BIOS." fi # From b5fedc444032baaf1cbe1805f9d94286dce58e71 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Tue, 25 Feb 2025 12:44:07 +0000 Subject: [PATCH 14/23] Removed command I added to README to clone original repo, since it's not even clear if the pull request will be accepted. Also add two commented-out lines to add LVM & BTRFS support. --- README.md | 7 ++----- grub2/grub.cfg | 2 ++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9ef7120..1ad3882 100644 --- a/README.md +++ b/README.md @@ -83,11 +83,8 @@ Installation Mount the GLIM partition (and the GLIMISO partition if present) on your USB memory stick (or external hard drive). -Then clone this git repository: - - git clone git@github.com:thias/glim.git - -And just run the script (as a normal user) : +Then clone the git repository (or use Code > Download ZIP before unzipping it), +and just run the script (as a normal user) : ./glim.sh diff --git a/grub2/grub.cfg b/grub2/grub.cfg index a89a2ed..06e34c0 100644 --- a/grub2/grub.cfg +++ b/grub2/grub.cfg @@ -32,6 +32,8 @@ insmod part_msdos insmod part_gpt insmod ext2 insmod ntfs +#insmod btrfs +#insmod lvm for i in 0 1 2 3 4 5 6 7 8 9; do if [ -e (hd0,gpt$i)${isopath} ]; then set root="(hd0,gpt$i)" From 48b9b6d3c1f0f9096316021e9bf23902f7b5c9d0 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Thu, 27 Feb 2025 22:12:42 +0000 Subject: [PATCH 15/23] Ensure the ISO folders are owned by the user (not root) if sudo had to be used --- glim.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/glim.sh b/glim.sh index 3e757a1..06afd66 100755 --- a/glim.sh +++ b/glim.sh @@ -209,25 +209,32 @@ fi # Check USB mount dir write permission, to use sudo if missing if [[ -w "${USBMNT}" ]]; then CMD_PREFIX="" + CMD_CHOWN="" else CMD_PREFIX="sudo" + CMD_CHOWN="--copy-as=$USER" fi if [[ -w "${USBMNTISO}" ]]; then ISOCMD_PREFIX="" + ISOCMD_CHOWN="" else ISOCMD_PREFIX="sudo" + ISOCMD_CHOWN="sudo chown $USER:$USER" fi # Copy GRUB2 configuration -echo "Running rsync -rt --delete --exclude=i386-pc --exclude=x86_64-efi --exclude=fonts -- ${GRUB2_CONF}/ '${USBMNT}/boot/${GRUB2_DIR}' ..." -${CMD_PREFIX} rsync -rt --delete --exclude=i386-pc --exclude=x86_64-efi --exclude=fonts -- ${GRUB2_CONF}/ "${USBMNT}/boot/${GRUB2_DIR}" +echo "Running rsync -rt $CMD_CHOWN --delete --exclude=i386-pc --exclude=x86_64-efi --exclude=fonts -- ${GRUB2_CONF}/ '${USBMNT}/boot/${GRUB2_DIR}' ..." +${CMD_PREFIX} rsync -rt $CMD_CHOWN --delete --exclude=i386-pc --exclude=x86_64-efi --exclude=fonts -- ${GRUB2_CONF}/ "${USBMNT}/boot/${GRUB2_DIR}" if [[ $? -ne 0 ]]; then echo "ERROR: the rsync copy returned with an error exit status." exit 1 fi # Be nice and pre-create the directory, and mention it -[[ -d "${USBMNTISO}/iso" ]] || ${ISOCMD_PREFIX} mkdir -p "${USBMNTISO}/iso" +if [[ ! -d "${USBMNTISO}/iso" ]]; then + ${ISOCMD_PREFIX} mkdir -p "${USBMNTISO}/iso" + if [ -n "$ISOCMD_CHOWN" ]; then $ISOCMD_CHOWN "${USBMNTISO}/iso"; fi +fi echo "GLIM installed! Time to populate the '${USBMNTISO}/iso' sub-directories." # Now also pre-create all supported sub-directories since empty are ignored @@ -237,7 +244,10 @@ args=( ) for DIR in $(sed "${args[@]}" "$(dirname "$0")"/README.md); do - [[ -d "${USBMNTISO}/iso/${DIR}" ]] || ${ISOCMD_PREFIX} mkdir -p "${USBMNTISO}/iso/${DIR}" + if [[ ! -d "${USBMNTISO}/iso/${DIR}" ]]; then + ${ISOCMD_PREFIX} mkdir -p "${USBMNTISO}/iso/${DIR}" + if [ -n "$ISOCMD_CHOWN" ]; then $ISOCMD_CHOWN "${USBMNTISO}/iso/${DIR}"; fi + fi done echo "Finished!" From 3c0146b38e7711ec550a6e543a4f27cb7b2664ce Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Sun, 13 Apr 2025 22:06:23 +0100 Subject: [PATCH 16/23] Auto-detect when booted off a disk other than hd0. And report what it detected. (Thanks to eugenesan.) --- grub2/grub.cfg | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/grub2/grub.cfg b/grub2/grub.cfg index 06e34c0..addc0db 100644 --- a/grub2/grub.cfg +++ b/grub2/grub.cfg @@ -18,6 +18,9 @@ set gfxpayload=keep # Enable GUI terminal_output gfxterm +# Welcome msg +echo "Booting GLIM" + # Set how menu looks loadfont unicode insmod png @@ -30,19 +33,26 @@ probe --set rootuuid --fs-uuid $root set isopath=/iso insmod part_msdos insmod part_gpt +insmod exfat insmod ext2 insmod ntfs #insmod btrfs #insmod lvm -for i in 0 1 2 3 4 5 6 7 8 9; do - if [ -e (hd0,gpt$i)${isopath} ]; then - set root="(hd0,gpt$i)" +insmod regexp +echo "Boot partition: ${root}" +#set hdnum=0 +regexp --set 1:hdnum "^hd([0-9]+),.*" "${root}" +echo "Boot disk: hd${hdnum}" +for pnum in 0 1 2 3 4 5 6 7 8 9; do + if [ -e (hd${hdnum},gpt${pnum})${isopath} ]; then + set root="(hd${hdnum},gpt${pnum})" break - elif [ -e (hd0,msdos$i)${isopath} ]; then - set root="(hd0,msdos$i)" + elif [ -e (hd${hdnum},msdos${pnum})${isopath} ]; then + set root="(hd${hdnum},msdos${pnum})" break fi done +echo "ISO partition: ${root}" # Required to have these available in other configfile files export rootuuid From 315ff6483c9098121829f2d08fcfc774d19e133e Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Sun, 13 Apr 2025 22:06:39 +0100 Subject: [PATCH 17/23] Prevent EFI boot menu from being updated to show GLIM. Copy readme to GLIM partitions. (Thanks to eugenesan.) --- glim.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/glim.sh b/glim.sh index 06afd66..078768e 100755 --- a/glim.sh +++ b/glim.sh @@ -51,7 +51,7 @@ fi echo "Found partition with label 'GLIM' : ${USBDEV1}" # Sanity check : our partition is the first one on the block device -USBDEV="${USBDEV1/%[0-9]/}" # This will fail if there are more than 9 partitions on the device, but seems unlikely & will work with NVMe partitions like /dev/nvme0n1p2 +USBDEV="${USBDEV1/%[0-9]/}" # This will fail if there are more than 10 partitions on the device, but seems unlikely & will work with NVMe partitions like /dev/nvme0n1p2 if [[ ! -b "$USBDEV" ]]; then echo "ERROR: ${USBDEV} block device not found." exit 1 @@ -197,7 +197,7 @@ if [[ $BIOS == true ]]; then fi fi if [[ $EFI == true ]]; then - GRUB_TARGET="--target=x86_64-efi --removable" + GRUB_TARGET="--target=x86_64-efi --removable --no-nvram" echo "Running ${GRUB2_INSTALL} ${GRUB_TARGET} --efi-directory '${USBMNT}' --boot-directory '${USBMNT}/boot' ${USBDEV} (with sudo) ..." sudo ${GRUB2_INSTALL} ${GRUB_TARGET} --efi-directory "${USBMNT}" --boot-directory "${USBMNT}/boot" ${USBDEV} if [[ $? -ne 0 ]]; then @@ -232,8 +232,8 @@ fi # Be nice and pre-create the directory, and mention it if [[ ! -d "${USBMNTISO}/iso" ]]; then - ${ISOCMD_PREFIX} mkdir -p "${USBMNTISO}/iso" - if [ -n "$ISOCMD_CHOWN" ]; then $ISOCMD_CHOWN "${USBMNTISO}/iso"; fi + ${ISOCMD_PREFIX} mkdir -p "${USBMNTISO}/iso" + if [ -n "$ISOCMD_CHOWN" ]; then $ISOCMD_CHOWN "${USBMNTISO}/iso"; fi fi echo "GLIM installed! Time to populate the '${USBMNTISO}/iso' sub-directories." @@ -242,7 +242,6 @@ args=( -E -n '/\(distro-list-start\)/,/\(distro-list-end\)/{s,^\* \[`([a-z0-9]+)`\].*$,\1,p}' ) - for DIR in $(sed "${args[@]}" "$(dirname "$0")"/README.md); do if [[ ! -d "${USBMNTISO}/iso/${DIR}" ]]; then ${ISOCMD_PREFIX} mkdir -p "${USBMNTISO}/iso/${DIR}" @@ -250,4 +249,10 @@ for DIR in $(sed "${args[@]}" "$(dirname "$0")"/README.md); do fi done +echo "Copying readme to GLIM partitions ..." +${CMD_PREFIX} cp -v "$(dirname $0)/README.md" "${USBMNT}/glim-readme.txt" +if [[ "$USBMNTISO" != "$USBMNT" ]]; then + ${ISOCMD_PREFIX} cp -v "$(dirname $0)/README.md" "${USBMNTISO}/glim-readme.txt" +fi + echo "Finished!" From 896233ed3cb6184868444e7dd28b59a2b23c84be Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Sun, 13 Apr 2025 22:06:56 +0100 Subject: [PATCH 18/23] Credit Eugene Sanivsky (eugenesan). Cosmetic improvements. --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1ad3882..fd24098 100644 --- a/README.md +++ b/README.md @@ -85,9 +85,9 @@ memory stick (or external hard drive). Then clone the git repository (or use Code > Download ZIP before unzipping it), and just run the script (as a normal user) : - - ./glim.sh - +``` +./glim.sh +``` Once finished, you may change the filesystem label to anything you like. The script will have created an `iso` folder, inside of which you will see an empty folder for each supported Linux distro. @@ -261,11 +261,12 @@ create a GitHub pull request which includes : may work. * An updated supported directories list in this README file. +Credits +------- ---- -Copyleft 2012-2023 Matthias Saou http://matthias.saou.eu/ - -Copyleft 2025 Chris Handley https://github.com/cshandley-uk +* Copyleft 2012-2023 Matthias Saou http://matthias.saou.eu/ +* Copyleft 2025 Chris Handley https://github.com/cshandley-uk +* Copyleft 2025 Eugene Sanivsky (eugenesan) https://github.com/eugenesan All configuration files included are public domain. Do what you want with them. The invader logo was made by me, so unless the exact shape is covered by From 3108c26ddf3585c76e00a6f9138000f47f7ce275 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Mon, 14 Apr 2025 21:59:48 +0100 Subject: [PATCH 19/23] Added 'format_empty_disk.sh' script --- README.md | 17 ++++++- format_empty_disk.sh | 116 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 format_empty_disk.sh diff --git a/README.md b/README.md index fd24098..b88ba18 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ GRUB2 Live ISO Multiboot ======================== -https://github.com/thias/glim | http://glee.thias.es/GLIM +This version: https://github.com/cshandley-uk/bash_glim +Forked from: https://github.com/thias/glim | http://glee.thias.es/GLIM Overview @@ -47,6 +48,8 @@ although you can still use a single partition if you want. easier to find, and also is in the same location whether you use one or two partitions. +* Added the `format_empty_disk.sh` script. + Requirements ------------ @@ -76,6 +79,18 @@ change it's partition type to "BIOS Boot" (which has the GUID `21686148-6449-6E6F-744E-656564454649`). You can do this with GNOME's Disks utility, without resorting to the terminal! +Alternatively you can try using `format_empty_disk.sh`, my experimental new +script which will ask you a few questions before before setting-up an empty +disk with GLIM's recommended two partition set-up (plus a BIOS Boot partition), +ready to use with `glim.sh` itself. I've tried to make it safe, so for example +it shouldn't delete any partitions, only create new ones... And in the event of +any errors, the script should stop rather than risk doing anything wrong. +HOWEVER, it is still a very new script, which likely contains bugs, especially +on systems different to my own, so please let me know about any problems you +experience. You use this script entirely at your own risk. If it formats your +entire computer, then that is your problem. So please make sure you have a +recent backup before using it. + Installation ------------ diff --git a/format_empty_disk.sh b/format_empty_disk.sh new file mode 100644 index 0000000..9b6ea13 --- /dev/null +++ b/format_empty_disk.sh @@ -0,0 +1,116 @@ +#!/bin/bash +set -e # exit on error +#set -v # print script lines to be executed +#set -x # print commands being executed + +for Cmd in fdisk lsblk sgdisk blockdev partprobe; do + if [ -z "$(which $Cmd | cat)" ]; then + echo "ERROR: This script needs the '$Cmd' command, please install it." + exit 1 + fi +done + +GlimSize=100M +BiosBootSize=1M + +echo "Please read the 'README.md' documentation before using this script." +echo "" +echo "WARNING: This script will format a chosen empty hard disk with GLIM's recommended set-up. Although I've tried to be careful, a bug could potentially wipe your whole computer. So make sure you have a recent backed-up before executing this script." +echo "" +echo 'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.' +echo "" +read -p "If you have read, understood & fully accepted the above, then please enter 'yes' in capitals: " Ans +if [ "$Ans" != "YES" ]; then + echo "Script cancelled by user." + exit 0 +fi +echo "" + +# Specify disk to overwrite +read -p "Please enter path of disk to overwrite: " Disk +if [ -z "$Disk" ]; then echo "Script cancelled by user."; exit 0; fi +echo "" + +# Check that disk is a block device +#if [[ ! "$Disk" == /dev/* ]]; then +# echo "ERROR: '$Disk' does not start with /dev/" +# exit 1 +#fi +Devices="$(lsblk -o name -lpn --nodeps -e7)" +if [ -z "$(echo "$Devices" | grep "^${Disk}$")" ]; then + echo "ERROR: '$Disk' is not a known block device:" + echo "$Devices" + exit 1 +fi + +# Check not overwriting the boot disk (but this is not foolproof) +if [[ "$(awk '$1 ~ /^\/dev\// && $2 == "/boot" { print $1 }' /proc/self/mounts)" == ${Disk}* ]]; then + echo "ERROR: $Disk is the boot disk." + exit 1 +fi + +## Check that disk has no mounted partitions +#if [ -n "$(mount | grep ^$Disk | cat)" ]; then +# echo "ERROR: $Disk is has mounted partitions." +# exit 1 +#fi + +# Check that disk has no partitions +set -x +Partitions="$(sudo fdisk -l $Disk | sed '1,/^$/d')" +set +x +if [ "$(echo "$Partitions" | wc -l)" -gt 1 ]; then + echo "ERROR: $Disk is not empty, it has partitions:" + echo "$Partitions" + exit 1 +fi + +# Confirm using the correct disk +sudo sgdisk --print $Disk +echo "" +read -p "Is this the correct disk to overwrite? [y/N] " Ans +if [[ "$Ans" != "y" && "$Ans" != "Y" ]]; then echo "Script cancelled by user."; exit 1; fi +echo "" + +# Create partitions on disk +trap "echo 'ERROR: Script did not finished partitioning.'" EXIT +set -x +#sudo sgdisk --zap-all $Disk # erase any existing partition information from HD +sudo sgdisk --mbrtogpt $Disk # use GPT not MBR +sudo sgdisk --clear $Disk # wipe any previous partition +#sudo partprobe $Disk # request the OS re-reads the partition table +sudo blockdev --rereadpt $Disk # request the OS re-reads the partition table', and errors if a partition is already mounted on the disk + +sudo sgdisk --new=1:0:+$GlimSize $Disk # use first 100MB +sudo sgdisk --new=3:-${BiosBootSize}:0 --typecode=3:ef02 --partition-guid=3:21686148-6449-6E6F-744E-656564454649 $Disk # use last 1MB for BIOS Boot partition needed by GRUB +sudo sgdisk --new=2:0:0 $Disk # use rest of space +#sudo sgdisk --typecode=1:8300 --typecode=2:8300 $Disk +#sudo sgdisk --change-name=1:GLIM $Disk # This is just a human-readable label, displayed by --print under the Name column +#sudo sgdisk --change-name=2:GLIMISO $Disk +sudo sgdisk --change-name=3:"BIOS Boot" $Disk +sudo partprobe $Disk # ensure kernel is using the new partition table, before we format partitions +set +x + +echo "Waiting a few seconds... " +sleep 2 # give OS time to auto-mount new partitions, if they happened to start at same location as a previously-deleted partition +sudo umount ${Disk}1 2>/dev/null | cat +sudo umount ${Disk}2 2>/dev/null | cat +sudo umount ${Disk}3 2>/dev/null | cat + +# Format partitions +trap "echo 'ERROR: Script did not finished formatting.'" EXIT +set -x +sudo mkfs.fat -F 32 -n GLIM ${Disk}1 +sudo mkfs.ext4 -L GLIMISO ${Disk}2 +set +x + +# Try to get OS to mount new partitions +sleep 1 +sudo partprobe $Disk +#sudo blockdev --rereadpt $Disk + +# Report success +echo "" +echo "Successfully finished creating the partitions needed by GLIM." +echo "Ensure ${Disk}1 (GLIM) & ${Disk}2 (GLIMISO) are mounted before running the 'glim.sh' script." +trap "" EXIT From 5015483d04f4bb0a7f5bb098bba493604aeb4bc6 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Mon, 14 Apr 2025 22:05:28 +0100 Subject: [PATCH 20/23] Disabled superfluous partition wiping command --- README.md | 2 +- format_empty_disk.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b88ba18..0532e82 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ script which will ask you a few questions before before setting-up an empty disk with GLIM's recommended two partition set-up (plus a BIOS Boot partition), ready to use with `glim.sh` itself. I've tried to make it safe, so for example it shouldn't delete any partitions, only create new ones... And in the event of -any errors, the script should stop rather than risk doing anything wrong. +any errors, the script should stop rather than risk doing anything wrong. HOWEVER, it is still a very new script, which likely contains bugs, especially on systems different to my own, so please let me know about any problems you experience. You use this script entirely at your own risk. If it formats your diff --git a/format_empty_disk.sh b/format_empty_disk.sh index 9b6ea13..76c704b 100644 --- a/format_empty_disk.sh +++ b/format_empty_disk.sh @@ -77,7 +77,7 @@ trap "echo 'ERROR: Script did not finished partitioning.'" EXIT set -x #sudo sgdisk --zap-all $Disk # erase any existing partition information from HD sudo sgdisk --mbrtogpt $Disk # use GPT not MBR -sudo sgdisk --clear $Disk # wipe any previous partition +#sudo sgdisk --clear $Disk # wipe any previous partition #sudo partprobe $Disk # request the OS re-reads the partition table sudo blockdev --rereadpt $Disk # request the OS re-reads the partition table', and errors if a partition is already mounted on the disk From 3b3acd1e38ae6d7d58512af6657c6fd76253ce49 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Fri, 30 May 2025 17:26:11 +0100 Subject: [PATCH 21/23] Update README to clarify MBR needed for legacy BIOS & reworked MBR/GPT & partitioning explanation --- README.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 0532e82..b2e9599 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ GRUB2 Live ISO Multiboot ======================== This version: https://github.com/cshandley-uk/bash_glim -Forked from: https://github.com/thias/glim | http://glee.thias.es/GLIM + +Forked from: https://github.com/thias/glim | https://glee.thias.es/GLIM Overview @@ -30,7 +31,6 @@ it, which isn't the case for many with NTFS (Ubuntu does, Fedora doesn't) and exFAT (Ubuntu doesn't, Fedora does). Ext4 is a safe bet for the second partition. - Screenshots ----------- @@ -58,19 +58,19 @@ You need a USB memory stick (or external hard drive!) partitioned & formatted one of the following ways: 1. A single partition formatted as FAT32 with the filesystem label `GLIM`. -It doesn't matter if it uses MBR or GPT. +You can use MBR or GPT as needed (but legacy BIOS may need MBR). or 2. Two partitions. The small first partition must be formatted as FAT32 with the filesystem label `GLIM`, I suggest 100MB in size. The second partition -should be formatted as Ext4 with the filesystem label `GLIMISO`. It's best if -the USB stick uses MBR, but if it uses GPT (as GNOME's Disks utility does) then -GRUB only supports installing for EFI (not BIOS) - unless you add a third BIOS -Boot partition. GLIM needs the BIOS Boot partition to come after the other two -partitions. +should be formatted as Ext4 with the filesystem label `GLIMISO`. -See the link below for details on how to create a BIOS Boot partition: +It's best if the USB stick uses MBR, but if it uses GPT (as GNOME's Disks +utility does) then GRUB only supports installing for EFI (not BIOS) - unless you +add a third BIOS Boot partition. GLIM needs the BIOS Boot partition to come +after the other two partitions. See the link below for details on how to create +a BIOS Boot partition: https://wiki.archlinux.org/title/GRUB#GUID_Partition_Table_(GPT)_specific_instructions @@ -79,17 +79,17 @@ change it's partition type to "BIOS Boot" (which has the GUID `21686148-6449-6E6F-744E-656564454649`). You can do this with GNOME's Disks utility, without resorting to the terminal! -Alternatively you can try using `format_empty_disk.sh`, my experimental new -script which will ask you a few questions before before setting-up an empty -disk with GLIM's recommended two partition set-up (plus a BIOS Boot partition), -ready to use with `glim.sh` itself. I've tried to make it safe, so for example -it shouldn't delete any partitions, only create new ones... And in the event of -any errors, the script should stop rather than risk doing anything wrong. -HOWEVER, it is still a very new script, which likely contains bugs, especially -on systems different to my own, so please let me know about any problems you -experience. You use this script entirely at your own risk. If it formats your -entire computer, then that is your problem. So please make sure you have a -recent backup before using it. +Or if you find partitioning difficult, then you can try using my experimental +new script `format_empty_disk.sh`, which will ask you a few questions before +before setting-up an empty disk with GLIM's recommended two partition GPT set-up +(plus a BIOS Boot partition), ready to use with `glim.sh` itself. I've tried to +make it safe, so for example it shouldn't delete any partitions, only create new +ones... And in the event of any errors, the script should stop rather than risk +doing anything wrong. HOWEVER, it is still a very new script, which likely +contains bugs, especially on systems different to my own, so please let me know +about any problems you experience. You use this script entirely at your own +risk. If it formats your entire computer, then that is your problem. So please +make sure you have a recent backup before using it. Installation From a024164784570099eb4acb137077f313360125af Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Fri, 30 May 2025 16:48:50 +0100 Subject: [PATCH 22/23] Offer to install require commands using 'apt'. Fix cosmetic typo. --- format_empty_disk.sh | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/format_empty_disk.sh b/format_empty_disk.sh index 76c704b..6458632 100644 --- a/format_empty_disk.sh +++ b/format_empty_disk.sh @@ -3,19 +3,47 @@ set -e # exit on error #set -v # print script lines to be executed #set -x # print commands being executed -for Cmd in fdisk lsblk sgdisk blockdev partprobe; do +GlimSize=100M +BiosBootSize=1M + +# Check if necessary commands are installed +NeededCmds="fdisk sgdisk partprobe awk mkfs.fat lsblk blockdev" +for Cmd in $NeededCmds; do if [ -z "$(which $Cmd | cat)" ]; then + # (command not installed) + if [ -n "$(which apt | cat)" ]; then + # (system uses 'apt') so offer to install missing command + echo "This script needs the '$Cmd' command, so trying to install it:" + if [ "$Cmd" == "sgdisk" ]; then + sudo apt install gdisk + elif [ "$Cmd" == "partprobe" ]; then + sudo apt install parted + elif [ "$Cmd" == "awk" ]; then + sudo apt install gawk + elif [ "$Cmd" == "mkfs.fat" ]; then + sudo apt install dosfstools + elif [ "$Cmd" == "lsblk" ]; then + sudo apt install util-linux # this should always be installed + elif [ "$Cmd" == "blockdev" ]; then + sudo apt install util-linux # ditto + else + sudo apt install $Cmd # works for "fdisk" + fi + fi + fi +done +for Cmd in $NeededCmds; do + if [ -z "$(which $Cmd | cat)" ]; then + # (command not installed) echo "ERROR: This script needs the '$Cmd' command, please install it." exit 1 fi done -GlimSize=100M -BiosBootSize=1M - +# Show warning to user echo "Please read the 'README.md' documentation before using this script." echo "" -echo "WARNING: This script will format a chosen empty hard disk with GLIM's recommended set-up. Although I've tried to be careful, a bug could potentially wipe your whole computer. So make sure you have a recent backed-up before executing this script." +echo "WARNING: This script will format a chosen empty hard disk with GLIM's recommended set-up. Although I've tried to be careful, a bug could potentially wipe your whole computer. So make sure you have a recent backup before executing this script." echo "" echo 'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.' echo "" @@ -44,13 +72,13 @@ if [ -z "$(echo "$Devices" | grep "^${Disk}$")" ]; then fi # Check not overwriting the boot disk (but this is not foolproof) -if [[ "$(awk '$1 ~ /^\/dev\// && $2 == "/boot" { print $1 }' /proc/self/mounts)" == ${Disk}* ]]; then +if [[ "$(awk '$2 == "/boot" && $1 ~ /^\/dev\// { print $1 }' /proc/self/mounts)" == ${Disk}* ]]; then echo "ERROR: $Disk is the boot disk." exit 1 fi ## Check that disk has no mounted partitions -#if [ -n "$(mount | grep ^$Disk | cat)" ]; then +#if [ -n "$(grep ^$Disk /proc/self/mounts | cat)" ]; then # echo "ERROR: $Disk is has mounted partitions." # exit 1 #fi From 5e2d3fe74afd4be77f27171fb5c0ed21c0af3222 Mon Sep 17 00:00:00 2001 From: Chris Handley <61214105+cshandley-uk@users.noreply.github.com> Date: Fri, 30 May 2025 18:08:54 +0100 Subject: [PATCH 23/23] Detect BIOS Boot partition & adjust user messages accordingly (more user friendly) --- glim.sh | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/glim.sh b/glim.sh index 078768e..744cddf 100755 --- a/glim.sh +++ b/glim.sh @@ -64,9 +64,6 @@ if [[ "${USBDEV1}" != "${PartOrder[0]}" ]]; then exit 1 fi echo "Found block device where to install GRUB2 : ${USBDEV}" -if [[ `ls -1 ${USBDEV}* | wc -l` -gt 3 ]]; then - echo "WARNING: There are more than two partitions on ${USBDEV}" -fi # Look for second partition USBDEV2=`blkid -L GLIMISO` @@ -84,6 +81,19 @@ else fi fi +# Look for BIOS Boot partition +BiosBoot="$(echo "$FDisk" | grep -E ^${USBDEV} | awk '{ print $1 }' | xargs -I {} lsblk -ndo PARTTYPE {} | grep "^21686148-6449-6e6f-744e-656564454649$" | cat)" + +if [ -n "$BiosBoot" ]; then + echo "Found BIOS Boot partition." + NumOfPartitionsExpected=3 +else + NumOfPartitionsExpected=2 +fi +if [[ `ls -1 ${USBDEV}?* | wc -l` -gt $NumOfPartitionsExpected ]]; then + echo "WARNING: There are more than $NumOfPartitionsExpected partitions on ${USBDEV}" +fi + # Sanity check : our GLIM partition is mounted if ! grep -q -w ${USBDEV1} /proc/mounts; then echo "ERROR: ${USBDEV1} isn't mounted" @@ -127,7 +137,11 @@ PartType="$(echo "$FDisk" | grep -iPo "Disklabel type:\s\K.*")" if [[ $? -ne 0 ]]; then PartType="dos" # Error, so assume the best case so don't give spurious warnings elif [[ "$PartType" == "gpt" ]]; then - echo "The ${USBDEV} block device uses GPT, which means you can only install for EFI (not BIOS) unless it has a 1MB BIOS Boot partition for Grub. GLIM needs this after the GLIMISO partition (if there is one)." + if [[ -z "$BiosBoot" ]]; then + echo "The ${USBDEV} block device uses GPT, but appears to be missing the 1MB BIOS Boot partition, so Grub can only install EFI (not BIOS). Grub needs a 1MB BIOS Boot partition, and GLIM needs this after the GLIMISO partition (if there is one)." + else + echo "The ${USBDEV} block device uses GPT, and Grub can install for both EFI & BIOS, since it has the required BIOS Boot partition." + fi else PartType="dos" # Ensure script behaves sensibly if fdisk doesn't output "gpt" or "dos" echo "The ${USBDEV} block device uses MBR, which means Grub can install for both EFI & BIOS." @@ -147,8 +161,8 @@ if [[ $BIOS == true ]]; then EFI=true echo "y" - if [[ "$PartType" == "gpt" ]]; then - BiosBootPartWarning="(Grub needs a BIOS Boot Partition) " + if [[ "$PartType" == "gpt" && -z "$BiosBoot" ]]; then + BiosBootPartWarning="(Grub needs a BIOS Boot Partition - which was NOT found) " fi read -n 1 -s -p "Also install for standard BIOS? $BiosBootPartWarning(y/N) " BIOS if [[ "$BIOS" == "y" || "$BIOS" == "Y" ]]; then