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

13 comments:

  1. I tried to boot Ubuntu 13.04 x64 from my multibootstick but it doesn't work. I found no other help so hopefully you can help me. I don't need persistence.

    Here is my menu.lst entry:

    title Ubuntu 13.04 x64
    find --set-root /images/ubuntu-13.04-desktop-amd64.iso
    map /images/ubuntu-13.04-desktop-amd64.iso (0xff) || map --mem /images/ubuntu-13.04-desktop-amd64.iso (0xff)
    map --hook
    root (0xff)
    kernel /casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed noprompt boot=casper iso-scan/filename=/images/ubuntu-13.04-desktop-amd64.iso quiet splash locale=de_DE.UTF-8 --
    initrd /casper/initrd.lz

    What should I change? Ubuntu loads but gets stuck in the beginning of the boot process.

    ReplyDelete
  2. Is your USB boot device NTFS by any chance?

    ReplyDelete
  3. I just tested the ISO both on a FAT32 and NTFS drive - both worked fine using your exact menu (except I used /_ISO/MAINMENU instead of /images.
    Are you sure that the path and filename is correct (i.e. all lowercase)?

    ReplyDelete
    Replies
    1. Thanks for your reply. On my notebook it worked fine. But another try on my PC shows the same problem. Is it possible that secure boot or another UEFI setting is causing the problem?

      Delete
  4. Here is the menu I used in both cases:
    title Ubuntu 13.04 x64
    map /_ISO/MAINMENU/ubuntu-13.04-desktop-amd64.iso (0xff) || map --mem /images/ubuntu-13.04-desktop-amd64.iso (0xff)
    map --hook
    root (0xff)
    kernel /casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed noprompt boot=casper iso-scan/filename=/_ISO/MAINMENU/ubuntu-13.04-desktop-amd64.iso quiet splash locale=de_DE.UTF-8 --
    initrd /casper/initrd.lz


    Of course, if you made an Easy2Boot USB drive, all you need to do is copy the ISO file and it would just work - you wouldn't need any menu!

    ReplyDelete
  5. Well it is difficult to know what the problem is from your description of 'it doesn't work' - since it does work on a notebook, can you describe what happens in detail?
    To boot to grub4dos yout BIOS must be in non-UEFI mode.

    ReplyDelete
    Replies
    1. I downloaded the ISO again, put in on my USB drive and now it worked without a flaw. Don't know the cause of my problem but thank you very much for you help!

      Delete
  6. HI
    Usb FLASH 4Gb Fat32
    ubuntu-13.04

    if i use casper-rw on root of of it - persistent exists
    menu.lst:
    =========
    title Ubuntu-13.04-desktop-i386 PERSISTENT

    partnew (hd0,3) 0x0 /ISO/ubuntu-13.04-desktop-i386.iso
    map /ISO/ubuntu-13.04-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
    =========

    if i rename "casper-rw" to "pers" and trying to boot as described below - persistent does not exist
    menu.lst:
    =========
    title Ubuntu-13.04-desktop-i386 PERSISTENT
    partnew (hd0,2) 0x0 /pers
    partnew (hd0,3) 0x0 /ISO/ubuntu-13.04-desktop-i386.iso
    map /ISO/ubuntu-13.04-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
    =========

    what i must to do or check?
    casper-rw is not fragmented

    ReplyDelete
  7. Use RMPrepUSB - DriveInfo - 0 - see if partitions are present in partition table.
    Type mount under Ubuntu to see if casper-rw is mounted.
    Check grldr version is 2013 version.

    ReplyDelete
  8. Hi Steve
    easy2boot is wonderful sw, thank you
    I have some questions, I seldom boot windows, trying to do it all in linux
    Is volume name the same as label, ie (in linux) dosfslabel?
    Is it an artifact of the bloging sw, are these all supposed to be 1 line?
    partnew (hd0,3) 0x0 (bd)%MFOLDER%/Linux/ubuntu-12.10-desktop-i386.iso
    and
    if "%check%"=="0x00" partnew (hd0,2) 0x0 (bd)/ubuntu1210-rw
    Is this how assignment is done?
    Konqueror web browser really hates blogspot, crashes quickly (using FF now)
    thanks
    dave

    ReplyDelete
  9. Hi
    Yes. those are one line each. If you cut and paste the code into Notepad, you should see what is all one line and what is not.

    If you make an ext2 file using RMPrepUSB, then it makes the volume name the same as the filename. This is just the way that RMPrepUSB does it because I use the command
    mke2fs.exe -L persistence H:\persistence
    and so I always set the volume label to the same name as the filename. RMPrepUSB does not prompt for the volume label, it just uses the same name as the filename.
    I guess I could change RMPrepUSB so that it prompts for the volume label? Then you would not have to rename the file afterwards...

    If you read some of my tutorials on my site, it explains about partnew.
    cheers
    Steve

    ReplyDelete