7

Self-explanatory question. But please keep in mind in totally new to Linux.

  • I really request you to answer this as though you were hypothetically going to explain to a 12 year old. Im actually 38, but the point is i find it difficult to follow things that intermediate Linux uses are cool with.
  • If there is a similar question previously answered(I tried finding one for ~25 mins, found nothing for Lubuntu with good steps -- im stupid, i need steps) , please do not immediately shut my question... Maybe give me some time so i can test to see if it works and if it does, i'll shut the question myself!
  • I need this because I have to move around and travel a lot, and need a reliable way to port a full OS without the risk of damaging a laptop, and further once im there, i generally have access to a machine, and for the rest my phone suffices.
An Ant
  • 183
  • 3
    Welcome to Ask Ubuntu: Please see: How to Create a Full Install of Ubuntu 20.04 to USB Device Step by Step https://askubuntu.com/questions/1217832/how-to-create-a-full-install-of-ubuntu-20-04-to-usb-device-step-by-step – C.S.Cameron Jun 25 '20 at 11:10
  • @C.S.Cameron Errors Step 41-42 ...running 41 gives me some errors that do not seem to impede what I'm doing, but trying out step 42 gives me ' grub-install: error: /boot/efi doesn't look like an EFI partition.' Relevant Screenshot attached here [https://drive.google.com/file/d/1HUBYBUIoP16WXVrgSErspYMyVbHs78MR/view?usp=sharing] I am a complete noob so tell me exactly what I should do from hereon ? – An Ant Jun 25 '20 at 11:56
  • 1
    Does your boot,esp partition /boot/grub/ folder contain both i386-pc and x86_64-efi folders with a grub.cfg file a duplicate of the one in your root /boot/grub folder? – C.S.Cameron Jun 25 '20 at 12:40
  • I'm unsure how to determine that... I don't think its even mounted, and am too afraid to alter the system's state... Please guide me @C.S.Cameron – An Ant Jun 25 '20 at 12:50
  • 1
    Open Disks, highlight the target drive, then the boot,esp FAT32 partition, if there is a little triangle lower left click it. a blue link to the partition should appear double or triple click that, Files should open, double click the boot folder, then the grub folder. do you see the items I mention above? – C.S.Cameron Jun 25 '20 at 13:10
  • Right, I did it... No , the boot, esp partition is empty @C.S.Cameron – An Ant Jun 25 '20 at 13:26
  • 1
    Copy Boot and EFI folders to it from the Live USB or from the Ubuntu iso file. confirm /boot/grub/ has i386-pc and x86_64-efi folders. overwrite grub.cfg with the one from thr root /boot/grub/ folder then reinstall grub per my instructions. – C.S.Cameron Jun 25 '20 at 13:52
  • @C.S.Cameron it displays permission denied ... Oh, what a mess... What should I do ? – An Ant Jun 25 '20 at 14:15
  • Open Files using sudo -H nautilus to have admin control. – C.S.Cameron Jun 25 '20 at 14:25
  • It is getting late here, I will post a simplified, easy to understand Full install method tomorrow. – C.S.Cameron Jun 25 '20 at 14:38
  • @C.S.Cameron, Do you think it would be worthwhile to create a compressed image file with an installed system that boots in UEFI and BIOS mode with Ubuntu 20.04 LTS like I have done with previous versions? At 16.04 LTS there was some interest, but later on I have had next to no feedback, so I have skipped it. But I notice now, that it can be complicated for new users to do it themselves even with detailed instructions ... – sudodus Jun 25 '20 at 14:48
  • @C.S.Cameron Yes please, that will be much appreciated, im still hitting errors , feel like I'm hitting a wall here, and its getting late here too... ! – An Ant Jun 25 '20 at 15:20
  • 1
    @sudodus That would make it easy to install to USB. It makes a pretty big download but could save a lot of hassle. perhaps add a small NTFS partition that could be expanded. A small swapfile could also be expanded. Don't think we need a separate /home partition. Making it encrypted could be an option. Maybe provide it as an answer at https://askubuntu.com/questions/1217832/how-to-create-a-full-install-of-ubuntu-20-04-to-usb-device-step-by-step – C.S.Cameron Jun 25 '20 at 16:46
  • 1
    Its all fixed. The minor oversight of not mounting the boot + esp tagged partition to /boot/EFI had resulted in this catastrophe, and I managed to troubleshoot it myself. – An Ant Jun 25 '20 at 16:47
  • 1
    Well done @An Ant. – C.S.Cameron Jun 25 '20 at 16:49
  • 1
    Congratulations @AnAnt :-) So you need not use a compressed image file. It is possible but difficult, maybe imposiible to make it with encrypted disk, because you must do that yourself in order to set the passphrase. We'll see what I can do, but there is no hurry now. – sudodus Jun 25 '20 at 16:54
  • thanks a lot fellas, I'm surprised myself the I managed to figure this one out, being a proper noob , but credits to @glitchyme for this - https://superuser.com/a/1379609 which finally I tried out of desperation and when it worked I realised the issue. – An Ant Jun 25 '20 at 16:59
  • @C.S.Cameron, "That would make it easy to install to USB. It makes a pretty big download but could save a lot of hassle." - I made it and the file size is smaller than the corresponding Ubuntu iso file (2,0 vs. 2.6 GiB). See this link. – sudodus Jun 26 '20 at 19:59
  • No, the answer that I have selected as accepted answers my question perfectly ! @KKPatel , please look before you leap – An Ant Jun 28 '20 at 08:56
  • Full Credits to @DanielMasey for the step-wise instructions. I decide to do some good documentation with the aim of ideally allowing even a noob to achieve a portable Linux install of any distro , which is available here, and updated occasionally --> https://docs.google.com/document/d/14PWThtbylgmqsnQbR8hUbgU6hfh55GJ9N1EOEEbrnzg/edit?usp=sharing The Linux to my GNU is Daniel Masey's answer. However, a noob might need more instructions to apply this generally across other distros. Hence this separate answer. My issue was still 100% solved by Daniel's answer, so it remains the accepted answer. – An Ant Jun 29 '20 at 11:07

