Friday, September 23, 2016

Install and use Ubuntu from a Removable USB Flash Drive

Ubuntu is fantastic Linux distribution. It takes jut 600 MB RAM on fresh book. It is much faster than other propitiatory desktop operating systems.

Normally, a home compute have SATA hard disk ( 300 Mbps for SATA 2.0 and 600 MBps for SATA3.0. Now a days, USB 3.0  comes with 150 MBps and upto 200GB !

My Objective

1-Being Linux professional, use Ubuntu Linux for all daily work I do at home. So, install and run desktop OS from a USB Flash drive and Propitiatory  OS only when firmware need to be upgraded ( most vendor do not release firmware for Linux !). I have achieved it !
2-Bring your operating system in where ever you go ! Use your USB to run your own Personal Desktop OS at school, office, Cafe, hotel etc.


Let me share steps.


What you need


1-A 2 GB USB drive to be used as Latest Ubuntu installer media

2-At least 8 GB Usb drive to install Ubuntu . I use ScanDisk Ultra Fit USB 3.0 Flash drive - 32 GB (SGD 16) 

Prepare Install Media


1- Download latest Ubuntu iso : http://www.ubuntu.com/download

2- Download Rufus . Use it to burn Ubuntu iso on USB flash drive you are intended to use as installer : http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-windows

If you are already on one of Ubuntu system, use Startup Disk Creator to burn iso on USB Srive

3-Boot Ubuntu from installer USB. You may need to change boot order in setup. Usually accessed by F2 key when pressed during POST. F12 - one time boot menu. Turn off Secure Boot if your BIOS has this option.

This installer USB is a FAT32 filesystem and it will not save any changes you will made on this as it similar to live CD. Though, there is work-around to save your changes (if you need) - search for casper-rw. Though, this is not our interest at this moment.

4- (skip this if you can boot with USB installer) If you can not boot from installer USB with all your efforts, possibly, your system does not support USB boot , does not support USB 3.0 or you need to upgrade bios etc. You may try re-burning iso once more. Obviously, if you can not boot installer from USB, you can not install and run Ubuntu from USB too. Stop here !

5- If above fails and you wish to install Ubuntu on free space of existing disk or on second disk :
a- Burn iso on a DVD ( you have bootable DVD, right !)
b- Download macrorit disk partition expert portable version
c- Reduce your disk ( BTW can be use dor USB too) partition to free up around 8 GB
d- Follow steps somewhat similar to below to install Ubuntu ( You do not need BIOS Boot and EFI System partition ESP)

Ubuntu Installation on USB Drive

1-Boot from USB installer media prepared in above step. Open an terminal and check if installer has booted in UEFI mode:

[ -d /sys/firmware/efi ] && echo "EFI boot on HDD" || echo "Legacy boot on HDD" ]

2- Select "Install Ubuntu". Refer : http://www.ubuntu.com/download/desktop/install-ubuntu-desktop . Select language, contact to wifi, Check both check boxes - to install update and third party update.

3- Plug in USB Flash drive on which you are going to install Ubuntu. Identify USB correctly and destroy partition table and create GPT disklabel. [ CAUTION: identify USB correctly, this operation is destructibve ]
         dd if=/dev/zero of=/dev/sdX count=100
         eject  /dev/sdX
         ( re-insert USB to re-read partition
         parted /dev/sdX mklabel gpt

4-You must select "Something Else" in installation type. It will allow you to manual partition USB Drive

5- USB Partition : You must have minimum 3 partition. swap partition (point c) can be ignored, though it is recommended.
Note : If you  do not see BIOS Boot and ESP partition option in below steps, installer has not booted in UEFI mode. So, you  will not be installed Ubuntu in UEFI mode. But you can install it in Legacy mode. It mean, your flash drive will not appear as boot device on other system that support UEFI. Enable UEFI in system setup and again if you need to install it in UEFI mode.

a- A 10 MB partition "BIOS boot" partition - Unformulated, no filesystem on it, no mount point, Set bios_grub flag on it ( it is required by GPT partition type - ignoring details discussion here)

b- A 100 MB  flag "EFI System Partition - ESP". DO NOT select mount poin /boot/efi and DO NOT select to format it as vfat32  ( ESP is a variant of vfat32 for not exact vfat32). Selecting ESP partition will automatically will set boot and esp flags on it. Leave mount point blank as installer know what to do with this. More detail is here.
c- 1 or 2 GB Swap partition of "Linux swap" type

d - All remaining space as - ext4 Linux FIlesystem, format it

Important Note #1 :You MUST select your USB drive in "Device for boot loader installation"

6- Select Download updates while installing and Install this third-party software now. It will install many 3rd party packages that Ubuntu repository do not have because of Licensing issues.

7- Go ahead and kick off installation and grab a coffee you deserve ! Once you will be back,  Installation might be completed. Take out installation media, label it, keep it safe ( Trust me, you  need it in future). Reboot system. If USB is your first boot device, your Ubuntu will be on your screen in 2 minutes. If required, bring one time boot menu, select USB flash drive, boot it.

8-Is your newly installed Ubuntu is portable and you can use it on any other systems ?  Hint : If you see UEFI : USB 3.0 ScanDisk (32GB), [ see this image]. It depends how much attention you paid to Important Note #1. Try to boot some other system to boot from USB.

Important Note #2 :If you do not see a boot option similar to above, it indicate that boot loader was installed on some other existing ( first hard disk) disk that already had a UEFI ESP. Follow steps on my next blog.

Important Note #2 : There is fantastic tool boot-repair is you have messed up you windows boot manager or installer USB boot record.

Also see https://www.ventoy.net/en/index.html to boot multiple Linux from USB

No comments:

Post a Comment