How can Lubuntu 20.04 LTS be installed in a USB which can boot into both- UEFI & Legacy BIOS systems?

I presume you want a persistent (full-installation) on this USB. It is possible to make a USB installation that can boot in both Legacy and UEFI modes, but it requires some effort:

First, you have to have an installation media that boots in both Legacy and UEFI. Tools such as Rufus or Ventoy can be used to create these. For example, if using Rufus, when making the installation medium, set the partition scheme to "MBR" and the target system to "BIOS or UEFI". If using Ventoy (which can be run under Linux as well as just Windows), it will support both Legacy and UEFI by default, just copy the Lubuntu ISO to the USB.

  1. Plug in your installation medium and boot from it through Legacy mode first. Select "Try Lubuntu" at the menu.
  2. Once at the desktop of your live system, plug in the USB you wish to use as the target (which Lubuntu will be installed onto).
  3. Connect to the internet if not already connected.
  4. Open a terminal and run sudo apt install gparted. LXQt has KDE Partition Manager by default, however Gparted works better in cases like this.
  5. Launch Gparted. Change the dropdown in the top right-hand corner to your target USB device.
  6. Right click any existing mounted partitions and unmount/swapoff them.
  7. Select "Device" on the top bar, and select "Create partition table". Change the dropdown to "GPT" (note: this will erase all data on the disk, ensure data is backed up to your satisfaction first!).
  8. Create a new partition. The size should be 1MB and the file system should be unformatted.
  9. Create another partition. The size should be 100MB and the file system should be FAT32.
  10. Create another partition. The size should be around ~1GB and the file system should be swap.
  11. Create one last partition, which will be used as the root filesystem of your installation. The size should be however much space you have left on the disk. File system should be ext4.
  12. Apply the changes by clicking the tick button in Gparted.
  13. Right click the 1MB partition, select "Manage flags", and set the flags to bios_grub.
  14. Also set the flags of the 100MB partition to boot and esp.
  15. Close Gparted and proceed with the installation as you normally would, until you reach the partitioning step.
  16. Select "Manual partitioning" or "Advanced" at the partitioning step. You'll be asked to specify the partitions to use for installation.
  17. Set the 1MB unformatted partition to "Reserved BIOS boot area".
  18. Set the 1GB swap partition as swap.
  19. Set the ext4 partition as the root partition (mount point = /). If it is shown, check the box to specify to format this partition.
  20. Don't forget to change the bootloader dropdown to your USB drive!
  21. Confirm that the partitions are correct and then continue.
  22. Wait for installation to finish, then power off your machine.
  23. Boot from your installation media again, this time in UEFI mode. Follow the same steps to get to the live system desktop.
  24. Plug in your target USB again.
  25. Connect to the internet.
  26. Open a terminal.
  27. Run sudo fdisk -l. Take note of the /dev/sdx label of your USB drive, it will probably be /dev/sdb or /dev/sdc. In these next commands, /dev/sdx will refer to your disk. Make sure you substitute the x for the actual letter shown for your one!
  28. sudo umount /dev/sdx4
  29. sudo swapoff /dev/sdx3
  30. sudo umount /dev/sdx2 (this one may not be mounted but its best to make sure they're all unmounted anyway)(sdx1 is the BIOS boot partition so it will never be mounted).
  31. sudo mount /dev/sdx4 /mnt
  32. sudo mkdir -p /mnt/boot/efi
  33. sudo mount /dev/sdx2 /mnt/boot/efi
  34. sudo swapon /dev/sdx3
  35. sudo mount --bind /dev /mnt/dev
  36. sudo mount --bind /dev/pts /mnt/dev/pts
  37. sudo mount -t proc proc /mnt/proc
  38. sudo mount -t sysfs sysfs /mnt/sys
  39. sudo mount -t tmpfs tmpfs /mnt/run
  40. sudo chroot /mnt.
  41. apt install grub-efi-amd64 (EDIT: If on 32-bit instead of 64-bit, run apt install grub-efi-i386 instead).
  42. grub-install --efi-directory=/boot/efi --target=x86_64-efi --removable (this will install the UEFI bootloader. It will not conflict with your existing Legacy bootloader installation) (EDIT: If you experience problems at this stage, mount /dev/sdx2 /boot/efi and then try again)(EDIT 2: It may also be possible to copy the EFI bootloader files from the live system instead of installing like this, but I felt it was more robust to do a clean install of the bootloader)(EDIT 3: Replace --target=x86_64-efi with --target=i386-efi if on a 32-bit system).
  43. update-grub.
  44. blkid | grep /dev/sdx2 (x is still a placeholder here). From the output of this command, take note of the UUID number, which is in the format XXXX-XXXX.
  45. echo "UUID=XXXX-XXXX /boot/efi vfat umask=0077 0 1" >> /etc/fstab (XXXX-XXXX is still a placeholder, replace it with your partition's UUID).
  46. Now exit your chroot.
  47. Power off your system (all currently mounted partitions will be unmounted automatically).
  48. Boot from your new installation in either Legacy or UEFI mode; both will work!

Enjoy your system. If any of this doesn't make sense I'll be happy to clarify it. I have personally tested this before myself (for Kubuntu not Lubuntu), and works fine.


Simplified Full Install of Ubuntu 20.04 to USB that Boots BIOS and UEFI

  • Download BIOS/UEFI Template: https://phillw.net/isos/linux-tools/uefi-n-bios/dd_grub-boot-template-for-uefi-n-bios.img.xz

  • Flash image to target USB using Win32DiskImager, Rufus, mkusb, balenaEtcher, etc.

  • It is recommended to unplug any internal drives especially when installing in UEFI mode.

  • Boot Live Installer USB, and insert Target USB.

  • Start install process, select: Language, Keyboard, Wireless, Updates and Something Else.

  • Select Target USB for Bootloader installation.

  • (Optional Data Partition), Select the empty space on the Target drive and click the plus sign to create a FAT32 partition with mount point "/Windows". Leave at least 6GB empty space for root partition.

  • Select the empty space on the Target drive and click the plus sign to create an ext4 partition with mount point "/".

  • Select Install now, confirm partition to be formatted, enter location, name and password.

  • When install is complete copy root /boot/grub/grub.cfg to overwrite boot,esp /boot/grub/grub.cfg

  • If created in UEFI mode reinstall GRUB for BIOS boot:

    sudo mount /dev/sdx3 /mnt

    sudo grub-install --boot-directory=/mnt/boot /dev/sdx

Thanks to Sudodus for the mkusb based BIOS/UEFI Template