0

I have a bootable USB disk:

# dd if=/path/to/os_image.iso of=/dev/sdb
(...everything OK...)

# sudo dumpe2fs /dev/sdb
dumpe2fs 1.42.9 (4-Feb-2014)
dumpe2fs: Bad magic number in super-block while trying to open /dev/sdb
Couldn't find valid filesystem superblock.

GParted doesn't recognize any partitions (screenshot), the GUI file manager reports filesystem as isofs. The system boots and everything works fine.

The problem is, I want to use the USB disk for a live OS and as a storage with PCs and TVs which only recognize FAT32 and NTFS.

I have tried creating two partitions, doing dd on sdb1 and making sdb1 the only bootable partition, but the system didn't boot.

So my question is: how to put both FAT32/NTFS and (any) bootable ISO image on an MBR-partitioned disk without using an external bootable-usb-creator program? I would like to simply use dd, as I do now.

Presumably this could be solved using the right bootloader with the right configuration, I just don't know which bootloader and what configuration.

1

Bootable usb thumb drive with 2 partitions.

Windows and others may only see the first partition on a usb device even when there are multiple partitions. Therefore make your first primary partition the fat32 or NTFS partition so windows can see and use it.

partition 1 - ntfs or vfat

partition 2 - ext4

The second partition is where you will store the bootable iso. Use grub to load and select what live OS you want to use.

steps:

1: zero out partition table

sudo dd if=/dev/zero of=/dev/sdx bs=512 count=4

2: Create partitions (use cli “fdisk” or gui “gparted”)

create partition table "msdos"

create 2 partitions

p1 = ntfs

p2 = ext4 -- tag as bootable.

format partitions.

3: Install grub bootloader to usb device

sudo grub-install --boot-directory /mnt/usbp2/boot /dev/sdx

Verify: If these exist all is well so far...

  • /mnt/usbp2/boot/grub/fonts -- minimum unicode.pf2
  • /mnt/usbp2/boot/grub/i386-pc -- *.mod modules to load in you grub.cfg
  • /mnt/usbp2/boot/grub/local -- languages
  • /mnt/usbp2/boot/grub/grubenv -- environment variable storage

4: Create a grub.cfg file for the OS's on this pc

sudo grub-mkconfig --output=/mnt/usbp2/boot/grub/grub.cfg

Test by booting to usb

5: Copy support files to the usb

  • iso files
  • memdisk binary -- get from syslinux
  • grub.cfg -- custom for your usb stick. Overwrite grub.cfg created by grub-mkconfig

Note: each live iso may require different grub information.

Note: If you only get a grub command line, your grub.cfg probably contains errors. Go minimal to start.

6: Create your custom usb boot installer.

Copy the MBR and Partition Table

dd if=/dev/sdx of=/custom_boot/cb_mbr.img bs=512 count=1

Copy the bootable partition

dd if=/dev/sdx2 of=/custom_boot/cb_ext4.img bs=512

7: Create new bootable usb device

  • Delete all existing partitions and clean MBR

    fdisk or gparted (delete partitions)

    dd if=dev/zero of=/dev/sdx bs=512 count=1

  • restore MBR and Partition Table

    dd if=/custom_boot/cb_mbr.img of=/dev/sdx bs=512

  • Restore bootable partition

    dd if=/custom_boot/cb_ext4.img of=/dev/sdx2 bs=512

  • Fix the first partition and reformat (fat32 or ntfs)

    fdisk or gparted

My grub.cfg

My Notes

  • here is my grub.cfg I live boot gparted, "Super grub disk", Acronis" and others. – jc__ Jul 6 '16 at 15:26
  • grub-install was giving error "Attempting to install GRUB to a disk with multiple partition labels", probably because I set the label for both partitions when formatting them. Then, in GParted, I created a new table with two partitions and formatted them without setting the labels. Still the same problem. I used --force, and now I get grub console instead of a menu. In your grub.cfg I replaced your entries by mine, for which I used your PartedMagic entry and only changed iso, first argument to linux and argument to initrd. No error messages from grub at boot. Any ideas what is wrong? – kyrill Jul 7 '16 at 9:51
  • See answer for update. Note steps 4 and 5. If you have a grub command line you are almost there. – jc__ Jul 7 '16 at 17:29
  • Sorry, problem was between keyboard and chair -- a simple mistake in grub.cfg. Everything works fine now, except for the grub-install error (both partitions are always called "CDROM", even after e2label /dev/sdc2 '' and fatlabel /dev/sdc1 ''), but with --force, it installs. Thanks. – kyrill Jul 7 '16 at 22:46
0

To make this explicit -

  • "I would like to simply use dd, as I do now."
  • "Windows and others may only see the first partition on a usb device even when there are multiple partitions."

I don't think these goals are practical to achieve, so you will have to compromise somewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.