Wednesday, December 26, 2007

/home sweet /home

Last night, I encountered a very horrific situation. I was working on getting Sabayon to actually WORK CORRECTLY, and if you don't know my hard drive layout, I share my /home directory between Ubuntu and Sabayon (this is because it's on a different hard drive). The problem I had with Sabayon was that the application list was gone. I had to run applications by going Alt+F2 (which opens up the "Run Application" dialog box) and typing in it's name. I didn't want to do that, so I set out to figure what was wrong. I started out with a reinstallation of the partition (/home wasn't touched). When I booted back, the applications were still gone, so I decided that the problem lay in the /home partition. Now, I decided to do something that could have gone better. I did a clean reinstall from another partition, and copied all of the contents from there to my /home. Now, many of the programs I had were preserved, but it also overwrote a couple of configuration files that Ubuntu kinda wanted. However, I got many of the applications back in the menu, which was good.

Let's fast forward to when I boot into Ubuntu. Everything initially goes normally, however, once I log in, Gnome looks like crud. I'm missing the top panel and title bars, and there's an error saying that Gnome couldn't find some file. The theme was reverted back to the minimal one, and nothing really worked. I was worried, however, I worked on servers a week ago, so I knew my way around the command line (sorta). So, I go into what's called a virtual terminal (Press Ctrl+Alt+F1 through Ctrl+Alt+F6) and logged in. These are basically ways for you to log in if your GUI goes kapoot. From there, I used irssi to get to IRC (boy am I getting dependent on that) and get some help! Luckily, there was someone (Kr0ntab on #ubuntu-california) who knew how to restore a /home directory. And this is what I'm going to lay out now.

1. Unlock the root user
sudo passwd
and pick a root password. Be sure you do this and not sudo su, and LOG IN as root in a virtual terminal (Ctrl+Alt+F[1-6]).

2. Log out from your user. This means both from X, and any virtual terminals you might be in (type "exit" without quotes).

3. Move your home directory to some backup location:
mv /home/*user* /root/backup
where *user* is your username.

4. Now here comes the fun part, get rid of your home directory:
rm -rf /home/*user*
As always, be careful when you use rm -rf. MAKE SURE you didn't mistype anything.

5. Make sure your home directory is GONE. Do an "ls /home" (without quotes) and make sure that it's not there.

6. Copy a skeleton home directory to your home directory:
cp -r /etc/skel
/home And rename it:
mv /home/skel /home/*user*
7. Now log back in to X and your home directory should be reconfigured to its original state. If you can log in to something that looks like you just installed Ubuntu, you're good so far. Now re-lock the root account for security reasons:
sudo -l
And log out of root.

8. Now you're wondering how you're going to get the settings you worked so hard to tweak. Well, some, you're just going to have to do by hand, but most you can get back. Remember when we backed up the original home directory? Well, go back there and move back files that you know weren't a problem (you wouldn't want to restore that file that broke you system, would you? So be aware of what you're moving back).

After this, it's just a matter of copying and pasting (or dragging and dropping, depends how you like it). Most program configuration files (such as .gaim or .xchat) ought to be fine, and you should be able to replace them. However, try not to replace configuration files (like files that have to do with X), because you might replace the wrong file; and plus, those are settings you could tweak back easily. Don't take that chance.

Well, this is how I saved my home directory. I hope this guide will be of help to you if you ever need it. Hopefully, you won't. And for those of you who enjoy it when I screw something up on my computer, I HOPE YOU'RE HAPPY!!!

No comments: