With the latest Raspberry Pi 3 (from now on referred to as Pi 3) which its CPU is about 10x faster than Raspberry Pi 2, and with built-in WIFI and bluetooth connectivity, the option to run a full fledge version of Ubuntu O/S is available for all Ubuntu fans. Moreover, running a full fledge version of Ubuntu allows you to use your Pi 3 as a desktop PC, and continue to use your favorite applications on Pi 3 for your daily work.
You can get official Raspberry Pi NOOB here:
Unfortunately, there is no image of Ubuntu 16.04 LTS there.
In this article, I will share with you the steps I had taken to install Ubuntu 16.04 LTS for Raspberry Pi 3 to Berryboot boot manager I had installed (please read article titled “Optimizing Raspberry Pi 3 environment”). Ubuntu 16.04LTS core version is not available by default for download on Berryboot, so we need to prepare a image with the format required by Berryboot and then supply it to Berryboot via USB device.
Preparing Ubuntu 16.04 LTS from official wiki is available at https://wiki.ubuntu.com/ARM/RaspberryPi
1. Download the image for Pi 3, ubuntu-16.04-preinstalled-server-armhf+raspi3.img.xz at http://www.finnie.org/software/raspberrypi/ubuntu-rpi3/ubuntu-16.04-preinstalled-server-armhf+raspi3.img.xz
2. Make sure you have the utility installed. We will need the following packages :-
You can install using the command :-
sudo apt-get install xz-utils kpartx squashfs-tools
3. You need to uncompress the .xz file, use the unxz command :
Wait for the OS prompt to be displayed on the next line, which indicates that the uncompress process is done. Check your folder now, you should have a .img file with the same name as the .xz file.
4. Typically, a Raspberry Pi image (the .img files provided by Linux distribution, such as the one you downloaded earlier) consists of two partitions, a smaller one for booting up and another larger one is for data. To manually add an O/S to BerryBoot, you will need to extract the larger partition and convert it to appropriate format. You can use the utility kpartx to access partitions in a .img file. You can make the partitions from the .img file mountable.
Access the .img file using kpartx by using the following command :
sudo kpartx -av ubuntu-16.04-preinstalled-server-armhf+raspi3.img
From the output of kpartx command, we can see there are two partitions with size of 8192MB and 270336MB respectively. The second larger partition is the one we want to convert to Squash FS to allow it to be imported by BerryBoot. Note that loop1p2 representing the larger partition as shown by kpartx output above. In your environment, loop<n>p2 might be shown, where <n> is any number. Please use the <n> shown in your environment for next few commands. In my steps below I will continue to use loop1p2.
5. Mount the second partition by the following command :
sudo mount /dev/mapper/loop1p2 /mnt
No message from the mount command is good news. You can double check if the mount is successful by issuing a simple ls command, such as :
If you could see subfolders similar like those shown in picture above, you have successfully mount the larger partition.
6. As Raspberry Pi has built-in microSD card slot and most linux distro would map it as /dev/mmcblk0. Some linux distro would hard-code this piece of information in /etc/fstab file of its image. Other linux distro would have used LABEL= in /etc/fstab, just like the image we are converting. Regardless of styles used for /etc/fstab, before you convert the image format to the one BerryBoot needs, you need to comment out all lines because BerryBoot will manage the location to store the image. This is especially important for storing on NON-microSD based storage, such as USB storage devices, for faster access. However, BerryBoot needs one line in /etc/fstab for it to work, and the line is :
proc /proc proc defaults 0 0
We need to prepend the above “proc” line to /etc/fstab after we commented out all lines in it.
7. To check the existing content of /etc/fstab, you can use the cat command :-
As seen above, for this ubuntu image, there is no reference to /dev/mmcblk, but it has LABEL= instead. You can either use a text editor such as nano or vi to edit the /etc/fstab file, or use these 2 sed commands to do the trick :
sudo sed -i 's/^\([^#]\)/#\1/g' /mnt/etc/fstab
sudo sed -i '1s/^/proc\t\/proc\tproc\tdefaults\t0\t0\n/' /mnt/etc/fstab
If you issue another cat command to check, you should see that the lines with LABEL= has been commented out ( a line started with # will be ignored), and a new line which starts with “proc” has been prepended.
If you use text editor instead, make sure you add the “proc” line as the first line, and add # to the beginning of all other remaining lines.
8. Next step is to convert the larger partition to Squash FS, using the command :-
sudo mksquashfs /mnt converted_ubuntu-16.04-preinstalled-server_for_berryboot.img -comp lzo -e lib/modules
A progress bar will be shown if the conversion process started. It will takes a while for the operation to complete. Please wait until the operation is completed before proceed to the next
This command basically converts and optimizes the image with SquashFS file system. The parameter -e is to instruct the command to leave out the lib/modules which are shared among the distributions in BerryBoot
The result would be another .img file, named for clarity purpose as :-
in the current folder. Feel free to use any file name you like but your file name should have .img as the file extension.
The next screenshot is what you should see after a successful conversion.
9. You can now unmount the /mnt, and remove the /dev folders created by kpartx with these commands :-
10. Copy the converted_ubuntu-16.04-preinstalled-server_for_berryboot.img file to a USB storage device which you can plug in to Raspberry Pi later.
11. Insert the USB storage with the .img file above to one USB port of your Raspberry Pi while it is in off state. Boot up the Raspberry Pi with BerryBoot installed, you should see a menu like this :
Click “Edit menu” to get to the boot menu setup page.
12. You should get to the boot menu management screen, as shown below :
The “Add OS” button, if you long click on it, it will show you a drop down, select “Copy OS from USB stick” to continue.
13. You should see a file open dialog next. Navigate to the USB device and folder where you store the converted_ubuntu-16.04-preinstalled-server_for_berryboot.img file, select the file and click Open.
14. Wait for BerryBoot to copy the image and create a new OS entry for you.
15. After copying is done, you should see a new OS entry in the OS selection list. As you can see, the image we had created appears in the list to be selected.
16. Proceed to highlight the OS you added, then click “Set default” so that you will boot into it automatically if you do not select other options during the next reboot.
17. Click “Exit” to reboot your Raspberry Pi.
18. When the boot menu is shown, you should see that the converted image is selected to boot by default.
19. When Ubuntu 16.04LTS boots up for the first time, you will see a lot of message generating SSH keys, which is normal as cloud-init feature is being used. (cloud-init is the Ubuntu package that handles early initialization of a cloud instance.) I recommend you to connect your Raspberry Pi to the Internet via Ethernet cable when booting up for the first time so that necessary cloud-based initialization can be carried out.
20. Once you get the login prompt, you can login with user name “ubuntu”, password “ubuntu”, for the first time. You will then be prompted to change the default password before you can continue to use the new Ubuntu 16.04LTS on your Raspberry Pi.
21. The first two commands I suggest you to run are :
sudo apt-get update
sudo apt-get dist-upgrade
These commands will make sure you have the latest up-to-date Ubuntu 16.04LTS experience while using it.
22. Congratulations to you. You have successfully converted a standard Raspberry Pi OS image to those which you can install and multi-boot via BerryBoot boot manager. You can use the same method to convert more standard Raspberry Pi OS images and multi-boot among them via BerryBoot.