Question: I have an external HDD and use TrueCrypt for keeping encrypted file containers.
After mounting, whenever I try to dismount a file container (using TrueCrypt 7.0a on Ubuntu 11.04), it just does not happen and I get the following message:

```
device-mapper: remove ioctl failed: Device or resource busy
Command failed

```

Further, if I close TrueCrypt and then try to start it again, it says that TrueCrypt is already running, but I cannot access it from the Unity sidebar (because it is not there).

Also, if I power down my external HDD, the TrueCrypt volume still shows as one of the mounted volumes, but I cannot do anything with it.

Any possible work around? I remember this NOT happening in earlier versions of Ubuntu so I am guessing there is something to do with 11.04.

Thanks

Answer: 
How about to put a script in the correct runlevel?
I think runlevel 6 is shutdown, and then the directory to play in is 

```
/etc/rc6.d/

```
As a simplified version of funicorn's answer.. an upstart job, either in /etc/init/foo.conf or as ~/.init/foo.conf :

```
start on starting rc RUNLEVEL=6
task
exec myscript

```

This will run, and block the entire shutdown until "myscript" exits.

That is all you need. Note that the user jobs (~/.init/foo.conf) are a very new feature and on my 12.04 system with ecryptfs /home do not work, so you may just have to put the job in /etc/init.