I recently discovered that my Ubuntu root directory was getting uncomfortably tight from a space perspective (I’d allocated about 6 GB, /home of course lives on a separate partition). The culprit, du soon told me, was /usr, eating up as much as 4 gigs of space. I guess thats because I’ve installed tons of apps, including MATLAB (which eats up a whopping 1.4 gigs).

My primary HDD has a slew of partitions, which I’ve used at various points to test out distros, so I decided to move /usr to a partition I wasn’t using anymore. Initially, I’d thought of moving root itself to another, bigger partition, but after trying to figure out what options to give to grub-install, I decided not to be too adventurous. Maybe another day. In any case, I was nervous enough about moving /usr, though in the end it went off smoothly enough. Here’s how, for anyone who might be looking:

  1. Reboot and select recovery console in GRUB. Ubuntu should have thrown you into a root console.
  2. The partition I want to put /usr into is /dev/hda5. Enter the following commands:
  3. cd /
    mkdir usr_new
    mount /dev/hda5 /usr_new/
    rm -rf /usr_new/*
    cp -dpR /usr/* /usr_new/
    umount /usr_new
    mv /usr /usr_old
    mkdir /usr
    mount /dev/hda5 /usr
  4. Last thing to do is edit your /etc/fstab file. You need to add the following line:
    /dev/hda5 /usr auto defaults,errors=remount-ro 0 1
    It’s possible that a line beginning with /dev/hda5 already exists; if so, replace it with the above.
  5. Type reboot and press Enter. Hopefully, you should be good to go.
  6. If all goes well, when you relogin to Ubuntu, fire up a Terminal and do sudo rm -rf /usr_old.

Important: Be *very careful* while executing the rm -rf commands! The standard rule of the rm command applies… type-rm-minus-rf-star-hands-off-keyboard-STOP-AND-THINK! A mistyped rm -rf /* might be an honest mistake, but it will send the entire darkness of the universe descending upon you.

That I’m going to the trouble of moving around partitions, not to mention writing this post says enough about how much I’ve taken to using Ubuntu Linux as my primary distribution at home. I still prefer Fedora at work though, more on that in another post later, though.