Live USB on a 2-partition usb-drive

Yes, you can partition a USB flash drive to boot into a Ubuntu Live Session and use it as a regular USB drive (accessable to windows) on separate partitions. I was able to do this with a 32GB PNY USB 2.0 flash drive on a Sony Vaio T Series Ultrabook laptop with UEFI and Windows 8.0 installed. I also tested this from Ubuntu server 12.04 on my 16TB RAID5 i7-290 server.

I partitioned the USB flash drive using GParted in this configuration:

32GB USB Flash Drive GParted

sdh1 is the "Storage" partition that's accessible from Windows. sdh2 is the Ubuntu desktop 12.04 boot-able partition. These were my steps:

 1. Created a new 10 GB, ntfs, logical partition, with 25 MB Free space preceding 
and 0 MB following, labeled Storage (must be first on the drive) 2. Created a new 5 GB, fat32, logical partition, with 0 MB preceding and following 3. Set a boot flag for the second partition 4. (Created the other partitions which are not needed) 5. Booted to a Ubuntu Live Session loaded on a DVD and selected Try Ubuntu
without installing from the GRUB menu 6. Opened Startup Disk Creator with the USB flash drive pluged-in 7. The Ubuntu-Desktop 12.04 Image and pny USB 2.0 flash drive (/dev/sdh2) 5.0 GB
partition were already selected, moved the How much slide to store documents
and settings in reserved extra space and selected Make Startup Disk

Without selecting the boot flag, the Startup Disk Creator would only recognize the entire flash drive as /dev/sdh, instead of the desired second partition /dev/sdh2.

Without putting the Windows partition first, the Removable Media Bit...

"The removable media device setting is a flag contained within the SCSI Inquiry Data 
response to the SCSI Inquiry command. Bit 7 of byte 1 (indexed from 0) is the
Removable Media Bit (RMB). An RMB set to zero indicates that the device is not a
removable media device. An RMB of one indicates that the device is a removable
media device. Drivers obtain this information by using the StorageDeviceProperty
request."

...would mean only 1 partition shows up in Windows:

"Q. What is a superfloppy?

A.  
Removable media without either GPT or MBR formatting is considered a "superfloppy." 
The entire media is treated as a single partition.
The media manufacturer performs any MBR partitioning of removable media. If the
media does have an MBR, only one partition is supported. There is little
user-discernible difference between MBR-partitioned media and superfloppies.
Examples of removable media include floppy disk drives, JAZ disk cartridges,
magneto-optical media, DVD-ROM, and CD-ROM. Hard disk drives on external buses
such as SCSI or IEEE 1394 are not considered removable."

Here are some tools that flip the RMB (which is unnecessary in this case):
Laxar's USB Format Tool
Bootice
RMPrepUSB

These are software approaches (again unnecessary in this case):
Create a dummy.sys Driver
Use the Hitachi Microdrive Filterdriver

Credit:
TSJNachos117 Live USB on a 2-partition usb-drive
http://ubuntuforums.org/showthread.php?t=1020293
https://stackoverflow.com/questions/2598502/howto-flip-removable-bit-on-usb-drive-in-c
http://www.rmprepusb.com/tutorials/multipartufd


I found an alternative way which is more straightforward. There are 2 important pieces of information one needs to understand about why this works. The first is about the boot process and how the initial power on self test (executed by the BIOS) looks for a boot record on the first boot sector of the devices attached. This is a small file which basically passes the boot execution process onto the boot loader/manager such as GRUB2 on newer Linux installs. For more information on this, read this very informative post.

The 2nd piece of information is to understand that the ISO downloads for Linux OSes are designed to be installed on a disk (CD/DVD/USB) and not for a partition. These ISOs need to be modified using a small tool which can be found on the syslinux-utils package, called isohybrid. The ISO modification for installation on a partition is done with the --partok flag. I found this information from this post which describes the exact same issue. I am not sure how the --partok magic works, I searched for some explanation but could not find any.

In summary, here is what I did to get my live PureOS install to boot from a usb partition,

  1. Partitioned my USB using GNOME disk, I initially formatted the disk using MBR/DOS. I created a 4GB partition (FAT32) followed by a an ext4 Linux partition in the remaining space for my backups.

  2. Next I modified the ISO file I downloaded to make it bootable from the partition. To do this I had to install the syslinux-utils from the repositories, in which the isohybrid tool resides:

    sudo apt-get install syslinux-utils
    

    I then modified the ISO file with:

    isohybrid --partok pureos.ISO
    
  3. I used dd to copy this ISO to the above partition. You can get the partition device from the GNOME disk details.

    dd if=pureos.ISO of=/dev/sdb1 bs=1M
    
  4. From GNOME disk I edited the partition and checked the bootable option, which installs the required book record.

I was now able to boot from the USB key into the live CD and use it as a recovery solution while storing my system backups on the other partition.


This should be easy to do. However, be warned in advance that Windows will only be able to see the first partition (/dev/sdb1), the second partition will be invisible (I don't know why). Therefore, I would recommend the general-purpose storage partition be the first one, and the LiveUSB partition be the second one.

If after doing this, you can't get the key to boot, you should be able to set the Boot flag using GParted.

Please note: although I've successfully done this before, I've never tested doing something like this on a UEFI-based system, let alone something that uses Secure Boot.