Linux – Install deb packages in another directory (or equivalent)

dpkgexternal hard drivelinux

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?

Best Answer

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.

Related Question