1

I would like to engineer a USB stick partitioned such that it contains several Linux systems (and not Live versions). In particular, I would like to have at least two different versions of Fedora on the same USB stick, Fedora 24 for 64-bit arch and Fedora 8 for 32-bit arch. My intent is to replicate the environments of machines I need to work with for my job without consuming space on my laptop (via another partition or a virtual machine) and to be able to boot my OSes just by plugging my USB stick into my laptop.

So far, I managed to install a working Fedora 24 on a 32 Go USB Stick, along with GRUB2 which lets me choose between booting Fedora 24 and booting one of the OSes of my laptop. Both uses two partitions of respectively 10,01 Gio and 500 Mio, leaving at bit less than 20 Go of unallocated space I intend to use for other Linux distributions. To give you a better preview of the current state of my USB stick, here is what I see when reading my USB stick with GParted:

GParted display

The problem is that I don't know how I can safely add Fedora 8 on the USB stick while updating GRUB2 such that I can select Fedora 8 in my boot menu when my USB stick is plugged in (especially since, as I recall, Fedora 8 is slightly older than GRUB2). In particular, I have the following questions:

  • Is it safe to eventually resize down the partition where my Fedora 24 is located to make room for more OSes (in the future) ?
  • What general procedure should I follow to create a new partition on my USB stick and install on it a new OS that is not a Live version (note that I can use a second USB stick with a Live equivalent if necessary) ?
  • How can I update the GRUB2 located on my USB stick to feature the new OS in the list ?

Thank you in advance for your answers.

9
  • This answer may help. Commented Apr 2, 2018 at 14:15
  • Must you use LVM or can you use MBR partitions? Commented Apr 2, 2018 at 14:29
  • If you could use MBR partitions, use clonezilla to clone an OS to the partitions you create. You may want a swap partition for each OS on a swap file that lives in the OS partition. Commented Apr 2, 2018 at 14:34
  • "How can I update the GRUB2 located on my USB stick to feature the new OS in the list?" What device do you need to boot from? The laptop or the USB stick. This answer determines where you install the grub config file. Commented Apr 2, 2018 at 14:55
  • "What general procedure should I follow to create a new partition on my USB stick and install on it a new OS that is not a Live version (note that I can use a second USB stick with a Live equivalent if necessary)?" Will you make a new install the the OS, example in a virtual machine, or does the OS already exist somewhere? If you will install a new OS on a virtual machine, you can then clone it with clonezilla, then restore the clone to the USB stick. NOTE: watch the partitions on the clone/restore /sda1 /sda2 ... Commented Apr 2, 2018 at 14:55

4 Answers 4

1

How can I install several Linux distributions on a USB stick?

Assume:

  • BIOS boot from USB drive
  • MBR Partitions
  • GRUB boot loader

Tools:

Overview:

  • Zero out the partition table and boot record of the USB drive
  • Create Partitions on USB drive
  • Create OSs for USB drive in a virtual machine
  • Clone New OSs with clonezilla
  • Restore OSs to USB drive
  • Update and customize GRUB2

Step 1

Get tools ready and determine what OSs to put on USB and what size partitions and if swap partition will be used.

Your USB looks to be 32GB total.

Partitions we will setup.

NTFS 16GB partiton for Microsoft interoperatiblty.

Ubuntu14 32bit server 4GB ext4 with 1GB swap partition

Ubuntu16 64bit server 8GB ext4 with 4GB swap partition

NOTE: If you do not use stand by or hibernate on any of the OSs, they could share a single swap partition, or even use a swap file in each of the OS partitons.

Partition Layout:

  • P1 -- 15GB NTFS
  • P2 -- 4GB ext4
  • P3 -- 8GB ext4
  • P4 -- extended
  • E1 -- 4GB swap
  • E2 -- 1GB swap

NOTE: BIOS and MBR will only see 4 primary partitions. Use an extended partition in place of a single primary partition to overcome this limit.


Step 2

Prepare USB drive.

Create a new Virtual Machine named "test" No hard drive required or wanted for this VM. This should make the USB drive /dev/sda. This will make it simpler later.

Connect the Parted Magic ISO to the VM and boot to the ISO.

Connect USB drive and 'pass to the VM'

Verify USB visible in VM and note device number.

Start Partition Editor from desktop icon.

