Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have /tmp on a separate partition, and mounted with noexec. I am using Debian.

The installation of some packages fails, because the post-installation scripts of some packages need to run from /tmp.

I was wondering if it would be possible to "hook" a simple script to apt-get, which would be run every time before apt-get, and remount /tmp to exec. And similarly, remount it to noexec after apt-get has finished.

any ideas would be appreciated

share|improve this question
up vote 18 down vote accepted

You can use dpkg's hook system to remount it -- put this in /etc/apt/apt.conf.d/00exectmp:

DPkg::Pre-Invoke {"mount -o remount,exec /tmp";};
DPkg::Post-Invoke {"mount -o remount /tmp";};  
share|improve this answer
exactly what I needed. Thanks a lot. – user1968963 May 18 '13 at 14:36

Mumble, you can simply replace apt-get with a script of yours.

Move apt-get to real-apt-get and, then, create a script called apt-get like this one:


mount -o remount -o ... /tmp
real-apt-get "$@"
mount -o remount -o ... -o noexec /tmp

In any case, I do not like this solution. It is easier change the temporary directory environment variable when you need it. Something like (sh style):

mkdir /root/mytmp
export TMPDIR
apt-get ...
rm -rf /root/mytmp

This way apt-get will use /root/mytmp as temporary dir. No need to change the system.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.