Technology Encyclopedia Home >How to boot to USB device from bootloader in Linux?

How to boot to USB device from bootloader in Linux?

To boot to a USB device from the bootloader in Linux, you typically need to modify the bootloader configuration to prioritize the USB device over other boot devices like the hard drive. Here’s a general guide on how to do this:

Using GRUB Bootloader

  1. Access GRUB Menu: Restart your computer and press the key that opens the GRUB menu (commonly Shift, Esc, or F2).

  2. Edit GRUB Configuration:

    • Highlight the entry you want to boot from (usually the first one) and press e to edit.
    • Locate the line starting with linux or linux16. This line specifies the kernel parameters.
    • Add root=/dev/sdX where sdX is the identifier for your USB drive (e.g., sdb). You can find this by running lsblk or fdisk -l in a terminal when the USB is connected.
    • Press Ctrl+X or F10 to boot with the modified settings.
  3. Make Permanent Changes:

    • To make this change permanent, edit the GRUB configuration file. Open /etc/default/grub in a text editor.
    • Modify the GRUB_DEFAULT option to point to the USB entry or adjust other settings as needed.
    • Update GRUB by running sudo update-grub.

Example

Suppose your USB drive is identified as /dev/sdb1. You would:

  • Press e on the GRUB menu entry.
  • Find the line starting with linux and add root=/dev/sdb1.
  • Press Ctrl+X to boot from the USB.

Using systemd-boot

If your system uses systemd-boot, you can add a new entry for your USB device:

  1. Create a new .conf file in /boot/loader/entries/ with details about your USB device.
  2. Specify the path to the kernel and initramfs on the USB.
  3. Update the bootloader by restarting.

Cloud-Related Recommendation

For scenarios involving booting from USB in cloud environments, consider using services that offer virtual machine management and customization, such as Tencent Cloud’s Virtual Private Cloud (VPC) and Cloud Virtual Machine (CVM) services. These allow for flexible configurations and management of VMs, including the ability to customize boot settings and use custom images.

Remember, modifying bootloader settings can be risky and should be done with caution to avoid rendering your system unbootable. Always ensure you have backups and possibly a live USB for recovery.