Ubuntu – Multi-partition USB stick

partitioningUbuntuusb

In my freelance job as "the dude that fixes your computer" I have an extremely handy tool, a bootable USB stick with Ubuntu LiveCD that allows me to recover and investigate in a known, working environment.

Now, I want to reformat this USB stick and reinstall with Casper-RW persistance. I did this a few times before with a FAT-formatted USB stick. It was a horror. The USB drive corrupted constantly, by people accidently removing the USB stick, the computer not properly shutting down, ETC.

Now what I want to create a multi-partition USB stick so I can put Ubuntu on a ext partition, but still be able to store some Windows stuff in it, by having a secondary FAT partition.

However I read somewhere that Windows will only check the first partition on USB sticks, giving a problem with the first bootable linux partition.

Is this possible on some way?

EDIT

Perhaps it wasn't clear what the problem is. The problem is that I read somewhere that Windows will only recognize the first partition on a USB stick. But I want two partitions, a ext partition and a FAT partition. No issues so far, but in order to be bootable the ext partition must be the first one!

Best Answer

You can do what you want very easily.

Assumming only a two partition setup, you have to make the FAT partition your first primary partition (it has to be in the same order in the partition table and on the disk, it's usually the case, but strange things happen in Windows if you don't).

On your EXT partition install Ubuntu.

On the MBR install grub as following (I assume you already have a linux machine and grub2 working on it and that your pendrive is detected as /dev/sdb):

mount -t ext2 /dev/sdb2 /mnt
grub-install  --no-floppy --root-directory=/mnt/ /dev/sdb

This will setup grub on mbr and install all necessary files on your ubuntu partition. Next you need to setup your grub.cfg with a menuentry as follows (read grub2 documentation or the grub.cfg on your linux pc to build a full grub.cfg):

menuentry 'Ubuntu, con Linux 3.2.0-39-generic-pae' --class ubuntu --class gnu-linux --class gnu --class os {
        insmod gzio
        insmod part_msdos
        insmod ext2
        set root='(hd1,msdos2)'
        search --no-floppy --fs-uuid --set=root UBUNTU_PARTITION_UUID
        linux   /boot/vmlinuz-3.2.0-39-generic-pae root=UBUNTU_PARTITION_UUID ro   quiet nosplash
        initrd  /boot/initrd.img-3.2.0-39-generic-pae
}

You need your partition UUID for this to work on computer with more than one disk:

# blkid /dev/sdb2
/dev/sdb2: LABEL="GPART" UUID="75cdfe28-0ad8-4f0a-8c1d-9af6b2a5ba88" TYPE="ext2"

I'll leave it up to you to find out how to add a second entry for memtest86+, which is perfect for this kind of rescue flash drive.

Related Question