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.
- Plug in your installation medium and boot from it through Legacy mode first. Select "Try Lubuntu" at the menu.
- 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).
- Connect to the internet if not already connected.
- Open a terminal and run
sudo apt install gparted
. LXQt has KDE Partition Manager by default, however Gparted works better in cases like this. - Launch Gparted. Change the dropdown in the top right-hand corner to your target USB device.
- Right click any existing mounted partitions and unmount/swapoff them.
- 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!).
- Create a new partition. The size should be 1MB and the file system should be unformatted.
- Create another partition. The size should be 100MB and the file system should be FAT32.
- Create another partition. The size should be around ~1GB and the file system should be swap.
- 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.
- Apply the changes by clicking the tick button in Gparted.
- Right click the 1MB partition, select "Manage flags", and set the flags to
bios_grub
. - Also set the flags of the 100MB partition to
boot
andesp
. - Close Gparted and proceed with the installation as you normally would, until you reach the partitioning step.
- Select "Manual partitioning" or "Advanced" at the partitioning step. You'll be asked to specify the partitions to use for installation.
- Set the 1MB unformatted partition to "Reserved BIOS boot area".
- Set the 1GB swap partition as swap.
- Set the ext4 partition as the root partition (mount point =
/
). If it is shown, check the box to specify to format this partition. - Don't forget to change the bootloader dropdown to your USB drive!
- Confirm that the partitions are correct and then continue.
- Wait for installation to finish, then power off your machine.
- Boot from your installation media again, this time in UEFI mode. Follow the same steps to get to the live system desktop.
- Plug in your target USB again.
- Connect to the internet.
- Open a terminal.
- 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 thex
for the actual letter shown for your one! sudo umount /dev/sdx4
sudo swapoff /dev/sdx3
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).sudo mount /dev/sdx4 /mnt
sudo mkdir -p /mnt/boot/efi
sudo mount /dev/sdx2 /mnt/boot/efi
sudo swapon /dev/sdx3
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount -t proc proc /mnt/proc
sudo mount -t sysfs sysfs /mnt/sys
sudo mount -t tmpfs tmpfs /mnt/run
sudo chroot /mnt
.apt install grub-efi-amd64
(EDIT: If on 32-bit instead of 64-bit, runapt install grub-efi-i386
instead).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).update-grub
.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 formatXXXX-XXXX
.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).- Now
exit
your chroot. - Power off your system (all currently mounted partitions will be unmounted automatically).
- 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