The USB drive in my setup is: /dev/sda

Zero out partition table. This will delete ALL info on this device. Copy any data you want to keep first.

  • MUST have the correct device (example: /dev/sda) because you can make your computer unbootable if you zero out the wrong device.
  • dd if=/dev/zero of=/dev/sda bs=512 count=4

Refresh the drive list in GParted (ctrl+R)

device --> create partition table "msdos"

Create partitions:

NOTE: I created the NTFS partition last to 'use up' the remaining space.

  • Create Extended Partition at the back end of the space. 5GB or 5120
  • Create both swap partition in the Extended Partition. Type linux-swap. 4GB, 1GB. Extended Partition will be full.
  • Create the 2 OS partitions at the end of the unallocated space. Type ext4. 4GB, 8GB.
  • Label the 4GB 'Ubuntu14' (label will change on restore, this helps in identification)
  • Label the 8GB 'Ubuntu16' (label will change on restore, this helps in identification)
  • Create the NTFS data partition using the remaining unalocated space at the beginning of the drive. Type NTFS.
  • Label the NTFS 'data'

Apply changes. Should look something close to this. Note my USB drive is 1TB so my NTFS partition is much larger. GParted Screen shot


Step 3

Prepare the OSs that will be restored to the USB drive.

Created new Virtual Machine and install your OS. Ubuntu14 server 32bit in this example. I made the VM install drive smaller than the partition size on the USB. 4GB. During installation I used MBR not LVM and let the install create a swap partition.

Created new Virtual Machine and install your other OS. Ubuntu16 server 64bit in this example. I made the VM install drive smaller than the partition size on the USB. 8GB. During installation I used MBR not LVM and let the install create a swap partition.

Make any changes, updates, installs you want to each of the OSs.

Shutdown the new VMs

Start clone of new VMs.

Attach the pmagic_2013_08_01.iso to each of the new VM and boot from the ISO.

Look at the partitions on each VM. Note the location of the installed OS. Both should be /dev/sda1. (If not make adjustments later)

Now clone each OS using clonezilla from the desktop icon. I will place my cloned images on my desktop via ssh, so setup network before starting clonezilla.

Clonezilla options:

  • device-image -- cloning device /dev/sda1 to an image
  • ssh_server -- placing the image on my desktop. Place yours where ever you can get to it.
  • Beginner mode -- most defaults will work
  • saveparts -- we only want the OS partition.
  • give the image a name you will reconize later.
  • sda1 -- select the OS partition. Should only be one choice, but may not.
  • skip checking/repairing source file system -- The VM should all be clean and ready
  • Yes, check the saved image -- verify that the clone image is a good file. follow prompts.
  • wait.
  • Finished! -- poweroff is fine at this point.

Step 4

Restore OS images to the USB drive.

Go back to the 'test' VM that does not have a virtual drive attached and boot from pmagic_2013_08_01.iso.

Pass the USB drive to the 'test' VM.

Start the partition editor from the desktop icon. We are back here. See the Screenshot.

Match up the OS with the USB partitions to the image partitions.

Ubuntu14:

  • image partition -- /dev/sda1
  • USB partition -- /dev/sda3

Ubuntu16:

  • image partition -- /dev/sda1
  • USB partition -- /dev/sda2

NOTE: This version of clonezilla by default will restore the image to the same partition it was made from. /dev/sda1 to /dev/sda1. Not what we want, so this hack will get the images restored to the USB partitions.

clonezilla hack to restore image to a different partition it was cloned from:

Rename all files in the image directory with the new partition id.

/home/jc/clonezilla_images/ubuntu14/sda1* to /home/jc/clonezilla_images/ubuntu14/sda3*

Modify the content of file /home/jc/clonezilla_images/ubuntu14/parts. Replace 'sda1' with 'sda3'

Same for Ubuntu16, adjust numbers sda2.

NOTE: I started from device sda on both the VM and USB. If yours uses another device somewhere like /dev/sdb changes to more files required. Its just simpler to start with both on the same device. /dev/sda.

Restore images to the USB drive via clonezilla

