I want to run a few commands immediately after installation of Ubuntu.Therefore I thought of using preseeding concept.I extracted my iso and in the preseed folder appended the following line to custom.seed file

d-i preseed/late_command string in-target mkdir /home/abc

Now I repacked the iso and installed ubuntu using it..But no change happened..What am I doing wrong here?

1 Answer 1


I can't tell you what is wrong with that but I can tell you how I got mine working after lots of trial and error.

My requirements were to package new and replacement files in the ISO, as well as run a script after install.

preseed file:

d-i preseed/late_command string /bin/sh -c "$(cat /setup.sh); exit 0"

No doubt this is an odd way to run a script, but it works.


# [ hardware/hosting detection, other customizations ]
# set PackageList string
in-target --pass-stdout /bin/sh -c \
  "apt-get update &&
   apt-get install -y $PackageList &&
   apt-get dist-upgrade -y

This script is run in the installer environment that is lost on reboot. You must use the in-target command to run in the installed environment.

existing process to unpack ISO here

packing file in initrd

initrd is a filesystem archive that is expanded on boot and the environment the installer runs in. The setup.sh file in my case needs to be copied to that archive.

Expand initrd archive

cd $ExpandedISO/install
mkdir initrd
cd initrd
gzip -dc ../initrd.gz | cpio -id --no-absolute-filenames

Copy new files into expanded initrd directory.

Rebuild initrd archive:

# in $ExpandedISO/install/initrd/
find . | cpio -o -H newc | gzip > ../initrd.gz
# expanded dir can now be deleted to not take up space in ISO
rm -rf $ExpandedISO/install/initrd/

Existing process to repack ISO here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .