Post 3: Procedure (just read Post 4 before starting if you want to know what you are doing)
*A: prepare your usb flash drive*
You can do the following either from a version of Ubuntu installed on your HDD or from your live usb (with gparted installed, see Post 2).
(1) Plug in the target drive and start gparted. Any files present in it are going to be deleted. Find out its /dev/name (you can also use the utility "Disks" for that).
(2) Unmount all the partitions in your target drive (in case you have mounted partitions)
(3) Make a new GPT partition table on your target usb drive with gparted
(4) With gparted, make a 300 MB FAT32 partition, set the flags "boot" and "efi" (or "esp" if "efi" is not there)
(5) With gparted, make a large partition (at least 8GB, 16 is better) EXT4 and label it "root" (although the label is not necessary)
(6) With gparted, make a new 1GB swap partition
(6b) IF you want to use part of your drive for sharing data with Windows, move your partitions to the end of the flash drive (with gparted) and leave the free space for a new NTFS partition (it is better if the NTFS partition is the last to be made, just leave the free space at the beginning for the moment). Windows does not always recognize partitions in a usb drive, it may only recognize the first one (quite erratically).
(7) Shutdown. Plug your target drive off and plug in your live usb with the Ubuntu flavor you wish to install. Switch on and wait for the live Ubuntu to boot.
*B: install Ubuntu flavor from live CD*
The following steps require that you are working from an Ubuntu OS live in your live usb drive. Double check that boot-repair is installed.
(1) Plug in your target flash drive and find out its /dev name -- it would probably be /dev/sdc if you have only one internal HDD and you have your live usb on. Let's call it /dev/sdx -- just replace the "x" with the appropriate letter.
(2) Click the button for installing the OS on your PC.
(3) Select the language etc. Decide about installation options. When you get to the drive installation window, select "Something else" -- do not choose to install alongside the existing system or to wipe out HDD.
(4) Select your /dev/sdx1 (the EFI partition: FAT32 300 MB; in case it is given another number, just act on that partition) and press "change"; use it as efi partition -- regrettably, the installer will still install on sda1
(5) Select your /dev/sdx2, press change, use it as EXT4 partition; mount at "/"
(6) Select your /dev/sdx3, press change, use it as swap
(7) Go on with the installation. At the end, choose to close the window but to keep using the live CD.
*C: restore your main system*
(1) Unmount any mounted partitions on your target drive, unplug it.
(2) Run boot-repair and follow its directions -- you might check, in advanced options, that it is setting your grub to boot to the correct partition in your internal HDD. As an alternative, restore your EFI partition and boot configuration in any other way you have previously chosen when you have backed up. boot-repair always worked for me and I can see no reasons why it shouldn't.
(3) Shutdown. Remove the live usb drive. Boot to your main system (the one installed on the internal HDD).
*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:
(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.
Bookmarks