Clonezilla options:

  • device-image -- restoring device /dev/sda1 from an image
  • ssh_server -- Or where ever you put the image.
  • Beginner mode -- most defaults will work
  • restoreparts -- restoring a single partition
  • select image to restore
  • select the correct USB partition for the image -- Ubuntu14 to sda3; Ubuntu16 to sda2
  • follow prompts.
  • wait.
  • Enter command line prompt. -- Still have more images to restore

Restart clonezilla and repeat for all images.

My USB unmounted from the VM between restores so had to pass through the USB drive again.


Step 5

Install GRUB to USB drive

The Grub boot loader will be installed to the first 512 bytes of the USB drive. This loader will point to a grub.cfg file. Lets place ours on the Ubuntu16 partition. Its can be anywhere grub can read.

We will use our host OS to do this.

You could use a live OS in a VM to accomplish this.

Should be using a current linux OS with grub2.

Attach USB.

My USB drive is currently mounted as device /dev/sdf. Yours will differ.

Mount the partition the grub.cfg will live in.

NOTE: Each restored OS will have a grub.cfg file in it because it was a bootable OS in the VM. Verify you are pointing to and modifying the grub.cfg that USB boot loader is pointing to.

Ubuntu16 ext4

sudo mount /dev/sdf2 /media/usb_u16

install grub bootloader to usb device

sudo grub-install --recheck --boot-directory=/media/usb_u16/boot /dev/sdf

This will place the config file pointer to the Ubuntu16 partition boot directory. Common location for Ubuntu. Yours can be anywhere.

Installation finished. No error reported.

Create a grub.cfg file to work from as a template.

sudo grub-mkconfig --output=/media/usb_u16/boot/grub/grub.cfg

The important thing here is that grub-mkconfig will probe the USB drive and create boot entries for the OSs we installed on the USB drive. The part we do not want is it will also probe any installed drives on the host machine and create entries for these as well.

Now unmount everything and test USB boot.

If everything works you should be able to boot to the USB OSs. If not go back...


Step 6 Customize grub.cfg on the USB drive

When you boot this USB drive you will see the OSs on the host PC even if the USB boots on another PC. Lets fix this.

Lets gather some more info.

Each partition has an UUID number assigned to it. Get the UUIDs for our USB drive.

blkid

/dev/sdf2: UUID="078ecc53-f73c-4cc7-9d45-f78aa534b7c5" TYPE="ext4" PARTUUID="00005785-02" /dev/sdf3: UUID="a4654333-ee62-4dac-8c09-79a034e3125d" TYPE="ext4" PARTUUID="00005785-03" /dev/sdf4: LABEL="data" UUID="667308CA28B6BB86" TYPE="ntfs" PARTUUID="00005785-04" /dev/sdf5: UUID="8646e3f8-4f5c-40d4-a409-c4d65bf98d21" TYPE="swap" PARTUUID="00005785-05" /dev/sdf6: UUID="61b8680c-22c9-4efc-98a1-2aaaa4a7f304" TYPE="swap" PARTUUID="00005785-06" 

Yours will differ.

The 2 swap partition UUIDs save for later. You will add these to the /etc/fstab file to auto mount on boot.

The 2 OS partition UUIDs:

/dev/sdf2: UUID="078ecc53-f73c-4cc7-9d45-f78aa534b7c5" -- Ubuntu16 /dev/sdf3: UUID="a4654333-ee62-4dac-8c09-79a034e3125d" -- Ubuntu14 

Copy the 2 files memdisk and super_grub2_disk_hybrid_2.02s9.iso to the grub config directory, and splash.jpg image if you have one.

Ubuntu16 ext4

sudo mount /dev/sdf2 /media/usb_u16

sudo cp ./memdisk /media/usb_u16/boot

sudo cp ./super_grub2_disk_hybrid_2.02s9.iso /media/usb_u16/boot

sudo cp ./splash.jpg /media/usb_u16/boot

Create a backup copy of the created grub.cfg

sudo mv /media/usb_u16/boot/grub/grub.cfg /media/usb_u16/boot/grub/grub.cfg.orginal

Create our custom grub.cfg

sudo vi /media/usb_u16/boot/grub/grub.cfg

In short we need to copy from grub.cfg.orginal just the bare minimum. The grub setup stuff insmod..., the display stuff gfxmode=..., and the boot entries. The boot entries can be found by searching for the UUID numbers from above. Copy all including the sub-menu entries or just the main entry.

