Amateur Topologist

Everything but topology.

Tag: how to

Keep / and /home on a Separate Partition

The title pretty much says it all; if you’re running Linux, I highly, highly recommend that you put /home on a separate partition of your hard drive than the root partition /. Why do this? The biggest reason is that in case you mess up your operating system and need to reinstall it, then you only need to overwrite the / partition, leaving your data in /home fully intact. Since most applications store settings in some su<b>b</b>directory of your home directory, you’ll even get to keep your settings. How do you do this? Simple: when you’re installing the operating system, specify an additional partition to be used as /home. You also might want to set up a swap partition with size about equal to your RAM, but you don’t strictly have to. As for sizing the root partition, I’d go with about 20GB or so; most applications don’t take up a lot of space. If you’re on a SSD and 20 GB is a lot of capacity, you can probably get away with 10; I wouldn’t go any lower than that, though.

Now, the natural question is: how do you set up /home on a separate partition if you already have it on the same partition as /? It’s possible, but dangerous; if you mess this up, you can leave your system in a state that would require a good deal of knowledge to recover.  You should be fine as long as you follow these instructions, but I can’t guarantee anything, obviously. I also highly recommend you have an external hard drive of sufficient size to contain your current /home directory (which you can find out via du -sh /home ).

  1. Create a gparted CD or USB drive. You can’t modify a partition that you’re currently using, and you can’t unmount the root partition while you’re using that operating system. The natural solution: create a LiveCD or USB drive. First, you’ll need to download GParted from here. You can use brasero to burn the CD (pick ‘Burn image’) or usb-creator (both of which are likely in your repositories if you don’t have them already) to create a bootable USB drive from the .iso.
  2. Reboot and open up GParted. You should boot into the GParted CD/USB. If not, you did it wrong.
  3. Open up a terminal and GParted. Self-explanatory.
  4. Mount your current partition. Figure out which device is your Linux partition; look at the GParted window and take note of the entries in the ‘Partition’ column; your Linux partition will likely have filetype ext3, or ext4. For simplicity’s sake, I’m going to assume that it’s /dev/hda1, although you’ll likely have a different one. In the terminal, type the following:
    mkdir /tmp/linuxpart
    mount /dev/hda1 /tmp/linuxpart
  5. Mount your external hard drive. For the sake of this tutorial, I’m assuming it’s already formatted to something like ext3 and it only has one partition. If you only have one internal drive, then you’re going to be using /dev/sdb1, if you have two, then /dev/sdc1, etc.
    mkdir /tmp/exthd
    mount /dev/sdb1 /tmp/exthd
    mkdir /tmp/exthd/newhome

    Obviously, if the exthome directory exists already on your external, use a different filename.

  6. Copy. You can’t just use a plain ‘cp -R’ for this; you’d lose a lot of information. Instead, do
    cp -avu /tmp/linuxpart/home/* /tmp/exthd/newhome

    This will preserve various stuff, such as symbolic links. It’ll also take a while, so find something else to do.

  7. Delete. This is the moment of truth; so far, everything that you’ve done is harmless to your drive. Once you do this step, you’re essentially committed.
    rm -rf /tmp/linuxpart/home/*
  8. Unmount. Unmount the internal hard drive with
    umount /tmp/linuxpart
    This will let you resize it. Don't unmount the external hard drive, though.
  9. Shrink your old partition. Once that's done, you can right-click on the  partitions in GParted to manipulate them; it's fairly self-explanatory. Right-click the main home partition, select Resize/Move, set it to however large you think you'll need (I recommend 10-20 GB).
  10. Resize/move your new partition. Right-click your new partition, pick Resize/Move, and stretch it out to fill all of the available space.
  11. Execute. So far, you've only told GParted what you want it to do; once you click 'Apply', it'll do all the formatting and resizing and such. Give it a while, especially if you have a big hard drive. Once it's done, make note of the partition device; I'll assume it's /dev/hda2.
  12. Mount the new partition and copy files back.

    mkdir /tmp/homepart
    mount /dev/hda2 /tmp/homepart
    cp -avu /tmp/exthd/newhome/* /tmp/homepart
  13. Edit your filesystem table. This is important; without this, your OS won't know where to find /home . In the terminal, run
    mount /dev/hda1 /tmp/linuxpart
    nano -w /tmp/linuxpart/etc/fstab

    You should see a file pop up; you can ignore the lines that are already there and add one at the bottom that looks like this:

    /dev/hda2 /home  ext3 relatime 0 2

    Obviously, make sure to replace /dev/hda2 with whatever device your home partition is on; if you chose a filesystem other than ext3 for /home, then change that as well.

  14. Reboot You're done now; reboot, take the GParted CD out, and boot back into your freshly-partitioned Linux installation

Hopefully, this has all gone well and you now have /home on a separate partition. If it hasn't, well... that's why you make backups. You did make backups, right?

Linux on the MSI GT725

So I finally managed to get my sound to come out of speakers other than the bass on my new GT725 in a way that; it’s not 100% perfect, as I think that the subwoofer isn’t being used, but it’s good enough for me; if you’re an audiophile, you shouldn’t be listening to anything through built-in laptop speakers anyway. The graphics fix I detailed in this post, so I’ll share the fix I found for the soundcard. It’s fairly simple; in a terminal, run

gksu gedit /etc/modprobe.d/soundfix.conf

where soundfix.conf can be named anything you want, and then paste these three lines:

alias snd-card-0 snd-hda-intel
alias snd-slot-0 snd-hda-intel
options snd-hda-intel model=targa-dig

into the file. Reboot and you should have sound that doesn’t all come out of the bass speakers. If you want, you can replace targa-dig with one of the other models listed under the ALC888 section here; if one of them works better, let me know in the comments and I’ll edit it in.

Conky with BOINC and Banshee

Conky is a great tool for monitoring CPU, memory, and network usage. It also has now playing integration for MPD, XMMS, BMPx, and Audacious. But it completely lacks integration with my music player of choice, Banshee, and it also has no built-in way to check my progress in BOINC, a distributed computing project. On the other hand, which Conky does have is built-in support for executing arbitrary programs and parsing the result as markup/text. So I wrote a couple quick Python scripts, one to get now-playing data from Banshee and put it in a nice format, and the other to grab progress data from BOINC and calculate percent completion and estimated time until completion.

Conky with Banshee and BOINC scripts

Conky with Banshee and BOINC scripts

To use the Banshee script, you need to start banshee-conky-daemon.py on startup (it echoes the data to a file in /tmp to avoid constantly invoking the script and causing noticeable skipping in Banshee). In Ubuntu 9.04, you can do this by going to System->Preferences->Startup Applications and adding a new entry for ‘python ~/banshee-conky-daemon.py’ (assuming you put it there). Then add ${execp cat /tmp/banshee-conky-daemon} to your .conkyrc wherever you want the output in conky. If you keep conky at a different width, you might need to mess around with the trimming numbers on line 33.

The BOINC script is simpler; just add ${execpi boinc-conky.py} to your .conkyrc. Red tasks are actively being worked on, green ones aren’t. Only tasks that have been started are shown. The dict maps project URLs to short names; if you find the program crashing with KeyErrors, just add an entry to the dict that maps the missing key to a description eight letters or less (the restriction is to maintain proper time estimate alignment; it can be changed).

If you have questions, leave a comment. Apologies for the lack of comments in code; I’ll answer any questions you may have. I promise to code with comments from now on.