Skip to content

Instantly share code, notes, and snippets.

@vgezer
Last active November 29, 2021 14:43
Show Gist options
  • Save vgezer/da81d27ec922882f2502 to your computer and use it in GitHub Desktop.
Save vgezer/da81d27ec922882f2502 to your computer and use it in GitHub Desktop.

Preparing BerryBoot Images

What is BerryBoot?

For people short on SD cards: Berryboot is a simple boot selection screen, allowing you to put multiple Linux distribution on a single SD card. In addition it allows you to put the operating system files on an external USB hard drive instead of on the SD card itself.

Website

Steps are taken from BerryBoot wiki

You need to install mksquashfs and kpartx to create your own images.

Usage

  1. Download a normal IMG file from your community.

  2. If it has extension of TGZ or ZIP, uncompress to extract IMG file.

  3. Save berry.sh to your computer and give executable rights by using the following command in terminal:

  chmod +x berry.sh
  1. On a desktop PC (not from your Banana/Raspberry Pi) move the script to the same directory as the IMG file and use:
  ./berry.sh IMAGENAMETOCONVERT

After some time you the new image will be created in the current folder as: IMAGENAMETOCONVERT_berryboot.img

Note: You need administration rights to perform these steps. Use your administrator/root password.

#!/bin/bash
type /sbin/kpartx >/dev/null 2>&1 || { printf >&2 "\033[31mkpartx is required, but not installed. On Debian/Ubuntu (and derivatives) use: \nsudo apt-get install kpartx \n Aborting.\n\033[0m"; exit 1; }
type mksquashfs >/dev/null 2>&1 || { printf >&2 "\033[31mmksquashfs is required, but not installed. On Debian/Ubuntu (and derivatives) use: \nsudo apt-get install squashfs-tools \nAborting.\n\033[0m"; exit 1; }
if [ $# -eq 0 ]
then
echo "No image file specified. Stopped."
echo "Usage: ./berry.sh IMAGEFILE.img"
exit 1
fi
imagefile=$1
outputimage=${imagefile%.img}
echo "Using image: $imagefile"
echo "Mounting all the partitions in $imagefile"
sudo kpartx -av $imagefile
sleep 1
echo "Mounting device map to /mnt"
sudo mount /dev/mapper/loop0p2 /mnt
sleep 1
echo "Adding device to fstab"
sudo sed -i 's/^\/dev\/mmcblk/#\0/g' /mnt/etc/fstab
echo "Creating squashfs filesystem as image"
sudo mksquashfs /mnt ${outputimage}_berryboot.img -comp lzo -e lib/modules
echo "Cleaning up..."
sudo umount /mnt
sudo kpartx -d $imagefile
printf "\033[32mDone. The image for BerryBoot is ready at location: ${PWD}/${outputimage}_berryboot.img\033[0m\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment