Thursday, 9 January 2020

a1ive grub2 file manager menu for Ubuntu with persistence

Here is how to add multiple Ubuntu-based ISOs+persistence to your a1ive grub2 drive.


Instructions

1. Download and copy your Ubuntu ISO to the second partition on your E2B USB drive.

2. With your E2B drive in 'E2B' mode (you can see the \_ISO\MAINMENU folder in Explorer), run \_ISO\_Make_Ext.bat under Windows to create a persistence file in the root of the USB drive:

The volume name must be casper-rw.
You can use RMPrepUSB - Make ext2/3/4 instead of Make_Ext.bat if you wish. If you select 'All drives' in RMPrepUSB, you can make a file on the root of one of your internal hard drives.

Under Linux, you can create an ext3 file using mkfs.ext3 (see here for details).

3. Make a new folder on the second NTFS partition called \persist (the same partition that contains your Ubuntu ISO).

4. Move the persistence file into the \persist folder on the second partition. Ensure the filename is exactly the same as the ISO filename (no spaces!).

5. Create a new text file in the same folder as the .ISO file with exactly the same name as the ISO but with a .grubfm file extension.

e.g. ubuntu-18.04.3-desktop-amd64.grubfm (download here) - this file should work with most Ubuntu-based ISOs - just change the filename to match the ISO filename.

# available variables are:
# grubfm_file     - e.g. (hd0,msdos1)/test/ubuntu.iso
# grubfm_path     - e.g. /test/ubuntu.iso
# grubfm_dir      - e.g. /test/
# grubfm_device   - e.g. hd0,msdos1
# grubfm_disk     - e.g. hd0
# grubfm_name     - e.g. ubuntu.iso
# grubfm_filename - e.g. ubuntu
# grubfm_fileext  - e.g. iso
# grub_platform   - e.g. efi or pc  (UEFI or Legacy BIOS)
# grub_cpu        - e.g. i386 or x86_64 (i386=Legacy mode or 32-bit UEFI, x86_64=UEFI64)
# grub_uefi_version  - e.g. 2.4
# grub_secureboot
# CPU  (=32 or 64)

if cpuid -l; then set CPU=64; else set CPU=32; fi

# --class=   defines the icon displayed next to the menuentry

# Only show menu if 64-bit CPU:
if [ "$CPU" == "64" ] ; then
menuentry "Ubuntu 64-bit with persistence" --unrestricted --class ubuntu {
#only update partition table if already empty
if ! test -d (hd0,4) ; then partnew --type=0x00 --file="(${grubfm_device})/persist/${grubfm_filename}" (${grubfm_disk}) 4 ; fi
sleep 1
loopback loop "${grubfm_file}" 
set root=(loop)
if [ -e (loop)/casper/vmlinuz ]; then set vml=vmlinuz ; fi
if [ -e (loop)/casper/vmlinuz.efi ]; then set vml=vmlinuz.efi ; fi
if [ -e (loop)/casper/initrd ]; then set init=initrd ; fi
if [ -e (loop)/casper/initrd.lz ]; then set init=initrd.lz ; fi
linux (loop)/casper/$vml boot=casper persistent iso-scan/filename=$grubfm_path $params quiet splash
initrd (loop)/casper/$init
boot
}
else
# return back to 'open' menu
grubfm_open "${grubfm_file}"
fi

# Only show menu if 64-bit CPU:
if [ "$CPU" == "64" ] ; then
menuentry "Ubuntu 64-bit UK (no persistence)" --unrestricted --class ubuntu {
set params=locale=en_GB.UTF-8
echo Using $params
sleep 1
loopback loop "${grubfm_file}" 
set root=(loop)
if [ -e (loop)/casper/vmlinuz ]; then set vml=vmlinuz ; fi
if [ -e (loop)/casper/vmlinuz.efi ]; then set vml=vmlinuz.efi ; fi
if [ -e (loop)/casper/initrd ]; then set init=initrd ; fi
if [ -e (loop)/casper/initrd.lz ]; then set init=initrd.lz ; fi
linux (loop)/casper/$vml boot=casper iso-scan/filename=$grubfm_path $params quiet splash
initrd (loop)/casper/$init
boot
}
else
# return back to 'open' menu
grubfm_open "${grubfm_file}"
fi

menuentry "Back" {
grubfm_open "${grubfm_file}"
}


Example:
Ptn2: \persist\ubuntu-18.04.3-desktop-amd64  - e.g. 1GiB ext3 file with volume name of casper-rw
Ptn2: \_ISO\LINUX\ubuntu-18.04.3-desktop-amd64.iso - 64-bit ISO
Ptn2: \_ISO\LINUX\ubuntu-18.04.3-desktop-amd64.grubfm - menu file

6. Now boot to the grub2 File Manager and select the .ISO file (not the .grubfm file). Then choose the 'ISO User menu' option to get the new persistence menu.

IMPORTANT: Partition 4 on the USB drive must be free\unused\empty (the E2B drive won't boot to the E2B menu if this partition is in use).

Multiple persistence sessions

It is possible to have more than one menu so you can have multiple persistence files all using the same ISO.

Just copy the first menu, change the menuentry title and add say '_A' to the end of the line:

partnew --type=0x00 --file="(${grubfm_device})/persist/${grubfm_filename}_A" (${grubfm_disk}) 4
You can now create a new persistence file \persist\ubuntu-18.04.3-desktop-amd64_A.

To prevent overwriting an existing partition entry,  use:

if ! test -d (hd0,4) ; then partnew --type=0x00 --file="(${grubfm_device})/persist/${grubfm_filename}_A" (${grubfm_disk}) 4 ; fi



Tip: If a persistent boot hangs but the normal LiveCD boot works OK, then the persistence file is probably corrupt. Re-make the persistence file. I recommend you make a backup of a 'good' persistence file, so that if your current persistence file does become corrupt, you can use replace it with the backup copy. Always shutdown Ubuntu nicely when booting with persistence!

No comments:

Post a comment