Skip to content

Add support for >4GB ISO by optionally supporting a second partition. Plus other small improvements. #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2cd3342
Halt if multiple GLIM partitions are found
cshandley-uk Feb 19, 2025
5bae091
Actually check GLIM is the first partition. Warn rather than error if…
cshandley-uk Feb 19, 2025
f59e3fa
Fix script to handle spaces in $USBMNT
cshandley-uk Feb 19, 2025
a302c78
Make harder to accidentally accept 'Ready to install GLIM' by changin…
cshandley-uk Feb 19, 2025
d6db6f6
Warn that Grub needs a BIOS Boot Partition if GPT is used. Allow inst…
cshandley-uk Feb 19, 2025
5cf7b15
Print 'Finished' so users knows the script completed successfully (ra…
cshandley-uk Feb 19, 2025
e21f178
Allow ISOs to be stored on a separate partition (e.g. ext4) to suppor…
cshandley-uk Feb 19, 2025
c878989
Don't print errors if user runs GLIM on an existing GLIM installation
cshandley-uk Feb 19, 2025
e31577a
Updated README for optional second partition. Explain that GPT needs …
cshandley-uk Feb 19, 2025
79975b6
Fix indentation
cshandley-uk Feb 19, 2025
4aad6d9
Small improvement to README
cshandley-uk Feb 20, 2025
ba2522e
Handle cases where partition table entries are not in disk order
cshandley-uk Feb 20, 2025
73d53cb
Fix typo
cshandley-uk Feb 20, 2025
b5fedc4
Removed command I added to README to clone original repo, since it's …
cshandley-uk Feb 25, 2025
48b9b6d
Ensure the ISO folders are owned by the user (not root) if sudo had t…
cshandley-uk Feb 27, 2025
3c0146b
Auto-detect when booted off a disk other than hd0. And report what it…
cshandley-uk Apr 13, 2025
315ff64
Prevent EFI boot menu from being updated to show GLIM. Copy readme to…
cshandley-uk Apr 13, 2025
896233e
Credit Eugene Sanivsky (eugenesan). Cosmetic improvements.
cshandley-uk Apr 13, 2025
3108c26
Added 'format_empty_disk.sh' script
cshandley-uk Apr 14, 2025
5015483
Disabled superfluous partition wiping command
cshandley-uk Apr 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 83 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
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
--------

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 :

Expand All @@ -22,12 +23,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
Expand All @@ -37,18 +38,76 @@ Screenshots
![Ubuntu Submenu](https://github.com/thias/glim/raw/master/screenshots/GLIM-3.0-shot2.png)


Installation
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.

* Added the `format_empty_disk.sh` script.


Requirements
------------

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) :
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 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:

https://wiki.archlinux.org/title/GRUB#GUID_Partition_Table_(GPT)_specific_instructions

./glim.sh
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!

Once finished, you may change the filesystem label to anything you like.
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.

The supported `boot/iso/` sub-directories (in alphabetical order) are :

Installation
------------

Mount the GLIM partition (and the GLIMISO partition if present) on your USB
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
```
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 `iso` sub-directories (in alphabetical order) are :

[//]: # (distro-list-start)

Expand Down Expand Up @@ -97,13 +156,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
Expand Down Expand Up @@ -217,9 +276,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 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
Expand Down
116 changes: 116 additions & 0 deletions format_empty_disk.sh
Original file line number Diff line number Diff line change
@@ -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
Loading