Friday, 17 May 2013

Booting Ubuntu 12.10/13.04 from an ISO with persistence from an NTFS USB drive

Grub4dos booting of Ubuntu with persistence from an ISO is fairly easy if you use a FAT32 USB boot drive. You just add the keyword 'persistent' into the command line and set the iso-scan/filename= to the name of the iso and create your ext2 casper-rw in the root using RMPrepUSB:


title Try Ubuntu without installing
find --set-root /ubuntu-12.10-desktop-i386.iso
map /ubuntu-12.10-desktop-i386.iso (0xff) || map --mem /ubuntu-12.10-desktop-i386.iso (0xff)
map --hook
root (0xff)
# NOTE: Next line may wrap, it should start with kernel and end woth splash --
kernel /casper/vmlinuz  file=/cdrom/preseed/ubuntu.seed noprompt boot=casper persistent iso-scan/filename=/ubuntu-12.10-desktop-i386.iso quiet splash --
initrd /casper/initrd.lz

However. when I tried this from my Easy2Boot USB hard drive, it booted fine, but persistence would not work.
The reason for this is that my USB hard drive was formatted as NTFS.
Many Ubuntu versions will not mount a casper-rw persistent file automatically if it is on an NTFS volume.
As you may know, Easy2Boot uses the trick of using the grub4dos partnew command to map a spare partition entry to an ISO file. In this way, nearly all linux ISOs can be directly booted with Easy2Boot (without needing the iso-scan/filename=xxx.iso cheat code).

Well, we can use the same trick to map the casper-rw file to an empty partition too!
Even better, we can rename the casper-rw file because linux will look for a volume name of casper-rw first before it looks for a file called casper-rw and we can put the file anywhere we like on the boot drive! This means we can have 2 or more different versions of linux ISOs (e.g. Ubuntu 12.04, 11.01, 11.10 and 12.10)  all on the same multiboot USB drive and all using different 'casper-rw' files!

The grub4dos menu for this is fairly simple too (a simplified version with no checks is shown below):


title Ubuntu-12.10-desktop-i386 PERSISTENT
partnew (hd0,2) 0x0 /ubuntu1210-rw
partnew (hd0,3) 0x0 /ubuntu-12.10-desktop-i386.iso
map /ubuntu-12.10-desktop-i386.iso (0xff)
map --hook
root (0xff)
kernel /casper/vmlinuz file=/cdrom/preseed/ubuntu.seed boot=casper persistent quiet splash --
initrd /casper/initrd.lz 


