Custom Ubuntu Installation image

First step is to download ubuntu budgie iso from cdimage.ubuntu.com

wget https://cdimage.ubuntu.com/ubuntu-budgie/releases/20.04.1/release/ubuntu-budgie-20.04.1-desktop-amd64.iso -4

After that add the iso file to a variable called iso_file

export iso_file=ubuntu-budgie-20.04.1-desktop-amd64.iso

Make a directory called mnt and mount the iso that directory

mkdir mnt
sudo mount -o loop ${iso_file} mnt/

Now we make a directory called extract-cd where we will place the mounted directory

 mkdir extract-cd
 sudo rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract-cd

Make a directory called squashfs where will place the squashfs filesystem and we move it to a directory called edit

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

Mount /dev to /edit/dev and chroot to edit

  sudo mount --bind /dev/ edit/dev
  sudo chroot edit

Mount stuff inside chroot and set a few variables inside chroot

mount -t proc none /proc
mount -t sysfs none /sys
mount -t devpts none /dev/pts
mount -t proc none /proc
export HOME=/root
export LC_ALL=C

Setup dns inside chroot

echo "nameserver 1.1.1.1" >> /run/systemd/resolve/stub-resolv.conf

Update software sources and upgrade packages and install apache with php-fpm

sudo apt update && sudo apt upgrade
sudo apt install php-fpm php

Clean up the chroot enviroment and exit

apt clean
rm -rf /tmp/*
rm -rf /var/cache/apt-xapian-index/*
rm -rf /var/lib/apt/lists/*
umount /proc
umount /sys
umount /dev/pts
exit

Add php to the list of packages to keep

sudo echo "php" >> extract-cd/preseed/ubuntu-budgie.seed
sudo chmod +w extract-cd/casper/filesystem.manifest
sudo chroot edit dpkg-query -W --showformat='${Package} ${Version}\n' > extract-cd/casper/filesystem.manifest

Create a squashfs file from the folder

sudo mksquashfs edit extract-cd/casper/filesystem.squashfs

This indicates where to save the final iso file

export output_file=ubuntu-budgie-20.04.1-desktop-apache-remix-amd64.iso

create the iso

cd extract-cd
sudo rm -f md5sum.txt
(find -type f -print0 | xargs -0 md5sum | grep -v isolinux/boot.cat | sudo tee ../md5sum.txt)
mv -f ../md5sum.txt ./
sed -i -e '/isolinux/d' md5sum.txt
export IMAGE_NAME="Ubuntu Budgie 20.04 apache-remix amd64"
genisoimage -r -V "Ubuntu Budgie 20.04" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -o ../${output_file} .
cd ..
isohybrid --uefi ubuntu-budgie-20.04.1-desktop-apache-remix-amd64.iso
sudo umount squashfs/
sudo umount mnt/

Enjoy your custom image

© 2020 by Omar Benchbana