M HYPE SPLASH
// news

Use flash drive as a boot loader

By Emma Valentine

I am trying to use a flash drive as a sort of key for booting to Ubuntu. I have Ubuntu installed on a separate hard drive from my Windows one. What I would like to do is have it boot to Windows as default, but when the flash drive is in, boot to Ubuntu. I cannot seem to be able to figure it out. I tried when installing Ubuntu to have the boot loader installed on the flash drive but that doesn't seem to work and I keep getting some sort of error.

Any help would be much appreciated.

2

2 Answers

Its quite simple you know. What you are trying to achieve is create a partition install ubuntu on it without the bootloader then use bootloader installed on usb drive to boot the ubuntu installation.

You can do it by simply adjusting some steps used to create multibootusb.

Using this script as an example this can be achieved.

SUMMARY:

  • first install ubuntu without bootloader. I think running ubiquity with -b flag should do the trick. After installing ubuntu dont remove the intallation media. First we need to install grub2.
  • Clean a usb drive. and create a gpt partition table
  • assuming you have UEFI system. Create a partition no less than 50 MB in size. Lets name it EFI. Format it with Fat32.
  • Now create another partition name it Files. Format it with FAT32/ext*.
  • Install grub bootloader on usb. Now I don't know if you will be able to access the second partition from windows.
  • Create a grub.cfg file pointing towards your ubuntu installation.

COMMANDS:

Assuming usb device is /dev/sdb. Size is 16GB.

$ sgdisk --zap-all /dev/sdb

Create a new gpt (partition table), using fdisk

$ fdisk /dev/sdb 

type n (new gpt partition table) then w (write).

$ sgdisk --new 1::+50M --typecode 1:ef00 --change-name 1:"EFI" /dev/sdb
$ sgdisk --new 2::"rem_space": --typecode 2:8300 --change-name 2:"Files" /dev/sdb

I use cgdisk for this.

$ wipefs -af /dev/sdb1
$ mkfs.vfat -v -F 32 /dev/sdb1
$ wipefs -af /dev/sdb2
$ mkfs.ext4 -L Files /dev/sdb2

Mount them temporarily.

$ cd tmp
$ mkdir EFI Files
$ mount /dev/sdb1 EFI
$ mount /dev/sdb2 Files
$ mkdir -p Files/boot

Install GRUB.

$ grub-install --target=x86_64-efi --efi-directory=/tmp/EFI --boot-directory=/tmp/Files/boot --removable --recheck

Thats it.

  • Now copy & paste a grub.cfg file to /tmp/Files/boot/grub, Either from live ISO or download it from internet and format it accordingly.

Edit: To create grub.cfg as a normal user use chown recursively on Files partition.

Download a program called Yumi, a Win program, then make your bootable usb.

Running YUMI from LINUX: WINE has previously worked for running YUMI from a Linux OS, with the exception of Fat32 Formatting the USB drive.

The YUMI UEFI version is a work in progress that utilize GRUB2 for both EFI and BIOS booting.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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