|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Sysadmin Debian and Carelessness Mix Well
How to recover from a near-catastrophic deletion of /var in a Debian installation
Jan. 13, 2002 12:00 AM
(LinuxWorld) — We all make careless errors. Some of you may want to pretend you're immune, but I am certainly unashamed to confess that I am often my own worst enemy when it comes to computing. My most recent disaster of foolishness occurred while setting up my system to compare the two journaling file systems Reiserfs and XFS. Somewhere along the line, I decided to convert some partitions on my workstation from ext3 to Reiserfs in order to gain some speed on those partitions. Reiserfs is faster than ext3 in part because of its clever design, and in part because it only journals metadata. ext3 is usually slower than Reiserfs even when you configure it to journal only metadata. Unlike Reiserfs, ext3 can also journal data. This makes ext3 preferable for partitions where data integrity is paramount. Fortunately, Linux makes it very easy to mix file systems, so you can have your speed and not worry about anyone eating your data, too. I still don't know quite how it happened, but I somehow backed up the wrong partition when I attempted to backup the /var partition. When it came time to restore the /var directory tree to the newly formatted Reiserfs partition, I discovered there was nothing to restore. As luck would have it, I had no other backups of the /var partition, so I couldn't even resort to using an old set of files. Let me see if I can impress upon you how major a disaster this can be for a Debian system. There are a number of directories in any Unix system that will cause you trouble if you lose them, such as the /etc directory, where most of your configuration files reside (the /usr/share tree is another example). When it comes to Debian in particular, the /var/lib/dpkg directory is an Achilles heel equivalent to the set of INI database files in OS/2, or the registry files in Windows NT, Windows 2000 or Windows XP. (The Windows 9x registry is also a weak spot, but it hardly matters since just about any damage can make a Windows 9x system unusable.) To put this in its proper perspective, I've had to reinstall OS/2 and Windows more times than William Shatner has attempted to resurrect his acting career, and only because I had damaged INI files or the Windows registry. In comparison, I've corrupted whole Linux file systems (thanks to bugs in experimental kernels), and wiped out sensitive trees like the /etc or /usr/share trees mentioned above. I've upgraded all of my hardware multiple times, including all the disk drives. Yet, in spite of all these disasters and changes, I'm still running the very same installation of Debian I began with years ago. (In case you're wondering how one keeps running the same installation with new drives, one could always use various backup systems to save and restore the OS. I took the fast and lazy route, however. I simply added the new drive to the machine along with the old one, copied the old installation to the new drive, and then removed the old drive.) This time, however, the outlook seemed grim. The heart of Debian is its package system, and Debian stores all of its most important information about packages in the /var/lib/dpkg directory which was now gone. Most important of all is the /var/lib/dpkg/status file. I searched the Internet for tips on how to recreate this file from scratch. I found many instances of people wanting to know the same thing, but I found no answers. I came up with a couple of my own. Three lessons learnedI've learned my lesson now, and that is to backup this file on a regular basis. However, in case you haven't learned this yet, here are the key things to remember, and two methods of restoring your /var/lib/dpkg directory from scratch without having to start from square one. (Granted, it's somewhat like starting from square three, but that's the price one pays for not performing regular backups.)
/var/cache/apt/archives /var/cache/debconf /var/log /var/lib/dpkg/info /var/lib/dpkg/parts /var/lib/dpkg/alternatives /var/lib/dpkg/methods /var/lib/dpkg/updates Then create this status file:
Put the following text into the status file. If your system has a different version of libc6, then substitute that version number in the example I provide below. Make sure to press return after typing in the version number, because dpkg needs to see a newline there. This is not a complete entry for libc6, it's just enough to get you going with a minimum of effort. Package: libc6 Status: install ok installed Version: 2.3.1-9 Now execute the following commands, one at a time. The first time you try to execute dpkg --clear-avail apt-get update apt-get dist-upgrade cd /var/cache/apt/archives dpkg -i libncurses* dpkg -i perl-base* dpkg -i libstdc++* dpkg -i dselect* dpkg -i dpkg* This brings you almost to a point where you can proceed without programs complaining about what you're doing. The last complaint you need to get rid of is the one about the insufficient information about libc6. Just reinstall it to update your status file with the missing information.
Finally, re-run the dist-upgrade command. This time it will work and install all the base packages for Debian.
Once you get to this point, you can re-install the rest of the software you want apt-get/dpkg to know about in a variety of ways. The dselect package manager is ugly and unfriendly, but it is quite effective for this purpose. If you prefer, you may be able to start up an X session (the software and configuration files are there, it's just that Debian doesn't officially know it.) Then install the friendly and powerful graphical Debian package manager synaptic and reinstall the software that way. Yes, all of this software is already installed, but what you are doing is filling up your /var/lib/dpkg/status file with current information about your system. Granted, this last procedure is about as close to reinstalling Linux as one can get without duplicating the effort required to reinstall Windows or OS/2. However, in my experience, it's not nearly as time-consuming. When you lose the Windows registries, you lose everything, including driver information and application configuration data. When you lose your /var/lib/dpkg directory, you only lose information about the status of what is and is not installed on your system. It doesn't wipe out your system or application configuration files, your applications, or the system's knowledge about the kernel and its modules (drivers). You won't have to reconfigure your applications, X11, the network, hardware drivers, and any of the other tedious tasks you might have to perform when re-installing Windows from scratch. Be careful. Make backups. If you slip up, I hope the above tips will help you recover. Reader Feedback: Page 1 of 1
Your Feedback
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||