The memdisk and the super_grub2_disk_hybrid_2.02s9.iso will allow us to boot from any OS on the host machine even when the boot entries do not exist.

There are many reasons why this is not the right way to do it, but it works.

Modify the Example grub.cfg for this USB drive.

Make a backup of you custom grub.cfg file because something will try to overwrite it.

sudo cp /media/usb_u16/boot/grub/grub.cfg /media/usb_u16/boot/grub/grub.cfg.custom


Step 7

Adjust the installed OSs

  • Add the swap partition UUID to/etc/fstab
  • Add any auto mount partitions (NTFS data, the other OS ext4) on the USB to /etc/fstab
  • On Ubuntu I would adjust the default grub entries with my changes so when the OS is updayed the changes will propagate to the new grub menu.

Test it!

4
  • Thank you for the extensive answer! I will try it soon and provide you a feedback. Commented Apr 4, 2018 at 9:54
  • Hello, I followed your tutorial up to Step 5 (included). It seemed to work at first because I indeed got the GRUB with Fedora 8 and Fedora 24 correctly listed (+ 2 options left by Fedora 24's default installation), however neither of those will successfully boot for now, as shown in the following captures (sorry for quality, I used my mobile phone): Fedora 8, Fedora 24. However, strangely, I can still boot Fedora 24 using the options provided by the default install. Did I restore my partitions wrong or can I "rescue" both OSes ? Commented Apr 5, 2018 at 10:37
  • To provide more details (I fear my previous comment isn't enough), here is another picture showing my boot menu. The 2 first options no longer work (these were created at Fedora 24 installation in my virtual machine). Other options lead to the cases I showed in my previous comment, except for the Fedora 24 rescue (selected via 4th item in the menu) which boots normally. I also provide you my grub.cfg (which I placed in the Fedora 24 partition, so /dev/sda2/ when booting from USB, FC8 is /dev/sda3/). Commented Apr 5, 2018 at 14:16
  • Finally, I think it's worth noting I did Step 5 in a VM (with 2 Go of RAM) rather than the host computer. However, trying to boot from my USB stick in the same VM leads to the exact same issues. Commented Apr 5, 2018 at 14:19
1

A few pieces of advice and comments on jc__'s tutorial

First of all, many thanks to jc__ (again) for posting his tutorial on how you can achieve the goal stated in my initial post. I can confirm the method works, despite that you might have to do some additional troubleshooting when the time to boot the installed OSes comes, which is why I am making this reply to enumerate a few things you might want to consider while following the tutorial.

0. If you pick older distributions, carefully check you can boot them at all

I learned the hard way that Fedora 8 is too old to boot on more recent hardware such as my current laptop (for reminders, Fedora 8 was released around 2007; my laptop was built in the 2010s). I don't recall the exact details (as I learned this thanks to one of my colleagues), but it seems the kernel has trouble dealing with my hardware and is unable to properly mount everything, which is why I eventually dropped Fedora 8 for Fedora 14 (which works fine).

But how can you check if a distribution will boot properly on your machine ? A simple approach consists in booting from USB with a Live version of the target distribution. If everything boots normally with the Live version, then you should have no trouble installing the distribution through a VM, cloning its partition on your USB stick and boot it from the USB.

In my case, I used YUMI - Multiboot USB Creator to test multiple Live versions of older Fedora releases on my laptop. Of course, this advice only applies if you need, like me, to use older distributions.

1. Consider using FAT32 or ext3/ext4 for the data partition

At some point, my Ubuntu 16.04 had trouble dealing with the data partition when it was formatted in NTFS. Eventually, I re-formatted it as FAT32 - an older format with which any Linux distribution should be okay. ext3/ext4 should be okay too if you exclusively use Linux (as far as I know, Windows cannot deal with these filesystems), though I haven't tested it myself.

I now use the data partition as a way to easily share data between the OSes on the USB and the OSes on the host computer.

2. Consider using a secondary USB stick for partition cloning

Having a second USB stick can be very practical for the first steps, as you can use it to store the images produced by clonezilla. When clonezilla ask you where you will put the /home/partimag/ folder, select the first option in the menu (just above ssh_server) while not having your second USB stick plugged into your machine, then plug it, wait around 5 seconds and press Enter, then select your second USB stick when clonezilla enumerates your options for the /home/partimag/ folder. The subsequent operations will be identical to those enumerated by jc__.

This approach does not - of course - change the outcome and has the merit of not involving your host computer at all with the partitioning of the USB stick and the cloning/restoration of the partitions where the target OSes are located. You can try this if you are unsure about toying around with disk partitioning.

3. If booting your USB OS fails after loading kernel, rebuild initrd/initramfs image

Depending on the target OSes, you might run into issues similar to those I presented in some comments of this topic, such as having timeout with queues in dracut while booting Fedora 24.

In my case, except for the particular case of Fedora 8 (cf. item 0), I fixed the problem by rebuilding the initrd image. Depending on your distribution and how recent it is, this image can also be prefixed by initramfs rather than initrd. No matter the name, the purpose of the file is the same: having a transient filesystem at boot time before mouting the actual filesystem. If this file is corrupted, erroneous or missing, you cannot properly boot your system.

Hopefully, any Linux distribution comes with an utility to rebuild this image. From my (short) experience:

  • Older distributions: mkinitrd
  • Recent Ubuntu distributions: mkinitramfs
  • Recent Fedora distributions: dracut

NOTE: when (re-)building the image, each utility will take the /etc/fstab file into account. Take advantage of this to already link a swap partition with your USB OS. In /etc/fstab, you can use an UUID to denote a partition, so use fdisk and blkid to get the UUID of the desired swap partition and update the /etc/fstab accordingly.

To use one of the three commands I listed to rebuild the image, you need first to chroot into the OS which you want to rebuild the initrd/initramfs image. I basically follow the same approach as in this tutorial, which consists in mounting the partition of the buggy OS (so, one of our USB OSes) on your host computer and using a few binding commands to properly chroot in it. You can create sub-folders in your /mnt folder if needed. In my case, to chroot into my Fedora 14, I used the following commands:

sudo mkdir /mnt/usb_f14 sudo mount /dev/sdb3 /mnt/usb_f14 sudo mount --bind /proc /mnt/usb_f14/proc sudo mount --bind /dev /mnt/usb_f14/dev sudo mount --bind /sys /mnt/usb_f14/sys sudo chroot /mnt/usb_f14 

Don't forget to check beforehand what /dev/sdX your partition is with fdisk. Once you are rooted in your USB OS, move to the /boot folder. If you wish to, rename the already present image (if any) to keep it (you can simply prefix it with old-, for instance) before you create the new image. Then, run

ls /lib/modules/ 

This will list the different kernels you have on your USB OS (most of the time, you should have only one). Indeed, any of the command I listed above requires you to give the kernel you will use to build the image. Then, depending on the utility you have access to, you should run one of the three following commands (by my-kernel, I denote one of the kernels listed by ls /lib/modules/; note that you can use other names for your images if you wish)

  • mkinitrd initrd-my-kernel.img my-kernel
  • mkinitramfs -o initramfs-my-kernel.img my-kernel
  • dracut initramfs-my-kernel.img my-kernel

Depending on your OS, there might be some messages about missing modules. As long as the image is produced, you can ignore them (I got some while rebuilding the image for my Fedora 14, and it still boots fine).

Note, also, that if you directly replace the old image, you might have to add a flag to your command to force the overwriting. For instance, with dracut, you should add --force. Refer to your manual for the other commands. Once you are done, unmount your USB OS partition and reboot your machine with the boot sequence set to boot from USB first. Your USB OS should now boot normally.

Finally, don't forget to take note of the name you gave to the new image, if different from the name of the initial image, because you will need to update your grub.cfg file to take the new image into account.

4. Double-check the partitions on the virtual machines

If you couldn't choose yourself the partitioning when installing one of your target OSes in a virtual machine (it happened to me with Fedora 14), it is possible you end up with two ext4 partitions, with a small one containing the /boot folder and the other containing the rest of the filesystem. If this happens, clone the larger partition with the method described by jc__, then boot again your virtual machine, copy somewhere (e.g., on secondary USB stick) the /boot folder and later place it in the partition you cloned after restoring it. Don't forget to update the /etc/fstab file afterwards before re-building the initrd image (see 3), as the original file will likely still list two ext4 partitions instead of one.

5. Exiting your USB GRUB, the easy way

While jc__ recommends to use super_grub2_disk_hybrid_2.02s9.iso and memdisk to get all the options on the host machine, you can also just add this simple menu entry in your grub.cfg:

menuentry 'Continue to host machine' { exit } 

This will make GRUB on the USB stick quit and resume the boot sequence of the host machine. In my case, since my host computer is a laptop with dual boot, I get the GRUB menu of my machine right after selecting this menu item.

That's about it for the comments I wanted to make. Since I don't have a lot of experience with Linux troubleshooting, don't hesitate to comment this post to point errors or inaccurate statements.

1
  • Thanks for the extra info. This should help someone else. A+ Commented Apr 13, 2018 at 17:08
0

Placing this in an answer spot because it is long and wordy. If answer corrections needed or additions will edit answer and delete this.

"grub.cfg (which I placed in the Fedora 24 partition, so /dev/sda2/"

"FC24 is /dev/sda2"

"FC8 is /dev/sda3"

Okay lets do some things to help with trouble shooting.

show the partition layout of the USB

GParted gui or sudo fdisk -l

show the UUID numbers of the USB partitions blkid

show the command used when installing grub.grub-install and grub-mkimage

On the VM used in step 5, did it boot from a hard grive (VHD) or a live OS. What OS was used.

"Did I restore my partitions wrong or can I "rescue" both OSes ?"

I don't think it is a restore issue, but a grub install issue.

Looking at the grub.cfg.

Entry: Fedora (4.5.5-300.fc24.x86_64) 24 (Workstation Edition) search ... --hint='hd0,msdos1' 913f30c2-4a22-44eb-a93d-9fad95764f5d first HD and first partition. --hint='hd0,msdos1 partition UUID 913f30c2-4a22-44eb-a93d-9fad95764f5d This tells us: /dev/sda1 and was probably the HD not USB. Expected. Entry: Fedora release 24 (Twenty Four) (on /dev/sda2) search ... --hint-bios=hd0,msdos2 d4be737a-c4ea-44cd-a22d-781086854ec8 first HD and second partition --hint-bios=hd0,msdos2 partition UUID d4be737a-c4ea-44cd-a22d-781086854ec8 This tells us: /dev/sda2 and is the second partition on the HD not USB. Not expected if this OS is on the USB. Expecting second HD (the USB) NOT the same as the booted OS. Perhaps /dev/sdb2 Entry: Fedora release 8 (Werewolf) (on /dev/sda3) search ... --hint-bios=hd0,msdos3 8bc6e37c-53b1-4fe9-b242-5b0b9c8c575e first HD and 3rd partition. --hint-bios=hd0,msdos3 partition UUID 8bc6e37c-53b1-4fe9-b242-5b0b9c8c575e Not expected if this OS is on the USB. Expectiong second HD (the USB) NOT the same as the booted OS. Perhaps /dev/sdb3 

The reason we expect any HD except the first one (or the one the host OS is on) is because the computer is booted from an OS (assume from a HD and not an ISO), the USB drive is then inserted and will be the next available HD. /dev/sdX The X is the drive letter.

At this point you are interacting with the booted OS, the host. The USB drive has been attached. The host OS may have auto mounted the USB. This is okay if read/write mount. I prefer to unmount (NOT eject) the USB and remount at my determined locations.

Verify the USB device assignment. sudo fdisk -l You know the layout and size of the USB, so get the /dev/sdX info.

OR

Unplug the USB from the host.

command dmesg

Plug the USB back in.

command dmesg

Should tell you abount the new device and the /dev assingment. sdX.

Mount the USB partitions to your predermined mount points.

example:

sudo mount /dev/sdX /media/f24

sudo mount /dev/sdx /media/f8

/media/f24 -- the root of the Fedora24 /media/f8 -- the root of the Fedora8 

Reinstall grub bootloader to the USB drive and point to the mounted partition.

sudo grub-install --recheck --boot-directory=/media/f24/boot /dev/sdX

--boot-directory=/media/f24/boot

This is where the boot loader will look for the grub.cfg file. BTW the one already there will not get us there.

/dev/sdX

This is the USB drive. Info gathered from above. No partition info here only the device.

Create a new grub.cfg file that will overwrite the file created by Fedora24 install.

sudo grub-mkconfig --output=/media/f24/boot/grub/grub.cfg

This will overwrite the grub.cfg from Fedora24 install.

Verify the new grub.cfg file.

Should have the host OS currently running info entry.

Should have the USB drive OSs. These will be on a different device than the host OS. /dev/sdX.

Also verify using command: blkid

The UUID numbers for the USB drive partitions should match the UUID numbers in the new grub.cfg.

NOTE: The /dev/sdX assignment will be incorrect when the USB is booted. Thats okay. The UUID partition number will still 'find' the correct partition and boot the correct OS. This will be adjusted in the custom grub.cfg later.

also verify the correct grub.cfg s loaded on USB boot.

After commands above change the colors in the new grub.cfg

Add the lines:

# Set menu colors set menu_color_normal=red/black set menu_color_highlight=light-gray/red 

Guessing between the lines:

### END /etc/grub.d/01_users ### and ### BEGIN /etc/grub.d/10_linux ### 

When you see a grub menu in different colors you know the correct one loaded. grub-install is correct.

Dont get stuck on this part, you could simply change the menu entries name...

If new grub.cfg passes UUID verification you know grub-mkconfig is correct.


Trouble shoot part 2.

Looking at the Ferora 24 menu entry...

GRUB is setting root 3 different ways. (NOT the Fedora kernel root. that is something else.)

1. set root='hd1,msdos2'

This is a 'hard' set of root. The 2nd. drive on the 2nd. partition.

The 'trick' here is this what drive is first can change on every boot. What ever device probes first becomes first.

2. search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos2 --hint-efi=hd1,msdos2 --hint-baremetal=ahci1,msdos2 d4be737a-c4ea-44cd-a22d-781086854ec8

This entry inside the if is basically saying we want partition with UUID xxx, but start looking on 2nd. drive 2nd. partition.

3. search --no-floppy --fs-uuid --set=root d4be737a-c4ea-44cd-a22d-781086854ec8

This is also inside the if statement and is saying go look for partition with UUID xxx anywhere you can look, except the floppy drive.

We want to use the 3rd syntax.

NOTE: GRUB counts the drive from 0 (hd0 - hdn) and counts the partitions from 1 (msdos1 - msdosn). GRUB2 manual.

"seems to me the initrd/initiramfs might be at fault here"

Yes, I think so too, but not the files themselves but where GRUB is looking for the files.

GRUB is looking to load the linux kernel from /boot/vmlinuz-0-rescue-731a5ce6cbc840ad9cad96ddf48e5db8, or more accurately GRUBroot/boot/vmlinuz-0-rescue-731a5ce6cbc840ad9cad96ddf48e5db8

GRUBroot = partition d4be737a-c4ea-44cd-a22d-781086854ec8. If we set it correct.

initrd is same.

GRUBroot/boot/initrd-2.6.23.1-42.fc8.img

BTW: Your first grub.cfg had Fedora24 loading different kernel and initrd. You may want to revert to using those again because of production kernel and language etc...

linux /boot/vmlinuz-4.5.5-300.fc24.x86_64 root=UUID=d4be737a-c4ea-44cd-a22d-781086854ec8 ro rhgb quiet LANG=fr_BE.UTF-8

initrd /boot/initramfs-4.5.5-300.fc24.x86_64.img

Verify files still exist.

"/dev/root cannot be found"

Yes because

linux /boot/vmlinuz-0-rescue-731a5ce6cbc840ad9cad96ddf48e5db8 root=/dev/sdc2

is saying the kernel root is on the 3rd. drive 2nd. partition.

Lets create a new entry by changing grub.cfg with text edit. Delete the others after this works.

menuentry 'Fedora 24 on USB drive' { insmod part_msdos insmod ext2 ## set the GRUB root using UUID only. search --no-floppy --fs-uuid --set=root d4be737a-c4ea-44cd-a22d-781086854ec8 ## is F24 root somewhere else? ## Probably not.. remove kernel switch root=/dev/sdc2 linux /boot/vmlinuz-0-rescue-731a5ce6cbc840ad9cad96ddf48e5db8 initrd /boot/initramfs-0-rescue-731a5ce6cbc840ad9cad96ddf48e5db8.img ## I think you want these instead if the files still exist. Make adjustments by adding and removing comments ## ## commented out # linux /boot/vmlinuz-4.5.5-300.fc24.x86_64 root=UUID=d4be737a-c4ea-44cd-a22d-781086854ec8 ro rhgb quiet LANG=fr_BE.UTF-8 # initrd /boot/initramfs-4.5.5-300.fc24.x86_64.img } 

and

menuentry 'Fedora 8 on USB drive' { insmod part_msdos insmod ext2 ## set the GRUB root using UUID only. search --no-floppy --fs-uuid --set=root 8bc6e37c-53b1-4fe9-b242-5b0b9c8c575e ## is F8 root somewhere else? ## Probably not.. remove kernel switch root=LABEL=/ ## not familure with this switch, but removed. linux /boot/vmlinuz-2.6.23.1-42.fc8 ro rhgb quiet initrd /boot/initrd-2.6.23.1-42.fc8.img ## I think you want these instead if the files still exist. Make adjustments by adding and removing comments ## ## commented out # linux /boot/vmlinuz-2.6.23.1-42.fc8 ro root=LABEL=/ rhgb quiet # initrd /boot/initrd-2.6.23.1-42.fc8.img } 

No update required, just reboot to the USB drive.

Remember after you get this working you will want to modify etc/grub.d/40_custom so a Fedora kernel update will probe and generate the correct new GRUB menu entry.

Not positive this can be done. You may be forced to manually update grub.cfg every time the Fedora kernel updates.

linux /boot/vmlinuz-4.5.5-300.fc24.x86_64 root=UUID=d4be737a-c4ea-44cd-a22d-781086854ec8 ro rhgb quiet LANG=fr_BE.UTF-8

initrd /boot/initramfs-4.5.5-300.fc24.x86_64.img

7
  • Hello, thanks again for taking your time for this specific topic. I chose to do the second option you suggested, as I initially installed GRUB on my USB key from a Fedora 24 VM. Now I did it from my Ubuntu 16.04, and the installation worked fine. I now also have the complete set of options for my dual boot, as shown in this new capture. The UUID's in the new grub.cfg also match. Unfortunately, booting F8 or F24 makes me run into the same issues as before: respectively, I get a message that filesystem /dev/root cannot be found, and for F24, dracut queues time out. Commented Apr 7, 2018 at 10:09
  • I did a bit of research myself after this and it seems to me the initrd/initiramfs might be at fault here. Unfortunately, I followed this tutorial to try rebuild the initrd image for my F8 but it didn't fix anything (I made a save of the previous image and restored it afterwards). As I read the problem might be the inability of the OS to find the swap partition, I also edited the /etc/fstab file in F24 to replace the UUID of the swap partition with the correct one. Again, this didn't change a thing. Commented Apr 7, 2018 at 10:12
  • As the rule of thumb is that the gravity of an issue is inversely proportional to the error that created it, I tend to think I did something really stupid at some point without realizing it... anyway, I provide you the output of fdisk and blkid as well as the new grub.cfg file if you wish to have a look at. Commented Apr 7, 2018 at 10:17
  • Hello, I added "Trouble shoot part 2." to this answer. Hope it helps. Commented Apr 9, 2018 at 15:38
  • Good news: following your comments and documenting myself a bit regarding initramfs, I managed to get Fedora 24 working on my USB stick. I will provide a few details on the small things I did in addition to your various advice when I am sure to be done (besides, I have to get Fedora 8 working too). Commented Apr 9, 2018 at 21:05
0

The answers provided have good information and offer insight to the process, which I consider very important (particularly for the auto-didactic types, which describes a lot of us here at SE).

However, there is a free project that more or less achieves something like this for those who come here and just want to accomplish something similar, if not exactly the same.

https://www.pendrivelinux.com/yumi-multiboot-usb-creator/

The name is silly. The graphics are cheesy. The tools work, and they work pretty well. At the very least the source code they make available might help you.

2
  • Note that YUMI doesn't do exactly what is discussed here. YUMI can copy isos on your USB stick and install a menu to select them, and add persistence, but it doesn't install the full operating system. If I recall correctly, there is even a checkbox in the window where you select your settings to show all .iso files because otherwise it will only show .iso of Live versions. Commented Apr 13, 2018 at 8:43
  • Thanks for the clarification, Jef. I have updated my answer, which is really only intended to help others who come across this question and want other options. Commented Apr 15, 2018 at 19:52

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.