How to install applications to a separate hdd?

66,755

Solution 1

There is a major difference between Windows and GNU/Linux. On Windows it is common, that each program together with all the libraries it depends on is installed in a separate folder. This often leads to a lot of wasted disk space due to libraries being installed multiple times, for each program that uses them.

On Linux, programs are installed following the Filesystem Hierarchy Standard (FHS). This means, that the libraries the programs depend on are all installed in a common dedicated location, so that they are usually only installed once, no matter how many programs use them. Also, programs are built in such a way, that they all use the same version of a certain library. This saves disk space (and RAM at runtime), but has the drawback, that one cannot freely install programs on different partitions or hard disks, at least not without editing system configuration files (for instance /etc/ld.so.conf.d to include the different library folders).

Since the Debian package system was implemented with the FHS in mind, there is, as far as I know, no easy way to install Debian packages to a folder different from the one they were intended to be placed in and have them working without manually moving and editing files afterwards. This is, because paths are often hardcoded at compile time. So even if you install a package to a different folder, for instance by using dpkg --instdir=folder/ package.deb on the command line, the program will still look for its configuration in '/etc', not 'folder/etc', but the config files that were shipped with the package of course were installed to 'folder/etc'... The program will not be added to the menu either, since menu files are supposed to be in '/usr/share applications', not in folder/usr/share/applications.

You can of course manually configure and compile a program from its source code to have it install the binary and data parts wherever you'd like, while still installing configuration files to the FHS compliant locations, but this is something I'd only recommend for advanced users. If you are going to compile from source, have a look at checkinstall, a tool that automatically creates debian packages.

Another option, that was suggested on linuxfromscratch, is to unpack the package to a suitable location and then to create symbolic links to all installed files in the corresponding FHS locations.

Since in the comments you were referring to games: Many games that are not bought through Ubuntu Software Center come as an installer executable, and those can then of course be installed to any folder, usually a subfolder of your home directory. Windows games, which are being run using WINE can also be installed in any directory you want. For wine there exists an environment variable called WINEPREFIX with which you can set up numerous independent WINE folders, each including its own virtual C: drive. Read the WINE man page for more info.

Even if games/programs come as Debian packages, you can look at the package contents in your favorite archive manager. If the game is going to be installed in /opt, you can usually safely install it to a different folder, since /opt is often used as installation location for programs that don't adhere to FHS.

Solution 2