However, I have added some checks to make sure we do not trash the 3rd partition (I don't check the 4th partition in this menu, Easy2Boot already checks that the 4th partition is free when it boots) and made an Easy2Boot Ubuntu.12.10.mnu file for Ubuntu as follows:


# Make a \casper-rw ext2 file using RMPrepUSB in the root of the drive (MUST be made as casper-rw)
# Rename the file to \Ubuntu1210-rw
# Place this .mnu file and the Ubuntu ISO in either \_ISO\MainMenu\Linux or \_ISO\MNU\Linux
# This menu will work even on an NTFS USB boot drive

iftitle [if exist (bd)%MFOLDER%/Linux/ubuntu-12.10-desktop-i386.iso] Ubuntu ubuntu-12.10-desktop-i386 PERSISTENT\n Boot using .mnu file with persistence
#enable parttype output
debug 1
# make empty table entry in 3rd position in ptn table
parttype (hd0,2) | set check=
debug off
set check=%check:~-5,4%
if "%check%"=="0x00" partnew (hd0,2) 0 0 0
if not "%check%"=="0x00" echo WARNING: PTN TABLE ENTRY 3 IS ALREADY IN USE - PERSISTENCE MAY NOT WORK! && pause
debug 1
if not exist (bd)/ubuntu1210-rw echo WARNING: /ubuntu1210-rw persistence file not found! && pause
errorcheck off
if "%check%"=="0x00" partnew (hd0,2) 0x0 (bd)/ubuntu1210-rw
errorcheck on
#map ptn 4 to ISO
partnew (hd0,3) 0x0 (bd)%MFOLDER%/Linux/ubuntu-12.10-desktop-i386.iso
map (bd)%MFOLDER%/Linux/ubuntu-12.10-desktop-i386.iso (0xff)
map --hook
root (0xff)
kernel /casper/vmlinuz file=/cdrom/preseed/ubuntu.seed boot=casper persistent quiet splash --
initrd /casper/initrd.lz 


This should work for most versions of Ubuntu.

For 13.04 x64 you need to load the /casper/vmlinuz.efi kernel:
iftitle [if exist (bd)%MFOLDER%/Linux/ubuntu-13.04-desktop-amd64.iso] Ubuntu 13.04 Persistent\n Boot using .mnu file with persistence - assumes we have a casper-rw ext2/3/4 partition
partnew (hd0,3) 0x0 (bd)%MFOLDER%/Linux/ubuntu-13.04-desktop-amd64.iso
map (bd)%MFOLDER%/Linux/ubuntu-13.04-desktop-amd64.iso (0xff)
map --hook
root (0xff)
kernel /casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash -- persistent
initrd /casper/initrd.lz

E2B .mnu file (using ext2 /ubuntu1304-rw file)
iftitle [if exist (bd)%MFOLDER%/Linux/ubuntu-13.04-desktop-amd64.iso] Ubuntu 13.04 PERSISTENT\n Boot using .mnu file with persistence
set ISO=%MFOLDER%/Linux/ubuntu-13.04-desktop-amd64.iso
set PF=/ubuntu1304-rw
#enable parttype output
debug 1
# make empty table entry in 3rd position in ptn table
parttype (hd0,2) | set check=
debug off
set check=%check:~-5,4%
if "%check%"=="0x00" partnew (hd0,2) 0 0 0
if not "%check%"=="0x00" echo WARNING: PTN TABLE 3 IS ALREADY IN USE - PERSISTENCE MAY NOT WORK! && pause
debug 1
if not exist (bd)%PF% echo WARNING: %PF% persistence file not found! && pause
errorcheck off
if "%check%"=="0x00" partnew (hd0,2) 0x0 (bd)%PF%
errorcheck on
#map ptn 4 to ISO
partnew (hd0,3) 0x0 (bd)%ISO%
map (bd)%ISO% (0xff)
map --hook
root (0xff)
kernel /casper/vmlinuz.efi  boot=casper persistent noeject noprompt quiet splash --
initrd /casper/initrd.lz 

Once you have booted to Ubuntu you can change the Desktop wallpaper or create a file on the Desktop and it should still be there when you reboot.

Whilst in Ubuntu, here are a few things you can try:

In the Desktop - click on your USB drive (listed in left-hand panel) to view the contents
CTRL+ALT+F1   - go to command shell
ls /media
if /media/ubuntu is not listed type:sudo mkdir /media/ubuntu  - now switch back to the Desktop GUI (ctrl+alt+F7) and can now browse your USB drive to mount it (this is a bug in the x86 liveCD!) - now press CTRL+Alt+F1 again.

ls /media/ubuntu/  - should see your USB drive listed (e.g. WDPassPort)

CTRL+ALT+F7 - return to Desktop GUI

mount -l     - lists mounted volumes

df -h   - should see /cow persistent ptn listed (doesn't mean it is working though!)

To make a new 2GB ext4 file:
cd /media/ubuntu/WDPassPort
rm casper-rw
rm casper-rw ubuntu1210-rw

dd if=/dev/zero of=casper-rw bs=1M count=2048
mkfs.ext4 -F casper-rw
mv casper-rw ubuntu1210-rw

As I am not a 'linux' user/guru and don't own any sandals (it's cold in the UK), please correct me if any of the linux commands are not accurate!

Hope you find this useful!

P.S. The latest versions of RMPrepUSB (v2.1.713 and later) will allow you to create an ext2 file with a volume name that you specify separately, so you can create in one step an ext2 file called, say, 'Ubuntu-rw' with a volume name of 'casper-rw'.