Tuesday 17 October 2017

How to add Ubuntu\LinuxMint to E2B with MBR+UEFI persistence (and an unfixed bug in Ubuntu!)

Early versions of Ubuntu (pre-v14) and Ubuntu-based linuxmint distros (pre-v17.03) could be set up with persistence with no problem.

As long as you added the 'persistent' boot parameter, the kernel script would look for either:

1) a 'casper-rw' file (formatted internally as ext2/3/4)

    - OR -

2) a FAT or ext partition with a volume label of 'casper-rw' which has been formatted as ext2/3/4.


Ubuntu bug!

However, Ubuntu 14.04 and linuxmint 17.03 and (all?) later versions have a bug in the casper boot script which means that they may fail to boot when a casper-rw partition is present and if that partition is located after the filesystem partition in the partition table. This bug does not apply if you booted from an ISO file (only from a 'flat-file' partition), so the .mnu files used by E2B which boot from ISOs are not affected by this bug.

Bug report for Ubuntu here.

So there is no problem if you use a casper-rw file (except it must be on the same partition and it must be a FAT32 or ext partition). So you can create a very large (>4GB) ext3 file on the E2B NTFS USB drive and use a .mnu file to get persistence - but this only works in MBR\Legacy mode.

For UEFI-booting, we need to create a FAT32 .imgPTN file. However, this issue does affect E2B when using .imgPTN partition images...


To work around the 'flat-file' partition bug, the persistent partition containing the ext filesystem must be before the FAT32 partition which contains the linux files in the partition table. For example:

Persistence works (this is the best arrangement):
Partition 1   SIZE=381.47MiB   Type: 00   *ACTIVE*  Ubuntu.imgPTN
START (LBA) = 378,104,968 (16896C88) SIZE (LBA) = 781,250 (000BEBC2) [End=378,886,217]

Partition 3   SIZE=1907.349MiB   Type: 0C FAT32LBA (2047GB max)       Ubuntu.
START (LBA) = 382,792,480 (16D0F320) SIZE (LBA) = 3,906,250 (003B9ACA) [End=386,698,729]

Persistence works (but may not UEFI-boot on all systems):
Partition 1   SIZE=381.47MiB   Type: 00   *ACTIVE* Ubuntu.imgPTN
START (LBA) = 386,698,736 (170C8DF0) SIZE (LBA) = 781,250 (000BEBC2) [End=387,479,985]

Partition 3   SIZE=1907.349MiB   Type: 0C FAT32LBA (2047GB max)       Ubuntu.
START (LBA) = 382,792,480 (16D0F320) SIZE (LBA) = 3,906,250 (003B9ACA) [End=386,698,729]

What matters is the partition table entry order and not the position of the partitions on the disk.
However, some UEFI BIOSes require the FAT32 partition to be after the non-FAT partition (as in the first example above).

This does not work (initramfs boot error):
Partition 1   SIZE=1907.349MiB   Type: 0C FAT32LBA (2047GB max)  *ACTIVE* Ubuntu.imgPTN
START (LBA) = 382,792,480 (16D0F320) SIZE (LBA) = 3,906,250 (003B9ACA) [End=386,698,729]

Partition 3   SIZE=381.47MiB   Type: 00        Ubuntu.   (ext3 persistent ptn)
START (LBA) = 378,104,968 (16896C88) SIZE (LBA) = 781,250 (000BEBC2) [End=378,886,217]


It means that the normal xxxx.imgPTN + xxxx. file arrangement will also fail.

There is a way to fix the casper script however - read the comments here.

But here are two ways to work around this annoying bug without needing to change the script...


MBR + UEFI (max. 4GB persistence)

This method uses a casper-rw persistence file. 

1. Drag-and-Drop the Ubuntu/Mint ISO onto the MPI_FAT32 Desktop icon to convert it to a .imgPTN file.

When prompted for a size, you must add on the extra space needed for persistence.

For example, if 1600MB was the suggested size, and you want 1GB of persistence, specify a size of 2600MB. You can add up to 4GB.