4 Answers4

5

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.

Daniel M.
  • 1,903
  • Doubt at step 17.... Lubuntu 20.04 seems to have these settings unavailable.... Either that or I just don't know how to get to them. I've tried right-clicking ,which yields no result and neither do any menu icons... Will have to ditch the GUI and hit the terminal ? screenshot : [ https://drive.google.com/file/d/1qPO-qgf3zP6aFlMDAvvyEbRVUvyN1Fxy/view?usp=sharing ] – An Ant Jun 25 '20 at 10:04
  • Okay... so no issues apparently... apparently the GUI is 10 steps ahead of me, and I can only change the the etx4 partition to root (/) and I'm guessing it configures the other automagically, since it wouldn't let me touch the setting of other partitions without formatting, which to me implies that it knows what its doing withe them... great ! I've set this to install at step 21 ~ 22. – An Ant Jun 25 '20 at 10:15
  • Errors @ Step 41-42 ...running 41 gives me some errors that do not seem to impede what I'm doing, but trying out step 42 gives me ' grub-install: error: /boot/efi doesn't look like an EFI partition.' Relevant Screenshot attached here [https://drive.google.com/file/d/1qPO-qgf3zP6aFlMDAvvyEbRVUvyN1Fxy/view?usp=sharing] – An Ant Jun 25 '20 at 11:09
  • Wrong screenshot link in above comment. correct screenshot link --> https://drive.google.com/file/d/1HUBYBUIoP16WXVrgSErspYMyVbHs78MR/view?usp=sharing – An Ant Jun 25 '20 at 11:19
  • I am in such deep sh*t, @DanielMassey , So if you see the screenshot error , right after that I absolutely have no idea to do, my system. I'm sitting and waiting for you. I have no idea what witchcraft commands I used, all I know is I need help to get beyond this error ! – An Ant Jun 25 '20 at 15:36
  • @AnAnt "Doubt at step 17" - you have to flag the partitions from Gparted, not the Lubuntu installer. "Errors @ Step 41-42" - You have to flag the EFI system partition /dev/sd{x}2 with boot and esp. – Daniel M. Jun 25 '20 at 16:16
  • And I apologise for my late response, but I don't get notified for StackExchange, so I can only see these comment when I login (which is 2 or 3 times a day usually). – Daniel M. Jun 25 '20 at 16:29
  • Right, I completely understand, please excuse my freaking out. You will have to edit your answer, because at before step 42 and after step 40 or 41, one needs to do ' sudo mount /dev/sdx2 /boot/efi ' before installing Grub. This I did and has fixed my issue, I had not forgotten to flag it with EFI and boot. Please edit , perhaps someone someday needs to follow this guide , he should make sure to mount the /dev/sdx2 to /boot/efi otherwise he'll never be able to install anything to /boot/efi since that location is blank ! – An Ant Jun 25 '20 at 16:45
  • @ Daniel Massey I copy Boot and EFI folders from the Live USB or an ISO file to the boot,esp partition so it is not empty. – C.S.Cameron Jun 25 '20 at 17:04
  • @AnAnt The EFI system partition was mounted into the chroot at stage 33, but I will make a note of it in an edit to the answer. – Daniel M. Jun 25 '20 at 17:21
  • @C.S.Cameron I wasn't aware copying the bootloader files directly would work, I feel that it's more robust to clean install the bootloader, however I'll make a note of it in an edit to the answer. – Daniel M. Jun 25 '20 at 17:21
  • @DanielMassey Your right, then. But you've mounted it to mnt/boot/efi in 33... Just edit 33 to /boot/efi and your done ! – An Ant Jun 26 '20 at 00:19
  • @AnAnt /mnt/boot/efi on the host should be treated as /boot/efi to the chroot at /mnt. I did add a note in brackets anyway next to the grub-install step, though. – Daniel M. Jun 26 '20 at 04:54
  • @DanielMassey Can this guide be minimally edited to work with 32-bit ISOs as well ? If so, I request you to see if you can add support for someone needing this answer later using a 32 bit version... While 64 bit is probably more than 95% of devices, someone may require access to 100% hardware configs... – An Ant Jun 26 '20 at 07:59
  • @AnAnt Only changes needed for 32-bit is instead of apt install grub-efi-amd64 you apt install grub-efi-i386, then at the grub-install step, change --target=x86_64-efi to --target=i386-efi. I'll edit this into the answer. Not that it will be of much use though, since Ubuntu dropped 32-bit support in 19.10. – Daniel M. Jun 26 '20 at 09:01
  • @DanielMassey Can this my x86_64 Linux work on an ARM x86_64 architecture ? Or is this even a theoretical possibility ? – An Ant Jul 01 '20 at 09:13
  • @AnAnt I wouldn't say so. x86_64 (also known as amd64) is the architecture for 64-bit PC. ARM is a different architecture, and 64-bit ARM is known as arm64 or aarch64, not x86_64. If installing UEFI Grub for 64-bit ARM, you would use --target=arm64-efi at the grub-install step. – Daniel M. Jul 01 '20 at 10:31
  • @DanielMassey so are you suggesting that all that needs to be changed is grub ? the iso in itself must also be replaced for an ARM version, correct ? – An Ant Jul 03 '20 at 05:29
  • @AnAnt Yes, the grub will need to be changed, but beside this, nothing from your x86_64 installation will work on arm64. You'll need a whole new installation for arm64. – Daniel M. Jul 03 '20 at 07:30
  • @DanielM. I'm very thankful for your answer and have created https://github.com/a-p-jo/Portable-Linux to save it under CC-BY-SA-4.0 with some more detailed steps and a bit of editing. Hope that is agreeable to you ! – An Ant Feb 13 '21 at 09:21
3

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

C.S.Cameron
  • 19,519
  • @An Ant: Here is the simplified full install procedure I promised you, Better late than never. – C.S.Cameron Jun 26 '20 at 13:47
  • After configuring Linux to my tastes, i see that i need no more than 6GB for the root partition (currently occupies only 5.2GB) ... When I attempt shrinking the root partition in GParted, I have no success. I intend to create an ExFAT partition with the unused storage to utilise this space as a regular flash drive , to move files from here to there. When i need space, I'll just extend the ext4 partition.... But i'm unable to shrink it ! What should I do, Cameron and @Daniel Massey – An Ant Jun 27 '20 at 01:23
  • 1
    @ An Ant: I have never had luck shrinking the root partition beyond what GParted wants. Once it runs out of space it will not boot. I have not had luck with ExFAT, but It has been a while since I tried. Usually I have a NTFS partition unless there is a Mac in the picture, then I recommend a FAT32 partition. Data partition is missing from above guide but I will add it soon. Perhaps I will try ExFAT. I think the data partition should be created in the installer before the root partition so that it is No1 partition. Old Windows only sees the first partition on a flash drive. – C.S.Cameron Jun 27 '20 at 04:31
  • 1
    @An Ant: If you do not have a separate /home partition, your root partition will continue to grow. It might not be fun to be traveling and run out of space. Remember, you will need a computer running Linux to expand the root partition or delete data on it. Which means that you will need to carry a spare Live USB with you. – C.S.Cameron Jun 27 '20 at 05:39
0

I do it using YUMI Multiboot USB creator (you can download it from Pendrivelinux.com). It is used to put multiple operating systems on 1 pen drive. I have one that is set up for UEFI and one that is set for Legacy BIOS (Version YUMI-2.0.7.2 is legacy, version YUMI-UEFI-0.0.2.3 for UEFI (obviously). This has worked for me on older systems, if I wish a legacy boot on a UEFI BIOS, I disable secure boot.

0

Creating a Full install USB the Easiest way

(Password is "changeme", change it)

Thanks to sudodus for the image file, perhaps he will create one with Lubuntu also.

C.S.Cameron
  • 19,519
  • Brilliant, except its 15 gigs... I guess we sacrifice convenience for bandwidth/download time or bandwidth/download time for convenience. – An Ant Jul 03 '20 at 05:31
  • @An Ant: It ends up as 15GB when flashed to disk, but it is only 2GB to download, That is better compression than the Ubuntu ISO. I don't think a Full install disk less than 16GB is practical. I made the remaining GB on mine a FAT32 data partition. – C.S.Cameron Jul 03 '20 at 05:48
  • Ah, I see. I though the downloaded size was 2 GB, my bad – An Ant Jul 03 '20 at 07:57