Install deb packages in another directory (or equivalent)

I have a netbook with a tiny hard drive, and an external drive to go with it. It's running Ubuntu. I want to be able to install some packages to that external hard drive, so that when the hard drive is not plugged in the netbook still functions, just with out some functionality. It doesn't have to be this way exactly, I just want the effect of offloading some of my installed libraries and programs onto the portable hard drive. In other words, just mounting some directories from the external drive wont work because I at least need some basic programs to run normally.

Here are some things I was thinking about but wasn't able to find enough information to actually understand if they are feasible, or how to go about doing them. Comments on how to do any of these or on alternate methods are greatly appreciated.

  1. Can I do something like this if I use the --root=/media/external switch of dpkg install and then add /media/external/ to my system path?
  2. What if I create some kind of wrapper for dpkg that will install the package into an alternate root (--root=/media/external) and then create a symlink in the internal file system to every file that was just installed on the external file system?
  3. How about something where I chroot into the external drive?
  4. How about something using LVM?

Solution 1:

You can use --root to install packages into another directory, but you can't use most programs from there as most programs look for some files in fixed places (like /etc). The option is there for cases like installing packages into a NFS root for diskless clients.

Maybe you could use something like UnionFS to merge the two file systems.

Solution 2:

If you want a simple answer that doesn't make you work your away around the debian package management, just use mount and symlinks. You could mount your external drive using /etc/fstab and have some symlinks that point into that drive. NOTE: You shouldn't blindly symlink, be sure before you change something ;)

A rather save suggestion would be to put your /tmp into a ramfs (which you should be doing anyways on many netbooks with SSD).

Are you sure your programs need the most space on your internal drive? Did you check it using a tool like xdiskusage?