2. Copy the .imgPTN file to \_ISO\LINUX folder on the E2B USB drive.

3. Run \MAKE_THIS_DRIVE_CONTIGUOUS (run as admin).cmd

4. Switch to the .imgPTN (e.g. MBR boot or use \_ISO\SWITCH_E2B.exe

5. Edit the menu files to add the 'persistent' parameter. Typically there will be a syslinux configuration file and a grub configuration file, e.g.
\syslinux\syslinux.cfg
label live
  menu label Start Linux Mint Persistent
  kernel /casper/vmlinuz
  append  file=/cdrom/preseed/linuxmint.seed boot=casper initrd=/casper/initrd.lz persistent  nosplash --

\boot\grub\grub.cfg

menuentry "Start Linux Mint 18.2 Cinnamon 64-bit Persistent" {
set gfxpayload=keep
linux /casper/vmlinuz  file=/cdrom/preseed/linuxmint.seed boot=casper nosplash persistent --
initrd /casper/initrd.lz

6. Use RMPrepUSB - Create Ext2/3/4 FS button to create a large file to fill the unused space in the new partition:
Filename = casper-rw
Volume Label = casper-rw
Size = (max to fill remaining space)
Type = ext3

You should now be able to UEFI- or MBR-boot to a 'Live' system with persistence.

MBR + UEFI (> 4GB persistence)

This should only be attempted on NTFS E2B USB Hard Disks. It may not always work. There should be plenty of contiguous free space on the E2B drive.

This process is experimental! You cannot use the E2B menu to select the Ubuntu image file, you must use SWITCH_E2B.exe.

1. Drag-and-Drop the Ubuntu/Mint ISO onto the MPI_FAT32 Desktop icon to convert it - specify a filename with no file extension and no dots in the filename. e.g. Ubuntu182x64 and add it to the \_ISO\LINUX folder.

2. Use RMPrepUSB - Create Ext2/3/4 FS button to create a large file:
Filename = Ubuntu182x64.imgPTN
Volume Label = casper-rw
Size = (any size you like)
Type = ext3

3. Run \MAKE_THIS_DRIVE_CONTIGUOUS (run as admin).cmd

4. Run \_ISO\SWITCH_E2B.exe (the E2B menu entry will not work - you must use Switch_E2B!).

Switch in the .imgPTN and the persistence file. Ignore any error messages about Partition Type 0.

Ensure the FAT32 partition is the second one listed.
If prompted to re-order the files, say 'No' for now. However, if UEFI-booting does not work, you may need to re-order them later, which may take a while and need several attempts!

5. Edit the menu files to add the 'persistent' parameter. Typically there will be a syslinux configuration file and a grub configuration file, e.g.
\syslinux\syslinux.cfg
label live
  menu label Start Linux Mint Persistent
  kernel /casper/vmlinuz
  append  file=/cdrom/preseed/linuxmint.seed boot=casper initrd=/casper/initrd.lz persistent  nosplash --

\boot\grub\grub.cfg
menuentry "Start Linux Mint 18.2 Cinnamon 64-bit Persistent" {
set gfxpayload=keep
linux /casper/vmlinuz  file=/cdrom/preseed/linuxmint.seed boot=casper persistent nosplash --
initrd /casper/initrd.lz

You can use quiet splash instead of nosplash to suppress boot messages.

Test both MBR and UEFI-booting.

If it does not UEFI-boot, use SWITCH_E2B.exe to restore the E2B partition and then re-select the .imgPTN file but say 'Yes' to re-order the two files. This may take a while and it is not always successful!

Note: You may need to unplug and re-connect the E2B USB drive when switching and restoring partitions using Switch_E2B.exe. I found my Windows 10 system got very confused!

You can use the CSM - menu #0 option to restore the E2B partition or use Switch_E2B.exe.

2 comments:

  1. Any hope of making the E2B menu work with this workaround?
    I don't always have admin rights on the computer to use Switch_E2B.

    ReplyDelete