Note: Pay close attention to directions and make sure to copy-paste the command rather than type it, to avoid typos. In Ubuntu using bash, you can use following commands to copy and paste: SHIFT+CTRL+C (copy) & SHIFT+CTRL+V (paste)

  1. Step 1: Download the Ubuntu iso to customize. Remember the directory where it is saved, because we would need to move it later.
  2. Install the prerequisite software, which allows you to unpack and repackage the iso with the following commasend(enter your root password upon prompt):
  1. sudo apt-get install squashfs-tools genisoimage
  1. Create a new folder for your working directory - you will require approximately 10 gigabytes of free hard drive space for decompressing and repackaging it, use the following command to create new directory:
  1. mkdir oseimage
  1. Copy the downloaded base image into the new directory using the following commands, replacing the old path, new path, and name of your ubuntu iso:
  1. cp /path/to/saved/ubuntu.iso ~/where/to/save/custom-img
  2. cd ~/custom-img
  1. Now extract the contents of the image
  1. mkdir mnt
  2. sudo mount -o loop ubuntu.iso mnt
  1. Here you will get a mount protected read-only warning, don’t worry, Iso's only do mount read-only, that is why we will extract its fs to customize in the upcoming steps
  1. mkdir extract
  2. sudo rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract
  1. Now extract the file system using following commands:
  1. sudo unsquashfs mnt/casper/filesystem.squashfs
  2. sudo mv squashfs-root edit
  1. We need access to internet in the chroot environment of the ubuntu installation to be able to add/update the ubuntu installation and its packages, we can do so by copying the resolv.conf from our system to the installation file system:
  1. sudo cp /etc/resolv.conf edit/etc/
  1. We now need to mount important directories before we can start editing the ubuntu installation
  1. sudo mount --bind /dev/ edit/dev
  2. sudo chroot edit
  1. This puts us inside the chroot environment of the ubuntu installation
  1. mount -t proc none /proc
  2. mount -t sysfs none /sys
  3. mount -t devpts none /dev/pts
  1. Following commands are need to make everything run smoothly
  1. export HOME=/root
  2. export LC_ALL=C
  1. LC_ALL is the environment variable that overrides all the other localisation settings
  2. The C locale is a special locale that is meant to be the simplest locale. You could also say that while the other locales are for humans, the C locale is for computers. In the C locale, characters are single bytes, the charset is ASCII (well, is not required to, but in practice will be in the systems most of us will ever get to use), the sorting order is based on the byte values, the language is usually US English (though for application messages (as opposed to things like month or day names or messages by system libraries), it's at the discretion of the application author) and things like currency symbols are not defined.
  1. dbus-uuidgen > /var/lib/dbus/machine-id
  1. The dbus-uuidgen command generates or reads a universally unique ID.
  1. dpkg-divert --local --rename --add /sbin/initctl
  1. dpkg-divert is the utility used to set up and update the list of diversions. File diversions are a way of forcing dpkg(1) not to install a file into its location, but to adiverted location.
  1. ln -s /bin/true /sbin/initctl
  1. Use to create a symbolic link
  1. Now we can start customizing our ubuntu installation. I will only cover adding and removing software in this guide, even though just about anything can be customized using the command line. You can remove a package by the following command
  1. apt-get purge package1 paackage2
  1. We are using purge command to remove data + config files of the package, optimizing the space required for the iso
  2. You can remove games, scanning utilities, and other unncessary packages, but stay away from core components unless you know what you are doing.
  1.  Since we are customizing a 64-bit Ubuntu image, we need multiarch (i386) support for some of the programming libraries. The following command is not necessary for everyone, but I recommend it anyway:
  1. dpkg --add-architecture i386

  1. Update the software repositories and packages before we proceed with the following
  1. apt-get update
  2. apt-get upgrade
  1. Now we are going to add the necessary packages into our ubuntu installation. We are adding FreeCAD, kdenlive, Vokoscreen, and Chromium Browser
  1. FreeCAD and FreeCAD-doc
  1. apt-get install freecad freecad-doc
  1. It will give you the error ‘unable to locate…’ and we need to first add the repository with the following commands:
  1. sudo add-apt-repository ppa:freecad-maintainers/freecad-stable
  1. Press ‘Enter’ when promoted
  1. apt-get update
  1. Now when you type ‘apt-get install freecad freecad-doc,’ you will get the error: packages have unmet dependencies. Hence, we need to grab necessary repository and add it to our sources list.  
  1. nano /etc/apt/sources.list
  2. Copy and paste the repository link: deb http://cz.archive.ubuntu.com/ubuntu xenial main universe
  3. Apt-get update
  1. Finally install freecad and freecad-doc
  1. Apt-get install freecad freecad-doc
  1. Install assembly and fasteners workbench by first adding the freecad-community repository and then installing them
  1. sudo add-apt-repository ppa:freecad-community/ppa
  2. sudo apt-get update
  3. apt-get install  freecad-extras-assembly2
  4. apt-get install  freecad-extras-fasteners
  1. Kdenlive
  1. apt-get install kdenlive
  1. Vokoscreen
  1. apt-get install vokoscreen
  1. Chromium Browser
  1. apt-get instal chromium-browser
  1. Finally update and upgrade all packages
  1. Now it is time to clean up and repackage the iso
  1. apt-get autoremove && apt-get autoclean
  2. rm -rf /tmp/* ~/.bash_history
  3. rm /etc/resolv.conf
  4. rm /var/lib/dbus/machine-id
  5. rm /sbin/initctl
  6. dpkg-divert --rename --remove /sbin/initct
  1. Unmount all the directories
  1. umount /proc || umount -lf /proc
  2. umount /sys
  3. umount /dev/pts
  4. exit
  5. sudo umount edit/dev
  1. You have now “logged out” of the installation environment and are “back” on the host system. These final steps will actually produce the ISO.
  1. Generate a new manifest
  1. sudo chmod +w extract/casper/filesystem.manifest
  2. sudo chroot edit dpkg-query -W --showformat='${Package} ${Version}n' | sudo tee extract/casper/filesystem.manifest
  3. sudo cp extract/casper/filesystem.manifest extract/casper/filesystem.manifest-desktop
  4. sudo sed -i '/ubiquity/d' extract/casper/filesystem.manifest-desktop
  5. sudo sed -i '/casper/d' extract/casper/filesystem.manifest-desktop
  1. Compressing the filesystem
  1. sudo mksquashfs edit extract/casper/filesystem.squashfs -b 1048576
  1. Update filesystem size (needed by the installer):
  1. printf $(sudo du -sx --block-size=1 edit | cut -f1) | sudo tee extract/casper/filesystem.size
  1. Delete the old md5sum:
  1. cd extract
  2. sudo rm md5sum.txt
  3. Now generate a fresh one: (single command, copy and paste in one piece)
  1. find -type f -print0 | sudo xargs -0 md5sum | grep -v isolinux/boot.cat | sudo tee md5sum.txt
  1. And finally, create the ISO. This is a single long command, be sure to copy and paste it in one piece and don’t forget the period at the end, it’s important:
  1. sudo genisoimage -D -r -V "$OSE" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../ose0.4.iso .
  1. Test the ISO using the following guide on VirtualBox - no USB creation required
  1. https://help.ubuntu.com/community/VirtualBox

The steps to unpack and repackage the iso were taken and tested from the following guides, lots of tools and guides on internet seemed to not work, including the ubuntu official guide:

https://nathanpfry.com/how-to-customize-an-ubuntu-installation-disc/

https://www.codinglogs.com/build-your-own-linux-live-distribution-based-on-ubuntu/