Simple as that.Post 5: Ubuntu to go? -- UEFI Should be easy
Post 5 only contains some advice for going on experimenting by yourself. I've never tried it yet. Sorry, I'm too busy. But I guess it should be easy.
The way for generating an "Ubuntu to go", that is a clone of your working system (on HDD) that entirely resides on usb key but is portable and UEFI bootable, is a variant on the present procedure.
Instead of installing a new system, you just copy to the flash drive the contents of all the system partitions in your internal HDD. This replaces steps B and C in the post (3) above. For example, if your "internal" Ubuntu is in two partitions: "/" and "home" you just make two analogous partitions in your flash drive and copy the contents to them. No need that the target partitions have the same size as the original ones (provided that you have enough space for copying everything to them).
Be careful about the owners of the files: do not copy the home dir as root. To do the copying you have
to run your liveCD, so that your HDD partitions are not mounted.
The contents of the EFI partition are copied as above: post 3, D.
*D: Tweak the usb flash drive*
(1) You are now in your working main system. Plug in the target drive with the Ubuntu installation. Find out its partition names /dev/sdxy. Find out the UUIDs of sdx1 (EFI) sdx2 (root) and sdx3 (swap) with gparted (right click on partition and select "information") or "sudo blkid /dev/sdxy" and write them down.
(2) The root partition of your target drive should have been automatically mounted when you have plugged in the flash drive. Mount the EFI partition of the target drive:
Code:
sudo mkdir /mnt/efi
sudo mount /dev/sdx1 /mnt/efi
(3) keeping the UUID of sdx1 (EFI) and sdx2 (partition root in target drive) in a sheet of paper or in the clipboard produce the crucial text file grub.cfg ("CGC" hereafter) opening your text editor as root (e.g. sudo leafpad for a Lubuntu user, sudo gedit, etc.). You should produce a text file containing exactly the following three lines, but you have to replace the expression between "<>" with the UUID of your EFI partition in your target drive:
Code:
search.fs_uuid <YOUR EFI UUID in target flash drive> root hd1,gpt2
set prefix=($root)'/boot/grub'
configfile $prefix/grub.cfg
Save as grub.cfg.
Again: use gedit or leafpad as you please, but open your editor as root and save as root (root must be the owner of the file) somewhere in your home directory.
(4) CAREFUL HERE -- the contents of your own EFI partition might differ from one install to another, so I am going to give you the files that you must have in the EFI partition of the target drive at the end of the job. You can also copy and paste the list of commands I produce below.
Some of these files MIGHT be redundant, in efi/Boot or in efi/EFI/Boot. No harm. All of these files must be copied from a working install of Ubuntu in your HDD: you can't do this from a live usb.
Supposing that the grub.cfg you have generated in (3) is in your current directory and is called "grub.cfg", that you have already made the dirs /mnt and /mnt/efi and that your EFI partition in the flash drive is sdx1, this is the list of commands you need in order to rebuild the above structure. If you have already mounted your efi partition in the target drive on /mnt/efi, just skip over the first command in the list.
Code:
sudo mnt /dev/sdx1 /mnt/efi
sudo mkdir /mnt/efi/Boot
sudo mkdir /mnt/efi/ubuntu
sudo mkdir /mnt/efi/EFI
sudo mkdir /mnt/efi/EFI/Boot
sudo mkdir /mnt/efi/EFI/ubuntu
sudo mkdir /mnt/efi/EFI/ubuntu/fw
sudo cp /boot/efi/EFI/Boot/bootx64.efi /mnt/efi/Boot/
sudo cp /boot/efi/EFI/Boot/bootx64.efi.grub /mnt/efi/Boot/
sudo cp grub.cfg /mnt/efi/Boot/
sudo cp grub.cfg /mnt/efi/EFI/Boot/
sudo cp /boot/efi/EFI/ubuntu/grubx64.efi /mnt/efi/Boot/
sudo cp /boot/efi/EFI/ubuntu/MokManager.efi /mnt/efi/Boot/
sudo cp /boot/efi/EFI/ubuntu/shimx64.efi /mnt/efi/ubuntu/
sudo cp grub.cfg /mnt/efi/ubuntu/
sudo cp /boot/efi/EFI/Boot/bootx64.efi /mnt/efi/EFI/Boot/
sudo cp /boot/efi/EFI/Boot/bootx64.efi.grub /mnt/efi/EFI/Boot/
sudo cp /boot/efi/EFI/ubuntu/grubx64.efi /mnt/efi/EFI/Boot/
sudo cp /boot/efi/EFI/ubuntu/MokManager.efi /mnt/efi/EFI/Boot/
sudo cp /boot/efi/EFI/ubuntu/fwupx64.efi /mnt/efi/EFI/ubuntu/
sudo cp grub.cfg /mnt/efi/EFI/ubuntu/
sudo cp /boot/efi/EFI/ubuntu/grubx64.efi /mnt/efi/EFI/ubuntu/
sudo cp /boot/efi/EFI/ubuntu/MokManager.efi /mnt/efi/EFI/ubuntu/
sudo cp /boot/efi/EFI/ubuntu/shimx64.efi /mnt/efi/EFI/ubuntu/
sudo umount /mnt/efi
You can make a bash file from the commands above (in this case, run it as root) or add a semicolon and a backslash at the end of each one but the last one and run it from terminal as a single very long command. Or you can copy and paste the commands one by one.
(5) in etc/fstab of the root partition of the target flash drive, replace the UEFI boot UUID with the UUID of sdx1 (if you've lost it, find it out with sudo blkid /dev/sdx1). You have to do this for the file etc/fstab of your flash drive's root partition, which should be mounted in /media/... and NOT for the /etc/fstab of your running system (!!)
The UUID of your root partition should already be correct in the flash drive's fstab: just check.
While you are tweaking fstab add noatime option to root partition
Code:
ext4 noatime,errors=remount-ro 0 1
Check the swap file in fstab; if it lists a swapfile from your HDD (normally sda) replace that UUID with the UUID of your flash drive swap file. (That is, unless you wish to use your flash drive only in the PC you are now using, in which case it may be convenient to use the HDD swap file.)
Now you can remove journaling from the flash drive root partition (to reduce wear). From terminal write:
Code:
sudo tune2fs -O ^has_journal /dev/sdxy
Replace sdxy with the device name of your root partition in the flash drive. sdxy should normally be sdb2, unless you have more than one HDD or you have another flash drive or ext. HDD plugged in.
(6) If you want to minimize the use of swap file, change the system swappiness value: in the root partition of your target flash drive edit etc/sysctl.conf as root. Then, change or add this line to the file:
Code:
vm.swappiness = 0
(You could also change the value while your system will be running: from terminal sysctl vm.swappiness=0)
(cat /proc/sys/vm/swappiness from terminal to find out current swappiness value *in your running OS*)
If you are low on RAM it is better to keep swappiness to 60 or 50.
After every update, your grub will also give you the option to start all the operating systems that are present in your HDD; if you are running your OS from another computer, just do not choose those options in the grub menu.
In addition to this, you have to modify your /boot/grub/menu.lst replacing the UUID of the root partition in your HDD with the UUID of the root partition in your flash drive.
Also remember to tweak the /etc/fstab in the root partition of your usb drive so that it points to the copies of the Ubuntu system partitions on your usb drive.
After the first boot into your flash drive clone, I guess you had better run update-grub.
Remember that your grub, after every update, will also give you the option to start all the operating systems that are present in your HDD; if you will later run your OS in another computer, just remember not to choose those options.
Last edited by Halbarad; October 2nd, 2016 at 12:43 PM.
All in all, Linux is better.
https://ubuntuforums.org/showthread.php?t=2338836
Like the author of the article, I have not done it yet. I may never do it; not because I am too busy with other things. As I've noted a few times in the past, Linux just isn't worth the trouble.