TL;DR

  1. Boot the external USB disk with the version of Ubuntu you just installed and I'm assuming /dev/sda is your SSD and /dev/sdb is your HDD.

  2. Create a partition on your HDD to contain all the applications you want to install (let's say 64 GB) using gparted and I'm assuming this will be the third partition you'll be creating on your HDD (/dev/sbd3)

  3. execute the following commands:

    mkdir /media/apps
    mount /dev/sdb3 /media/apps
    mkdir /media/apps/usr
    cp --preserve=all --recursive /opt /media/apps
    cp --preserve=all --recursive /usr/bin /media/apps/usr
    
  4. sudo nano the fstab on /dev/sda1/etc/ to include the following right after the / entry (the root directory)

    /dev/sdb3  /media/apps          ext4   errors=remount-ro  0   0 
    /opt       /media/apps/opt      none   defaults,bind      0   0
    /usr/bin   /media/apps/usr/bin  none   defaults,bind      0   0
    
  5. reboot and test

The long version:

Unix / Linux / Ubuntu was conceived to be a server OS with a desktop as an afterthought whereas Windows was conceived to be a Desktop OS and the server came as an afterthought.

So the Linux Filesystem Hierarchy Standard allows you to have an unlimited amount of drives / partitions to be located anywhere and bind them to the correct drive or partition with total transparency to the user whereas the Windows OS is limited to a maximum of 24 accessible drives/partitions (C: through Z: as A: and B: are reserved for floppy disks.)

Most applications you install yourself get installed in /opt/ and /usr/bin, so install Ubuntu normally and then use the below steps where I'm assuing /dev/sda is your SSD, /dev/sdb is your HDD and /dev/sdd is your USB stick:

  1. Boot the external USB disk with the version of Ubuntu you just installed.
  2. Create a partition on your HDD to contain all the applications you want to install (let's say 64 GB) using gparted and I'm assuming this will be the third partition you'll be creating on your HDD (/dev/sbd3)
  3. Mount that partition in a temporary directory:

    mkdir /media/apps
    mount /dev/sdb3 /media/apps
    
  4. copy the existing /opt and /usr/bin to there:

    mkdir /media/apps/usr
    cp --preserve=all --recursive /opt /media/apps
    cp --preserve=all --recursive /usr/bin /media/apps/usr
    
  5. sudo nano the fstab on /dev/sda1/etc/ to include the following right after the / entry (the root directory)

    /dev/sdb3  /media/apps          ext4   errors=remount-ro  0   0 
    /opt       /media/apps/opt      none   defaults,bind      0   0
    /usr/bin   /media/apps/usr/bin  none   defaults,bind      0   0
    
  6. reboot and test

  7. If everything works correctly, reboot to the USB stick again and delete everything in the /dev/sda1/opt and /dev/sda1/usr/bin to reclaim the disk space still in use by now obsolete directories already mounted somewhere else.

Warning: the last command might also make your system crash in the unlikely case of /dev/sbd3 not mounting due to a HW failure

Solution 3

The solution I have used for my Chromebook is to not install packages, but rather, download their .tar.gz counterpart.

This may not be what you are looking for, but if you have a very small drive and want to split your vital software (GNOME desktop, web browser) from your additional software (GIMP, IDE, games) to save on some local space and keep your computer working without the external drive, it's the best solution so far IMO.

Share:
66,755

Related videos on Youtube

plaguedoctor
Author by

plaguedoctor

Updated on September 18, 2022

Comments

  • plaguedoctor
    plaguedoctor over 1 year

    I was so good with windows, now I’m feeling like a complete idiot.

    I have an SSD for ubuntu and want to install the majority of my programs to a separate HDD but I have no clue how.
    All searches I have tried only turn up with dual-boot installations.

    • (RESOLVED -> ) I am also having trouble locating "/etc/". Specifically, to modify Conky.
      Searching for this term only turns up instances where people are telling you to access this file, not how to get to it.
    • Mitch
      Mitch almost 11 years
      Take a look at This, it'll get you started.
    • plaguedoctor
      plaguedoctor almost 11 years
      I was of the impression that everything extended from the home folder. Whoops. That page you linked wasn't helpful regarding my issue, but i'm reading through it now and learning a lot, so thank you.
    • belacqua
      belacqua almost 11 years
      I added the mount and fstab tags ; you can do what you're describing by manually setting particular filesystems to mount on particular partitions or drives.
    • plaguedoctor
      plaguedoctor almost 11 years
      @belacqua is there any other way than that? I don't just want particular file systems on another drive, I want all file systems of particular programs. That way I can sort them by how intensive they are of my system, having games/virtualbox/etc entirely on my SSD and things like libreoffice/thunderbird entirely on one of the HDDs.
    • belacqua
      belacqua almost 11 years
      It's not so easy to determine where a given installation and its files might reside -- see the answers in the link Mitch mentioned. You can use things like symlinks as well, but my recommendation is to start simple. Find an example application, ask a specific question here about it (or modify this one to be less general), and go from there. Or experiment cautiously.
    • plaguedoctor
      plaguedoctor almost 11 years
      It baffles me that there is no easy option to do this, given how critical it is for SSD users.
    • plaguedoctor
      plaguedoctor almost 11 years
      Still looking for an answer to this, and I still can't find anything related to my problem on the internet.
    • soulsource
      soulsource almost 11 years
      Why should it be critical for SSD users? Programs are not supposed to write anywhere except for /tmp, /var and /home, so by putting these directories on the conventional HDD, you minimize write access to the SSD... Also, if you have more than 10 GB SSD, you should have enough space for a complete Ubuntu installation on it... If you for any reason have an SSD smaller than 10 GB, you should probably have a look at dm-cache or BCache, which automatically move data between HDD and SSD, depending on usage...
    • plaguedoctor
      plaguedoctor almost 11 years
      @soulsource It IS critical for SSD users because of the limited space. I have a 120gb SSD, and modern games are all 20gb+, and virtual machines need at the very least 40gb space EACH, meaning I have severely limited space. I have a 2tb HDD for movies, music etc. which is almost full, and I also have a 1tb HDD for older slower games, program backups and certain virtual machines which is also almost full. Just because you use your computer one way doesn't mean everyone uses it that way. Why did you even comment here?
    • ignis
      ignis almost 11 years
      plaguedoctor: @soulsource is totally right, and gave you the 2 right ways to do it, being /tmp + /var + /home separation the simplest one. Be respectful, and think twice before replying.
    • Rinzwind
      Rinzwind almost 11 years
      @plaguedoctor there are NO 20Gb games that are installed from USC. Games you install manually and therefor get to choose your installation path. My GuildWars is happily sitting in /home/$USER/gw/ (I have a notebook with a 40gb SSD as boot and a 500Gb HDD mounted for personal file with /home/$USER/ symlinked (ie. shortcut in windows terms). Oh and soulsource is correct ;)
    • soulsource
      soulsource almost 11 years
      Actually, I'd like to apologize for my snotty formulation. I wasn't in the best mood then. Sorry.
    • plaguedoctor
      plaguedoctor almost 11 years
      @soulsource thank you, and I suppose I did react a bit harshly. Sorry. I've selected your answer as best, though I am dismayed at not being able to allocate my system's resources more directly.
    • plaguedoctor
      plaguedoctor almost 11 years
      @Rinzwind, USC games aren't the games I'm talking about. Also, games are supposed to go on my SSD, I just need to move other stuff to make space for them. You've misunderstood what I'm trying to do.
  • Rinzwind
    Rinzwind almost 11 years
    Correct and worthy of upvotes O
  • soulsource
    soulsource almost 11 years
    Nevertheless, it's not complete, since I didn't explain in detail what would be required to get a package installed at an arbitrary location working, which files one would have to edit and which environment variables would need to be set. I'm just afraid that then it'd become a medium sized novel...
  • Rinzwind
    Rinzwind almost 11 years
    I would not bother. Just mount /etc/ elsewhere. It takes 90% of the disc load from the ssd.
  • MSalters
    MSalters about 5 years
    Windows actually has the same support to mount drives on non-root paths, for about a decade now. And those drive letters could also be mapped per user, so H:\ could be a per-user home directory. No big surprise: the Windows NT line is inspired by VMS, very much a multi-user system. Nor was Unix conceived as a server OS: AT&T made phone switches. And UNIX specifically differs from its inspiration Multics in being less multi-user oriented at first - there simply was no need for that in a phone switch.
  • Fabby
    Fabby about 5 years
    @MSalters Wow, didn't know the AT&T phone switch bit... I do remember the VMS / NT part and that M$ hired DEC's Principle Engineer, and the OS/2 part too, but before that, it was a Single-user pre-emptively multi-tasking Desktop shell. >:-) Updated!
  • Stephen Kitt
    Stephen Kitt about 5 years
    Windows also supports non-letter drives (1:, !: etc.), as did some versions of DOS (with other characters, [: etc.). Windows is not limited to 24 partitions (look up volume mount points). Early versions of Windows (before 95) used cooperative multi-tasking, not pre-emptive, between Windows processes; only DOS VMs were pre-emptively multi-tasked (in enhanced mode).
  • stevegt
    stevegt about 5 years
    I used to work at AT&T, in the UNIX group. It didn't start life as a phone switch.
  • Peter - Reinstate Monica
    Peter - Reinstate Monica about 5 years
    @MSalters Unix does not seem to have anything to do with phone switches, apart that the responsible company developed both; and it appears to have been multi-user very early on, around the time the name was coined. See this answer on SE RC.
  • Fabby
    Fabby about 5 years
    @StephenKitt Cooperative! True! You could lock up the entire Windows session in C if you weren't careful! >:-)
  • Fabby
    Fabby about 5 years
    @stevegt why don't you add that as an answer here? ;-)
  • Gubatron
    Gubatron over 4 years
    wish this was as simple as modifying a dpkg config file and changing the default installation folder where all apks write to
  • Error404
    Error404 over 2 years
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.