Posts: 7
Joined: Wed Jul 29, 2015 2:38 am
Location: Minneapolis. MN

HOW TO: Create Berryboot Images For Difficult Distributions

Thu Jul 30, 2015 2:59 am

Specifically, I'm going to explain how I created a Berryboot image for "ubuntu-mate-15.04-desktop-armhf-raspberry-pi-2.img" but I believe the general concept can be extrapolated for use with other distributions.

Requirements: Working Linux system with "squashfs-tools" and "kpartx" packeges installed to be used for editing.

The image that I dealt with is somewhat unique in that the "virgin" image when copied to a microSD card and booted starts by running ubiquity in a specialized O.E.M. install mode. This is both a blessing and a curse. It is a blessing in that it forces one to install the image to a microSD card and run it at least once which I maintain is wise with an image for the R.Pi 2 and it is a curse because you cannot operate directly on the image as it was downloaded in the original downloaded state.

The Berryboot loader for the R.Pi 2 contains a broken version of "mksquashfs" so you will be unable to make a backup copy using the Berryboot menu of any images "WITH CHANGES" once the image is installed into a Berryboot managed system. (Making a backup copy can be done, just not by using the Berryboot menu.)

Hence if you wish to deploy a Berryboot compatible image multiple times it is best to make as many changes and install as many packages as you can think of on a system that was booted using the distribution's native R. Pi bootloader before you create your Berryboot compatible image.

While booted into one of your sessions using the distributions bootloader, open a terminal window, execute the command "ps -p 1 -o command" in the terminal and make a note of the output from the command.

It is my belief that after the Berryboot system initializes and mounts the squashed filesystem it will try to load either the "init" file located under "/sbin/" or the ""systemd" file located in the path "/usr/lib/systemd/" into memory and start executing this file. The output from your "ps" command must point to one of these two locations or you will need to perform some additional steps, which I will not detail.

While still in the terminal window (assuming the output of the "ps" command was "/sbin/init") , execute an "ls -l /sbin/init" command and determine if the init file is a symlink that points to a file elsewhere in the system. While Berryboot can accommodate symlinks to a certain extent during the load operation, Berryboot has no real understanding of the file layout of the squashed filesystm it mounted. Thus Berryboot cannot resolve symlinks which use absolute path names. In other words a symlink with the "init" label which points to the absolute pathname file "/lib/systemd/systemd" is not acceptable but the same "init" label pointing to the relative pathname file of "../lib/systemd/systemd" is aceptable. If the output from your "ps" command indicates a symlink with an absolute pathname file, it will be necessary at some point to delete the symlink and recreate it with a relative pathname and the same label. While you could change the symlink now on your running system and your system would still boot correctly, I advocate waiting until later in the process because there may be more changes that are neccessary.

Now I believe you have the minimum information necessary and you can power down and create a backup copy of your microSD card using either win32diskimager or "dd" if you're an experienced linux user.

Now start your other linux system which you are going to use for editing and begin to follow the steps on the Berryboot site for "Adding your own custom operating systems to the menu" from the Berryboot site. Stop following the steps before the step that begins "sudo sed -i 's/^\/dev\/mmcblk..." and instead first execute the command "sudo cp /mnt/etc/fstab /mnt/etc/fstab.bak". Then perform edits manually with "sudo nano /mnt/etc/fstab" and insert a "#" symbol at the beginning of each line that begins "/dev/mmcblk...". This will make that line in fstab appear as a comment line. When you have finished with changes to each "/dev/mmcblk..." line type "Ctrl o" and save the file followed by a "Ctrl x" to exit. Now it is time to address the symlink issue. Navigate to "/mnt/sbin" in a new terminal window and rename the "init" label to "init.bak". ("sudo mv ./init init.bak"). Now create a new symlink with "sudo ln -s ../lib/systemd/systemd init". Close this terminal window. Continue on to make the squashfs as in "Adding your own custom operating systems to the menu" but omiting the step that began with "sudo sed -i 's/^\/dev\/mmcblk..." in its entirety. Once the squashfs is created and before the step that begins "sudo umount /mnt" you may wish to reverse the changes you have made or your "backup image" will no longer be a viable backup image as the changes you have made have been made in your backup image file. Finally, you can "sudo umount /mnt" to unmount your image and "sudo kpartx -d image_you_want_to_convert.img" to destroy the loop.

A final step is required for the "Ubuntu Mate 15.04" image once you have successfully booted it using Berryboot. This shouldn't be necessary for other distributions. The Ubuntu Mate image contains a custom "update-initramfs" command which by default runs after the addition of any new packages. This custom command depends on a mounted "/dev/mmcblk..." device and /dev/root which will not exist in the berryboot image and the update-initramfs command will fail. To resolve this, I edited the "/etc/initranfs-tools/update-initramfs.conf" file and changed the line which says "update_initramfs=yes" to "update_initramfs=no". There may be a more proper method to accomplish the same result but I do not know the proper method to achieve desirable results.

There will be other annoyances with the Ubuntu Mate image under Berryboot such as the manner in which USB disks are mounted which prevents access to anyone without root privileges. Thus you will probably wish to create a launcher for a "Root File Manager" either before or after you create your Berryboot image.

Good luck to any who attempt to follow my disjointed and rambling guide!

Best Regards,


Return to “Other”