After much debugging trying to understand why `apt-get autoremove` was not working in a binary hook I realised that all packages installed in a binary hook are marked as manually installed - even the dependencies of packages. This is a bug.
Another side affect of this is that any dependency of a package in the base chroot that is removed in a binary hook is not autoremovable in the binary hook.
It is autoremovable once the image is created and launched though.
```
mount -t tmpfs none "$mountpoint/var/lib/apt"
```
Which means that inside the chroot that the binary hook works on, the `/var/lib/apt` directory is empty... including the `/var/lib/apt/extended_states` file which is used to store whether a package was auto installed or not.
The same goes the other way - any changes to the `/var/lib/apt/extended_states` file inside chroot that the binary hook is changing are not reflected in the final image due to the `teardown_mountpoint` (see https://git.launchpad.net/livecd-rootfs/tree/live-build/functions#n152) not persisting any of those changes.
The end result being.
* If a package is removed in the binary hook then the resulting image will likely have autoremovable packages at first launch
* Any package and their dependencies installed in a binary hook will all be marked as manually installed.
After much debugging trying to understand why `apt-get autoremove` was not working in a binary hook I realised that all packages installed in a binary hook are marked as manually installed - even the dependencies of packages. This is a bug.
Another side affect of this is that any dependency of a package in the base chroot that is removed in a binary hook is not autoremovable in the binary hook.
It is autoremovable once the image is created and launched though.
This is due to how the `setup_mountpoint` function works (see https:/ /git.launchpad. net/livecd- rootfs/ tree/live- build/functions #n123) specifically
``` var/lib/ apt"
mount -t tmpfs none "$mountpoint/
```
Which means that inside the chroot that the binary hook works on, the `/var/lib/apt` directory is empty... including the `/var/lib/ apt/extended_ states` file which is used to store whether a package was auto installed or not.
The same goes the other way - any changes to the `/var/lib/ apt/extended_ states` file inside chroot that the binary hook is changing are not reflected in the final image due to the `teardown_ mountpoint` (see https:/ /git.launchpad. net/livecd- rootfs/ tree/live- build/functions #n152) not persisting any of those changes.
The end result being.
* If a package is removed in the binary hook then the resulting image will likely have autoremovable packages at first launch
* Any package and their dependencies installed in a binary hook will all be marked as manually installed.