How to Customize an Ubuntu Installation Disc – The Right Way (16.04 Compatible!)

If you’re like me, you’ve wanted to customize an Ubuntu install DVD for a long time – but all the tools/directions for doing it are out of date and/or broken. Look no further!

I have successfully customized an ISO of Xubuntu 14.04 for my project Builduntu but this guide should work for just about any flavor of Ubuntu, maybe even other Linux distributions. If you aren’t sure, give it a try! Mint and Debian are very similar and may work with minimal changes to the commands (ie, replace apt-get with whatever package manager the particular distro uses). It helps if the distro you want to customize is the same as what you are running currently, but is not necessary.

Let’s get to it.

First download the ISO you want to start customizing from Ubuntu’s release server. Remember where you save it, because you’re going to have to move it in a minute.

From here on out, it’s bash command line. Don’t worry, it’s the easiest way of doing this (for now). You don’t need to be a Linux guru, just pay close attention to the directions and it will work fine.

Make sure the prerequisite software is installed for unpacking and repacking the image. Open a terminal and run:

sudo apt-get install squashfs-tools genisoimage

Create a fresh folder to begin work. For the purposes of this guide, everything will be done from the starting point of the user’s home directory (indicated in Linux by a tilde “~”). Approximately 10 gigabytes total of free hard drive space is required for decompressing the ISO filesystem and repackaging it at the end.

mkdir ~/custom-img

Move the base ISO downloaded in the first step to the working directory. From here on out, replace “ubuntu.iso” with the name of the image downloaded from the Ubuntu Release server ex. trusty-desktop-amd64.iso

cp /path/to/saved/ubuntu.iso ~/custom-img
cd ~/custom-img

Next, extract the contents of disc image.

mkdir mnt
sudo mount -o loop ubuntu.iso mnt
mkdir extract
sudo rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract

Here’s where things start to get interesting. Extract the filesystem with the following commands:

sudo unsquashfs mnt/casper/filesystem.squashfs
sudo mv squashfs-root edit

You’re going to need network access from within the chroot environment to download and install updated/new packages. Essentially what’s happening is you are going to “log in” to a command line instance of the Ubuntu installation, separate from the host system. Perhaps a confusing concept to wrap your head around at first, but it makes sense when you think about it. Copy resolv.conf from your system into the freshly unpacked fs.

sudo cp /etc/resolv.conf edit/etc/

Mount a few important working directories:

sudo mount --bind /dev/ edit/dev
sudo chroot edit
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devpts none /dev/pts

Now you are actually logged in to the installation instance as root. Neat. Before making changes, a few commands will make sure that everything goes smoothly while modifying packages.

export HOME=/root
export LC_ALL=C
dbus-uuidgen > /var/lib/dbus/machine-id
dpkg-divert --local --rename --add /sbin/initctl
ln -s /bin/true /sbin/initctl

OK, now you can start playing around. This guide is only going to cover adding and removing software, but it’s possible to customize just about anything. Things like custom backgrounds and settings are already documented elsewhere, but be careful! Many of the directions are outdated and the commands may need slight alterations to work correctly. I had to piece this guide together from a few different sources with a whole lot of dead reckoning.

Start by removing the packages you don’t want. Be sure to use the “purge” command so that the system will automatically uninstall and delete the package, which optimizes the space required for the ISO. When you execute purge, read the list of programs to be removed before you select “Y” and make absolutely sure you haven’t accidentally flagged a core system package via association. You will recognize this because the list will contain significantly more packages than those you selected.

apt-get purge package1 package2 package3

I personally remove games, scanning utilities (I don’t have a scanner) and default text editors like abiword and mousepad (geany is the best). Stay away from core components unless you know what you are doing.

Since I am customizing a 64-bit Ubuntu image, I need multiarch (i386) support for some of the programming libraries. The following command is not necessary for everyone, but I recommend it anyway.

dpkg --add-architecture i386

Update the software repositories and upgrade the remaining packages on the system.

