# Booting from usb stick



## andre64 (Apr 21, 2020)

Hi everyone. I'm a newbie in the *nix world and in command line, but my question is very simple. I would like to know how I can create an USB stick to boot FreeBSD - I don't mean a stick with an image or an ISO to install that, because the system is installed already, I want to know how to boot the installed FreeBSD from an USB stick in order to avoid booting from MBR - in my hard disk FreeBSD is installed with Windows 10, so the proper question would be about the installation of a bootloader for these two systems in an USB stick. Thanks and thanks for adding me in the forum.


----------



## eldaemon (Apr 30, 2020)

Easiest way would be to have the installer install to a second USB stick.


----------



## D-FENS (May 1, 2020)

You can't boot from a MBR because this kind of boot requires putting your computer in Legacy boot mode and Windows 10 does not boot in legacy mode.
If you want to double-boot Windows 10 and FreeBSD, then your boot mode needs to be UEFI.

Preparing the disk: It does not make any difference if you put the boot loader on a USB disk or a hard drive. Both are block devices and are treated the same, provided your computer's BIOS can boot from USB.
Preparing a UEFI device is described in the Wiki: https://wiki.freebsd.org/UEFI
Just make sure, doublecheck and triplecheck that you are working on the correct device: `gpart show` - make sure the device you are working on is the USB disk (for example, da1).


```
# You need to create a GPT partition table on da1:
gpart create -s gpt da1

# Then create an EFI system partition:
gpart add -t efi -s 256M da1 # It needs to be formatted with FAT16, so do not use the whole USB drive (it's probably too large for FAT16).

# No need to create a root partition (you already have it on your hard drive).
newfs_msdos -F 16 -c 1 /dev/da1p1 # I am not sure but FAT32 might also work with EFI, check this to be sure

mount -t msdosfs /dev/da1p1 /mnt
mkdir -p /mnt/EFI/BOOT
cp /boot/loader.efi /mnt/EFI/BOOT/BOOTX64.efi
umount /mnt
```

This will enable you to boot FreeBSD when booting from the USB drive.
If you want to dual boot, then you need to put both FreeBSD's loader.efi and Windows 10's EFI program on the EFI system partition. Then you could use the program *efibootmgr*(8) to add two boot entries to your BIOS and you'll be able to select which OS to boot on startup.

A word of warning - dual booting, especially with Windows, is quite tricky. So you need to be patient to get it right.


----------



## eldaemon (May 1, 2020)

My favorite dual booting is just having two drives and replacing as needed.


----------



## andre portes (Jun 29, 2020)

I have Windows 10 and Freebsd installed in my notebook under Legacy Mode and recently I've made an Usb stick with the same dual boot


----------



## Jose (Jun 30, 2020)

roccobaroccoSC said:


> You can't boot from a MBR because this kind of boot requires putting your computer in Legacy boot mode and Windows 10 does not boot in legacy mode.


Huh? My childrens' Windows 10 machines boot from legacy BIOS. I see no reason to use the UEFI monstrosity if given a choice. I have an Asrock motherboard where the CSM straight up doesn't work. That's the only UEFI machine in my house.


----------



## Mjölnir (Jun 30, 2020)

RTFM boot(8), boot.config(5) and gpart(8) (and those mentioned in these man pages).  Your goal should be possible, i.e. boot from USB and then the _boot0_, gptboot(8) or loader(8) (via _vfs.root.mountfrom_, see loader.conf(5)) on the USB stick boots the system installed on HDD/SSD.
EDIT: booting with UEFI is much faster than via CSM.  Then read uefi(8) instead of boot(8).


----------



## D-FENS (Jul 25, 2020)

Jose said:


> Huh? My childrens' Windows 10 machines boot from legacy BIOS. I see no reason to use the UEFI monstrosity if given a choice. I have an Asrock motherboard where the CSM straight up doesn't work. That's the only UEFI machine in my house.



I did not know Windows 10 supported that. Cool. I have not used Doze for years except at work where an IT department takes care of stuff.


----------

