Is it possible to install a program onto an external drive?

7,474

Solution 1

This is an interesting question. Let us discuss a few ways this could be attempted.

Method#1 : Manipulating location during apt-get installation

Using apt-get, it would not be possible to do so. If you're installing using .deb files, again it is not possible. The reason is simply that the location for installation is hard-coded into these packages.

To manipulate the installation location, you will have to compile sage from source and modify its makefile before installing it. This will come with a burden of managing the dependencies.

However, there have been discussions regarding this. Perhaps, people have done it. Maybe they have somehow manipulated the installation location. See here and here. If you find some way to do this, please add a comment.

Method#2 : Changing the location of the /usr folder

You could change the location of the /usr folder itself and transfer it to your external card. Usually this would be discouraged, but since you are saying that you always keep it inserted, so it should be fine.

To do this, there are 2 ways:

  1. (Preferable) Create a partition in your external card and transfer all of the content in the current /usr folder to that partition. Then, modify your /etc/fstab to mount that partition as the /usr folder, and remove the old /usr folder altogether. To do all of this, you will need to boot from some rescue disc or some live CD/USB.

  2. In this method also, first boot from some rescue disc or live CD/USB and then move the /usr folder to the external card and then create a symlink to the new /usr folder.

PS

This is an interesting question, something about which I've been thinking lately as my hard-disk was getting full. I will try some of these things and update my answer. Comments are welcome to criticize some of these methods.

UPDATE

Also see @gilles answer. His suggestion is better. Instead of moving all of /usr folder to the external card, just move the /usr/lib/sagemath to the external card because it occupies about 3.1GB of your installation. So, in Method#2, you could move this folder instead of /usr.

Solution 2

Splitting Debian packages onto different disks on a package by package basis is difficult. There's no support for that; you'd have to invoke dpkg separately on the packages that you want to install in a non-default location.

Putting a directory tree onto a separate disk is easy. Fortunately for you, as far as I can tell from a quick perusal, the Sage packages in the PPA install most files in /usr/lib/sagemath. You can easily put that on the SD card. Let's say that the SD card is mounted (when present) on /media/sdcard. Create a directory there and make a symbolic link.

mkdir /media/sdcard/sagemath
ln -s /media/sdcard/sagemath /usr/lib/sagemath

Then all files that dpkg installs under /usr/lib/sagemath will end up on the SD card (regardless of which package they come from).

If you try to use Sage or manage the Sage packages while the SD card is not present, you'll get an error message, and if you insert the SD card and repeat the action, there'll be no harm done.

Share:
7,474

Related videos on Youtube

Brian Fitzpatrick
Author by

Brian Fitzpatrick

I am a Lecturer in the mathematics department at Duke University.

Updated on September 18, 2022

Comments

  • Brian Fitzpatrick
    Brian Fitzpatrick almost 2 years

    I run Ubuntu 14.04 on a Toshiba chromebook using crouton. The drive my OS is installed on is small, with only 3.6 GB of free space. I'd like to install sage on my system but sage requires 6 GB of free space on the system.

    However, I always keep an SD card inserted into the unit. The card has 175 GB of free space. Is it possible to install sage on the SD card?

    The way I'm attempting to download sage with the commands

    apt-add-repository -y ppa:aims/sagemath
    apt-get update
    apt-get install sagemath-upstream-binary
    

    as found here.

    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' about 9 years
      How are you installing Sage? From deb packages? By unpacking an archive? By compiling from source?
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' about 9 years
    Moving /usr onto the SD card would make the system unusable when the SD card is not present. This isn't a good idea.
  • shivams
    shivams about 9 years
    Yes. But the OP has mentioned that the card will ALWAYS be kept inserted. I've mentioned this in my answer.
  • shivams
    shivams about 9 years
    @Gilles I just your answer. Your suggestion is definitely better.
  • Ned64
    Ned64 about 9 years
    You need the external drive to have a UNIX-type file system (like ext4, btrfs etc) if you need attributes like "executable" and owner/group information.
  • Brian Fitzpatrick
    Brian Fitzpatrick about 9 years
    @Ned64 My sd card is has ext4.
  • Brian Fitzpatrick
    Brian Fitzpatrick about 9 years
    @Gilles My etc/fstab reads # UNCONFIGURED FSTAB FOR BASE SYSTEM
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' about 9 years
    @BrianFitzpatrick How is it mounted then? (There may be a generic answer to this for Crouton but I don't know it.)