apt-get update && apt-get upgrade

Add packages to the system the usual way:

apt-get install package1 package2 package3

You are almost there! Time to clean up:

apt-get autoremove && apt-get autoclean
rm -rf /tmp/* ~/.bash_history
rm /var/lib/dbus/machine-id
rm /sbin/initctl
dpkg-divert --rename --remove /sbin/initctl

Unmount the directories from the beginning of this guide:

umount /proc || umount -lf /proc
umount /sys
umount /dev/pts
exit
sudo umount edit/dev

You have now “logged out” of the installation environment and are “back” on the host system. These final steps will actually produce the ISO. Other guides stop working at this point, but have no fear! The following commands have been tested and verified.

Generate a new file manifest:

sudo chmod +w extract/casper/filesystem.manifest

sudo chroot edit dpkg-query -W --showformat='${Package} ${Version}n' | sudo tee extract/casper/filesystem.manifest

sudo cp extract/casper/filesystem.manifest extract/casper/filesystem.manifest-desktop

sudo sed -i '/ubiquity/d' extract/casper/filesystem.manifest-desktop

sudo sed -i '/casper/d' extract/casper/filesystem.manifest-desktop

Compress the filesystem:

sudo mksquashfs edit extract/casper/filesystem.squashfs -b 1048576

Update filesystem size (needed by the installer):

printf $(sudo du -sx --block-size=1 edit | cut -f1) | sudo tee extract/casper/filesystem.size

Delete the old md5sum:

cd extract
sudo rm md5sum.txt

…and generate a fresh one: (single command, copy and paste in one piece)

find -type f -print0 | sudo xargs -0 md5sum | grep -v isolinux/boot.cat | sudo tee md5sum.txt

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:

sudo genisoimage -D -r -V "$IMAGE_NAME" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../name-of-your-custom-image.iso .

It takes a few minutes, but when that is done you will have a burnable/distributable ISO in your working directory (~/custom-img)

Have fun and good luck! Let me know how customizing works out for you!

If you appreciate my hard work, feel free to buy me a coconut water ( donate ). It will be greatly appreciated!

  52 comments for “How to Customize an Ubuntu Installation Disc – The Right Way (16.04 Compatible!)

  1. umi
    March 27, 2014 at 4:31 am

    Can this step be use on ubuntu server?

    • sylentprofet
      March 28, 2014 at 3:51 am

      Yes. Just change the name of the ubuntu.iso to match the image you download and it should be fine.

      • umi
        March 28, 2014 at 7:27 am

        but i cannot file the casper/filesystem.squashfs in ubuntu server iso. i only found it on ubuntu desktop. is in any chance i did miss something?

        • Alex
          January 25, 2017 at 4:05 am

          Ubuntu server does not have casper, so it’s a completely different process to customize that (although a lot easier), as there is no compressed filesystem on that iso.

          Loads of guides on the net for that, and they all work.

  2. Techgs
    April 18, 2014 at 2:55 pm

    Lol… You deserver to be donated. Excellent work. Think of creating shell scrip or may be python script… Suggest some packages to be removed ( like thunderbird,sudoku, ) some packages to be added ( mc, cheese, chromium, jre, jdk )

  3. necat
    April 21, 2014 at 7:16 pm

    Please mak e ascript for it :/ any other projects: remastersys, uck has been discontinued. 🙁

    • sylentprofet
      June 7, 2014 at 3:40 am

      Testing v0.1 now. Stay posted!

  4. Meral
    May 1, 2014 at 10:12 am

    Please make a script 🙁

    • sylentprofet
      June 7, 2014 at 3:39 am

      I’m almost done with one. Just in final testing phases of v0.1

  5. Serhat
    May 4, 2014 at 2:43 pm

    Hi,

    First thanks for your sharing.

    I want to ask if these all operations will work under a Ubuntu Live (Not installed system). I can put 2 HDD (Ubuntu Live ISO USB and Empty at least 10 gb HDD) on my machine. Than I can generate my ISO, with live system by mounting 10 GB HDD as “custom-img” ?

    And I want to ask if there are project to generate Custom ISO? I research them for years but some of the project are discontinued, or they are alpha, or they are not deseign for Ubuntu (and it’s variants).

    reconstructor: they want money. even I can not try without paying.
    remastersys: discontinued
    Ubuntu Builder: discontinued
    relinux: it is beta, which also it is not updating since 2 years.
    mklivecd: is on the 0.0.1 version since 2002
    ubuntu-customization-kit: I could not install it on fresh install ubuntu. which is also not updating since 2 years.
    liveCD: on their official site they write that they are support Mandrakelinux PCLinuxOS

    • sylentprofet
      June 7, 2014 at 3:36 am

      To answer your first question, yes I think this may work under a Live System. As long as you aren’t building on the File System, which is limited to the amount of RAM you have available.

      I’m working on a script for customizing the ISO. It’s a bit different in bash than just typing the commands, but it should be ready for release soon.

    • ipkpjersi
      November 9, 2016 at 1:56 pm

      I modified and merged the commands together. I tested this and it made an ISO that worked fine for me:

      first sudo chmod 777 /home/yourusernamehere/ and copy the ubuntu image over to /home/yourusernamehere/, then run this from /home/yourusernamehere/:

      mkdir ~/custom-img
      cp ubuntu* ~/custom-img/
      cd ~/custom-img
      sudo apt-get install squashfs-tools genisoimage -y
      mkdir mnt
      sudo mount -o loop ~/custom-img/ubuntu*.iso mnt
      mkdir extract
      sudo rsync –exclude=/casper/filesystem.squashfs -a mnt/ extract
      sudo unsquashfs mnt/casper/filesystem.squashfs
      sudo mv squashfs-root edit
      sudo cp /etc/resolv.conf edit/etc/
      sudo mount –bind /dev/ edit/dev
      sudo chroot edit
      mount -t proc none /proc
      mount -t sysfs none /sys
      mount -t devpts none /dev/pts
      export HOME=/root
      export LC_ALL=C
      dbus-uuidgen > /var/lib/dbus/machine-id
      dpkg-divert –local –rename –add /sbin/initctl
      ln -s /bin/true /sbin/initctl
      apt-get update && apt-get dist-upgrade -y && apt-get install zfsutils-linux -y && apt-get install openssh-server -y && apt-get install samba -y && update-grub && update-initramfs -u
      dpkg –add-architecture i386

      then once verified everything has installed (keep in mind as a side note, no sudo commands can be execited until we exit out of sudo chroot edit seen below before executing a sudo umount, that’s why we don’t sudo update-grub):

      apt-get autoremove && apt-get autoclean
      rm -rf /tmp/* ~/.bash_history
      rm /var/lib/dbus/machine-id
      rm /sbin/initctl
      dpkg-divert –rename –remove /sbin/initctl
      umount /proc || umount -lf /proc
      umount /sys
      umount /dev/pts
      exit
      sudo umount edit/dev

      then verify that sudo worked and did not give a sudoers error, if it did reboot then continue, if not just continue:

      cd ~/custom-img
      sudo chmod +w extract/casper/filesystem.manifest
      sudo chroot edit dpkg-query -W –showformat=’${Package} ${Version}n’ | sudo tee extract/casper/filesystem.manifest
      sudo cp extract/casper/filesystem.manifest extract/casper/filesystem.manifest-desktop
      sudo sed -i ‘/ubiquity/d’ extract/casper/filesystem.manifest-desktop
      sudo sed -i ‘/casper/d’ extract/casper/filesystem.manifest-desktop
      sudo mksquashfs edit extract/casper/filesystem.squashfs -b 1048576
      printf $(sudo du -sx –block-size=1 edit | cut -f1) | sudo tee extract/casper/filesystem.size
      cd extract
      sudo rm md5sum.txt
      find -type f -print0 | sudo xargs -0 md5sum | grep -v isolinux/boot.cat | sudo tee md5sum.txt
      sudo genisoimage -D -r -V “$IMAGE_NAME” -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../ubuntu-custom.iso .
      ls | grep hi

      P.S. Thanks OP, I will send a donation your way. 😀

  6. Michael
    May 14, 2014 at 12:17 pm

    how do you configure the target installation to use a proxy for the apt-get operations?

  7. SPV
    June 14, 2014 at 9:40 am

    mkisofs has been deprecated. instead replace it with genisoimage

  8. Bob
    August 12, 2014 at 4:45 pm

    I followed your directions and wow, great thanks. I have built a custom kernel image and while I am in the chroot env, I tried to install it. I was able to fix up the /etc/mtab file such that it has a rootfs, and then I did the dpkg -i custom-kernel-image.deb. It appears to install ok and in the edit directory I can see kernel installed. but when I use the iso image to install a machine, it it still on the generic kernel… and the directories dont have my new customer kernel. am I missing somthing?

  9. August 14, 2014 at 8:11 am

    It works with Ubuntu server 14.04. The only change that needs to be made for it to work is to change the ‘/casper/’ directory to ‘/install/’ when using this guide. Thank you for the guide. Funny enough it was way easier than getting remastersys or relinux to work. Keep up the good work. I am a python fan so would like to see that finished python script

  10. September 25, 2014 at 4:27 pm

    Is it possible to create my existing ubuntu 14.04’s image to install it other computers or this procedures only changes the new iso extracted from the image and recompressed as iso.

    • October 7, 2014 at 12:33 pm

      I’m not sure how well it works, but there is a program called Black Lab Imager that is a continuation of the remastersys project. The source code is free, but the team is asking for a one-time donation for access to a binary executable. Give it a try!

  11. David
    November 18, 2014 at 11:50 am

    Tried this on Ubuntu Server 14.10 iso. There were a LOT of dependency issues along the way that had to be resolved. I got them resolved, but then it throws me more troubles. Toward the end it didnt want to unmount anything. It kept saying it was busy. So I had to forcefully unmount the things.

    Creating the ISO itself went fine. After this I booted the ISO into a virtualbox and tried it. It started off going well. It booted up the Ubuntu installer as expected and went through the whole process. However, after reboot it freezes. It just wont boot into the system. I dont know why but something is obviously wrong.

    • November 21, 2014 at 8:21 am

      I’m gonna work on updating this guide for 14.10 soon. There may need to be some slight modifications to the commands.

      Were you building the ISO from inside of a 14.10 installation? Or were you trying to customize a 14.10 disc on a system with a 14.04 or earlier install? The main issue I can think of with dependencies etc would likely be caused by trying to customize a “newer” release from within an older host installation.

      Let me know if you have any luck! Like I said at the top of the post, some people are running into issues but others are able to get things working with a few minor changes to the commands.

      • David
        December 18, 2014 at 2:16 pm

        Well, I have a little free time to try and do this again so I am trying to work through it. The first error I am coming up to is where you have “dbus-uuidgen > /var/lib/dbus/machine-id”.

        when i put this in it states “no such file or directory”. when i type “dbus-uuidgen –help” it says “command not found”. i then go to a separate terminal and try “dbus-uuidgen –help” and it works fine. are the steps out of order for this? while in the “chroot edit/” terminal it just doesnt work.

        • David
          December 18, 2014 at 5:55 pm

          Update:
          I proceed to go on past the “dbus-uuidgen” not working right. i figured it wouldnt affect much anyway.

          most everything else seems to have gone alright. unmount things seems buggy. everything complained it was busy with the commands given. so i added the “-lf” switch on all of them. i could not exit after that because then it said there where “stopped jobs”. so then i just closed the terminal to kill it.

          after that i opened a new terminal and changed directory over to ~/custom-img and continued on. generating the iso gave me no problems.

          installation gave me one minor error with the “select and install” portion. apparently it didnt like one of the packages. probably modemmanager in gnome since thats the only one in the whole process that gave me an issue. so your mileage may vary on this. after i went in manually and hit apply it continued the installation.

          the system seems to have installed everything i asked it to install which is good. i ran playonlinux with a game and it seemed to going good. so i am going to say that its working.

          started with Ubuntu 14.10 64bit desktop installed on virtualbox. used apt-get update and apt-get dist-upgrade to make sure the host system was fully updated. i used Ubuntu 14.10 64bit server to build the image since server is a minimal install and you dont have uninstall a billion things. you just go in and install everything you want on top of it.

    • Rick Galbraith
      May 17, 2016 at 12:45 pm

      Sounds like you need to find a point to restart the process and try again. What you created may be a coaster.

  12. A.S.
    February 1, 2015 at 7:36 am

    Hi there,
    I am looking for a way to replace the live session user with my preferred username and also to avoid direct boot to the live user. I’d rather prefer the lightdm greeter screen to pop up and allow me to insert my credentials.

    I have the squashfs filesystem extracted as we speak but cannot find any relevant information regarding how to alter those. See this question of mine for more details. Do you have any idea how I should tackle this matter?

    Thank you for your help!

    • February 4, 2015 at 10:41 pm

      My best recommendation would be to read through the Live CD customization documentation provided by Canonical. It’s not the most reliable or up-to-date, but you might be able to modify some of the commands to work for modern versions. Some of the structure hasn’t been valid for 4 or 5 years, so your mileage will vary. Good luck!

  13. Michael Gregg
    February 21, 2015 at 12:02 am

    That worked! Thanks!

    How do I edit the list of packages that get installed?

    • February 24, 2015 at 10:37 am

      Use apt-get just as the directions mentioned. The packages that are added/removed during this process will be mirrored to the installation system.

  14. David
    March 20, 2015 at 12:16 pm

    been playing around with this some more and just wanted to post about this step up top:
    “sudo mksquashfs edit extract/casper/filesystem.squashfs -b 1048576”

    i believe if it is changed slightly it compresses it more.
    “sudo mksquashfs edit extract/casper/filesystem.squashfs -comp xz -b 1M -Xdict-size 100%”

  15. Jesse Millwood
    August 12, 2015 at 12:54 pm

    Has anyone gotten this method to work with the ubuntu-mini-remix?

  16. August 28, 2015 at 3:57 am

    Would not having wireless driver on my computer affect the installation. When I start, it says package not found

    • August 29, 2015 at 9:53 pm

      Did you copy resolv.conf from your system to the mounted filesystem? That’s important for network access during the editing process.

  17. David
    April 12, 2016 at 6:49 pm

    16.04 compatible.
    I have built one up starting with the server iso.

  18. Bob
    April 28, 2016 at 7:18 pm

    This is a fantastic tutorial. I successfully made a custom Xubuntu CD with this (though it had a few bugs because of a botched Java installation; I will try again). I’m trying to use it to alter TAILS a little and am running into the following error:

    ~/custom-img/extract$ sudo unsquashfs mnt/casper/filesystem.squashfs
    Could not open mnt/casper/filesystem.squashfs, because No such file or directory

    • Bob
      April 28, 2016 at 7:38 pm

      I’m sorry for not specifying that the successful custom CD was Xubuntu 16.04 and the failed one was TAILS 2.3.

      • David
        April 30, 2016 at 6:46 pm

        looking up TAILS it looks like it is a Debian system. which as i recall is not even the same kind of directories or anything. you should be able to just look at the folders on the mounted ISO and determine if any of this is going to work.

        the directories you are obviously looking for as above:
        ../casper/*
        or
        ../install/*

        which if they are there then you look in them and see if they have the files you want.

  19. Jayaraj
    May 8, 2016 at 12:33 am

    During the installation it shows “failed to install grub-efi to /target/ the system will not boot”
    it’s okey when installing with internet, but i want to install it offline. can you please help me?
    THANK YOU VERY MUCH for this post.

  20. Ivan
    May 21, 2016 at 9:11 am

    Great! Excellent! First guide which really work’s! In one word, excellent! I’m thrilled! Thank You very, very much.

  21. May 26, 2016 at 2:14 pm

    always stuck at genisoimage. can’t make iso. how to solve this? thanks.

    • May 26, 2016 at 5:04 pm

      Can you provide some error output? It’s hard to help without knowing more about the situation.. It is likely you’re either missing the genisoimage package, or typing the command incorrectly.

  22. Andy
    June 8, 2016 at 9:34 am

    Thanks for this script – looks very good with the current version of ubuntu-mini-remix-16.04-amd64.iso.
    There are no error while creating. ISO starts with VMWare Fusion – no problem –
    But if I do create a DVD or a USB stick from this iso – it doesn’t start up. BIOS settings for boot are set properly.
    Any idea ?

    • David
      June 21, 2016 at 8:41 am

      that sounds more like boot disc creator issue than anything else. granted i have ran into those problems before which i have found it to be either the USB creator i was using or the burning program not acting right. its kind odd like that.

      also, make sure your USB is FAT32 formatted with a bootable flag. sometimes those things, especially the large ones, can end up NTFS or exFAT formatted which doesnt always work. the USB creators also dont all format the drives. some just put the files on the disk.

      at least the good thing about USB is you dont waste a lot of disks trying to make it work. right?

  23. Thomas Stanton
    August 15, 2016 at 8:07 am

    Thank you, we found this very helpful, keep up the great work.

  24. Nicholas Estrada
    September 12, 2016 at 9:13 am

    How does one add software from a non-default repository to the install disk? I keep trying to add a repo with wget and it says host (my localhost name) could not be found.

  25. September 16, 2016 at 10:41 am

    Consider also https://apps.ubuntu.com/cat/applications/precise/uck/ the Ubuntu Customization Kit.

    • September 19, 2016 at 8:21 am

      I have tried many of the various tools available, including UCK. However, that specific app has not been updated since Ubuntu 13.10

      It might work for older distributions, but for anything above 14.04 it never produced a viable image for me, hence the guide here.

      Thanks for the suggestion!

  26. October 21, 2016 at 12:09 pm

    Thank you, perfect for providing custom live systems! 😉

  27. tuxintuxedo
    November 5, 2016 at 2:10 pm

    Hello. Thank you for the guide.
    My only problem is, that I cannot make the new ISO work with an updated kernel. Only kernels which are in the original repositories work, I always get kernel error when booting if I try a kernel from kernel-ppa/mainline. Any ideas?

    • David
      November 28, 2016 at 8:43 am

      That sounds kinda odd tbh. I have a 16.04 image and it comes with something like kernel 4.2 i think. I always update the kernel to the newest “STABLE” release from the mainline repository though. It has never failed me either.

      -make sure you are downloading all of the correct files. (ex. all low-latency or all generic and with the correct format 32bit/64bit)

      -when you go to install them there should be 3 files. (ex. “linux-headers…all.deb”, “linux-headers…amd64.deb”, and “linux-image…amd64.deb”) To install go to their folder and do “dpkg -i linux-headers*” followed by “dpkg -i linux-image*”

  28. Dave
    January 30, 2017 at 12:36 am

    Doesn’t seem to work with elementary -loki which is based on 16.04
    Everything is fine except once I start using apt I get a bunch of permission errors that keeps me from being able to install anything. fchmod operation not permitted in the apt/partials temporary file. I tried to to chmod -R 777 the apt directories… nada… any ideas??

    • Dave
      January 30, 2017 at 3:23 am

      ahhhh weird… everything worked if I sudo -i and run all commands from the /root which is where you land anyway. sudo works this way btw

Leave a Reply

Your email address will not be published. Required fields are marked *