Life gets rough when you start encountering filesystem failures. Are they caused by a software issue, or by failing hardware? Your first task is to determine exactly this.
1. Run the command:
and look for messages about disk failure. If you find these, the question is answered.
2. You can run a file system check on any read-only mounted partitions. Run the command:
and be ready for messages about bad blocks.
To check your root file system, you will have to mount it read-only, which is to say you’ll probably have to mount it under a running live-CD Linux system.
Again, if you’ve got bad blocks on the hard disk, your problem is hardware.
3. Get a low-level disk diagnostic program from your hard disk manufacturer’s web site.
Most of these are DOS bootable floppies. Again, you’ll know hardware is the issue if the tool tells you it is.
1. If you’ve got hard disk problems, back up your data NOW. Next, go get a new hard drive.
3. Shut down the computer if it’s running and add your new hard drive to the system. Your old, bad hard drive should still be in it too. Be aware of where you’re adding that new hard drive: if it’s the master drive on the secondary IDE controller, for instance, it’s hdc.
4. Boot to a live-CD or floppy-based Linux distro. (See this page for some choices.) You can use the built-in utilities fdisk to create partitions on your new hard disk, and mkfs to make file systems on them (i.e. format them), or get the excellent GNU Parted partition editor.
Make life easy on yourself and use the same partition layout that your original disk used.
I highly recommend a /boot partition, a swap partition, and a / partition. Modern hard disks are much more reliable than older ones, so elaborate schemes are generally not necessary. It’s your decision, though. (Disks over 8 GB outright require a /boot partition.)
Do NOT forget to make the swap file system on the new swap partition! (It is nice in some cases to use an older, smaller hard drive with a single partition for your swap partition. If you do this you don’t need to worry about a swap partition on your new hard drive. But don’t use a slow drive for the swap drive!)
5. Depending on the distro you’re currently running, your old hard drive’s partitions may already be mounted. You will, almost certainly, have to mount the new hard drive’s partitions once they’re created and formatted. See my page on this subject if you need help. I’d suggest:
mount /dev/hda1 /oldboot #assuming your old drive is hda
mount /dev/hda2 /oldroot
mount /dev/hdc1 /newboot #assuming your new drive is hdc
mount /dev/hdc2 /newroot
6. You are going to need to know the name of your old hard disk’s kernel:
and look for the kernel file. It may be named vmlinuz, bzImage, or almost anything. Look for a file of about 1.5 MB size or larger. Write down its name.
7. It’s time to transfer data from the old disk to the new one. One partition at a time, tar and transfer the contents of each partition. Change to each source partition to do this. I’d suggest:
tar cvplf – ./ | (cd /newboot; tar xplf -)
tar cvplf – ./ | (cd /newroot; tar xplf -)
8. Shut down the computer when this is done. Remove the old hard drive, and move the new one to the old one’s position on the IDE or SATA cable. Don’t forget to set the master/slave jumpers on the new drive to match the old one.
9. Now, boot your system to the floppy you prepared earlier. You’ll be in DOS, so you’ll need to load Linux with loadlin:
LOADLIN bzImage ro root=/hda2
This assumes your kernel image is named bzImage, and that your / partition is mounted at hda2.
Your system should boot. If it doesn’t, it’s time to troubleshoot further. One unfortunate possibility is that your old files may have been corrupted by the old hard drive’s failure, but don’t just give up!
10. Reinstall your boot loader. You must be root to do this. If it’s LILO, command:
If it’s GRUB (which I recommend), command:
If you’ve changed partition layouts, you’re going to have to edit your LILO or GRUB configuration file before reinstalling your boot loader (I told you to keep it simple).
11. Moment of truth: shut down, remove your DOS floppy, and reboot. If it does (and it likely will), you’re done. If it doesn’t, you now have the opportunity to become a more accomplished Linux geek by getting on the Internet and doing your own research.