How can I remove packages using preseed?

I'm setting up an automated "no questions asked" preseed system and using Dustin Kirkland's server preseed as an example.

He uses the following line to install three packages as part of the automated install:

d-i pkgsel/include string byobu vim openssh-server

I am looking for the inverse of this, basically be able to remove packages as part of the automated install.

  • I've checked the Installation Guide
  • I've checked this example preseed, but it's not clear if this is the canonical list of every single option available.

I am thinking I need to to use d-i preseed/late_command string apt-remove packagename to clean up stuff I don't want when the install is done, but I am not sure


Solution 1:

There isn't an option to purge o delete a package in the preseed configuration script but you can use this command....

d-i preseed/late_command

This command is run just before the install finishes, but when there is
still a usable /target directory. You can chroot to /target and use it
directly, or use the apt-install and in-target commands to easily install
packages and run commands in the target system.
"in-target" means: chroot /target
d-i preseed/late_command string [in-target] foo

example :

d-i preseed/late_command string \
            in-target apt-get remove packagename

you can also run a script :

d-i preseed/late_command string \
        in-target wget http://........./postinst.sh -O /root/postinst.sh; \
        in-target /bin/bash /root/postinst.sh

or install a group of DEB files :

d-i preseed/late_command               string \
    for deb in /hd-media/*.deb; do cp $deb /target/tmp; \
    chroot /target dpkg -i /tmp/$(basename $deb); done