3

I've had a 2GB SD card containing a Arch Linux installation running for a while now, and decided to buy a 16GB pendrive to extend its space.

I've formatted it to ext4 to match the filesystem on the root partition (as recommended), and migrated the home directories over.

Now I wanted to start installing a Rails server, but I ran out of space before installing nginx. It now seems such a waste to have that much free space waiting for home files, so I was wondering if I could migrate some other directories over to a new partition on the drive, that would free significant space on the root system?

2

[Unfortunately, the following method cannot be used as is for Arch or Pidora, which symlink /bin, /sbin, and /usr/bin. See comments. It will work for Raspbian.]

If you're installing rails and nginx from raspbian packages, moving /home is not going to make that much difference because they're not being put there. So you will end up with no space left on the 2GB partition and a near empty 16 GB partition.

I'm presuming you have another linux system on which you can mount both devices (the card and the stick). You cannot do this from the pi itself while the system is running. First, undo whatever you did to move /home and, if there's no room to put it back on the SD card right now, put it somewhere else temporarily. You want the partition on the stick empty.

More than half of the space is probably taken up by stuff in /usr (that should be where rails and nginx go). du -h /usr will demonstrate that; I have ~3.4 GB on the SD card and 1.7 GB of that is in /usr. That's what you should move to the stick. I'll refer to the stick as /mnt/stick and the card as /mnt/card. I've also left out sudo in the instructions below; hopefully you can sort out the need for that (I prefer to just do this kind of thing su root).

  1. Copy /usr to the ext4 partition on the stick:

    cp -a /mnt/card/usr/* /mnt/stick/
    

    Note you don't want to move the directory stub (usr) itself. You just want what's inside (directories: bin games include lib local sbin share src). Be certain that worked (you don't have to check too hard, just look to see if the directories are there and there's stuff in them). Now delete the original:

    rm -fr /mnt/card/usr/*
    

    Make sure that worked too. /mnt/card/usr should now be empty.

  2. Get the UUID of the stick partition. You need to know the device node it's currently using. If it's /dev/sdb1:

    > blkid /dev/sdb1
    /dev/sdb1: UUID="ae6c22c6-aafd-11e3-bf7a-6b21bc3e493c" TYPE="ext4"
    

    That output is an example. If it doesn't have a UUID, you need to give it one. Check to see if the system you are using has uuid or uuidgen on it; if not install one or the other (search for a package with "uuid" in the title, it should be obvious). Make sure it works (all it has to do is produce that random token). Now:

    tune2fs /dev/sdb1 -U `uuid`
    

    Notice the backticks around uuid; this appends its output. If you're not sure about that just run it and copy paste the UUID (e.g. tune2fs /dev/sdb1 -U ae6c22c6-aafd-11e3-bf7a-6b21bc3e493c).

  3. Add a line to /mnt/card/etc/fstab:

    UUID=[that UUID]    /usr    ext4     defaults,noatime  0  3
    

    The last number presumes there's a 1 and 2 already in that column (see man fstab for details).

That's it; put the card and the stick in the pi and try it out. The other thing you will want to think about is where rails, etc, keeps data. If you want that kind of stuff on the stick too, the easiest method is create a /usr/link into which you can copy whatever other subdirectories -- e.g., /var/rails_stuff. Copy that that in, delete the original (including the directory stub this time), and then ln -s /usr/link/rails_stuff /var/rails_stuff. You can do this with whatever from /home (or all of /home) too if you want. This can be done on the pi while the system is running.

  • In the meanwhile, I decided to give this a try, but your option seems definitely more interesting. Can I remove the pendrive and keep a functioning Linux system? – ravemir Mar 13 '14 at 23:57
  • @ravemir No. BTW, I just noticed you are using Arch -- if Arch symlinks /bin, /sbin, and /usr/bin (this is the new trend), my idea here is not workable. Raspbian still does it the old way. Will check on this and edit the question so no one shoots themself in the foot later. – goldilocks Mar 14 '14 at 0:23
  • Yeah, Arch does symlink those. I'll have to add a big caveat at the top of this. Sorry 'bout that, must pay better attention to the details. It's still not impossible for you to do this, it is just a tad more complicated. – goldilocks Mar 14 '14 at 0:37
  • That's a shame...it would be ok if I removed the drive and lost some stuff, but kept basic utils (like cd, cp, cat, etc...) – ravemir Mar 14 '14 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.