I Have a 16GB USB drive. I found out that multiple partitions on USB drives are possible. I need to make two partitions, one that contains Linux OS and the other one for storing files. A system like any other system (An OS Partition with different file storage partition). I want the storage partition to be accessible by Windows, which means that the storage partition should come before the OS partition in USB. The problem is, when storage partition is before the OS partition, the OS partition is useless and BIOS can't detect an OS if I select USB on boot. I think installing GRUB may solve problems but 'install-grub' throws errors.
1 Answer
Bootable usb thumb drive with 2 (or more) partitions, and windows to access the data partition.
Edit: This example uses an ISO instead of an installed OS. It should be simple to adjust for an installed OS.
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
- partition 3 - linux swap
The second partition is where you will store the bootable iso, or the installed OS. Use grub to load and select what OS you want to use.
Steps:
1: Zero out partition table on the USB device.
dd if=/dev/zero of=/dev/sdx bs=512 count=4
2: Create partitions (use cli "fdisk" or gui "gparted")
Create partition table "msdos" type.
Create Partitions.
Format partitions.
3: Install grub bootloader to usb device.
Mount ext partition on USB to PC. mount /dev/sdx2 /mnt/usbp2
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 the host pc.
sudo grub-mkconfig --output=/mnt/usbp2/boot/grub/grub.cfg
Test by booting to usb.
When you boot the USB drive you should get a list of the OS that was on the host PC not the empty USB, but this will test the grub and grub config that is on the USB.
5: Copy support files to the USB.
iso files
installed OS image from clonezilla or the like.
memdisk binary -- get from syslinux
6: Edit the grub.cfg on the USB for your ISOs and installed OS.
Each live ISO may require different grub information.
If you only get a grub command line, your grub.cfg probably contains errors. Go minimal to start like a single ISO.
Example grub.cfg for free live distro PartedMagic and others.
- I must create 3 partitions within an extended partition, is that okay?Notagenericmember– Notagenericmember2017-07-13 15:42:17 +00:00Commented Jul 13, 2017 at 15:42
- As long as the first is a primary, i think, yes its okay.jc__– jc__2017-07-13 15:43:36 +00:00Commented Jul 13, 2017 at 15:43
- Everything is within an Extended partition. Where to copy the support files?ext4 partition?Notagenericmember– Notagenericmember2017-07-13 15:56:44 +00:00Commented Jul 13, 2017 at 15:56
- I booted by USB before copying iso support files, it is going into grub's shell, no OS options.Notagenericmember– Notagenericmember2017-07-13 16:05:22 +00:00Commented Jul 13, 2017 at 16:05
-
/boot/grub.cfgmust exist on the partition tagged as bootable, ext3 partition.jc__– jc__2017-07-13 16:07:28 +00:00Commented Jul 13, 2017 at 16:07