Installing a new, additional disk or hard drive on your Linux system can be quite easy. Unfortunately, there are any number of little glitches that can occur along the way that can, quite literally, render your system unbootable. So, what should be a simple process can become a nightmare.
Herein, we outline the steps to follow to ensure a disaster-free installation of a new, additional disk (i.e. in addition to your current system disk).
The boot loader must boot from the fixed device that it is told to boot from (e.g. sda or hda). Presumably, the partitions on it are also fixed so why not always mount the same, fixed partition on root as well? Sadly, most OS distros don't come configured this way anymore. Instead, they boot from the fixed device and then go looking for a partition named "/". If you accidentally add a new drive that has a partition labeled "/" (e.g. a drive you are reusing from somewhere else) or if you inadvertently label a partition on the new drive as "/", you are screwed. You'd think that the loader would first look for the partition labeled "/" on the device it booted from. Not happening. For some reason, it has the uncanny knack of picking the wrong disk with 100% accuracy. Quite impressive but your boot sequence is going nowhere, since the loader will try to load the rest of the OS from the partition on the new disk. Even if you do luck out and hit a working OS, it will be on the wrong disk.
If you are using GRUB, the change is quite easy to make. Just open up either /boot/grub/grub.conf or /etc/grub.conf (its a symlink to /boot/grub/grub.conf) and add a few lines for the new boot choice. You can copy what's there (I make the copy the first choice and, hence, the default). Change its name and replace the "LABEL=/" string with "/dev/sda3" or whatever your root patition is. Here's an example of how the GRUB config for CentOS was hacked:
title NoLabel
root (hd0,0)
kernel /vmlinuz-2.6.18-92.1.22.el5 ro root=/dev/hda3 \
rhgb quiet crashkernel=128M@16M
initrd /initrd-2.6.18-92.1.22.el5.img
title CentOS (2.6.18-92.1.22.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-92.1.22.el5 ro root=LABEL=/ \
rhgb quiet crashkernel=128M@16M
initrd /initrd-2.6.18-92.1.22.el5.img
I added the "NoLabel" choice to allow me to boot without the stupid partition label matching feature. You might also want to change the "timeout" parameter to give you time to make a choice. Most OS distros set it to five seconds, which may be too short.
For GRUB, that's all there is to it. GRUB reads the config file on startup and does the rest. If you are still using LILO, you'll have to figure out how to hack its config file and then rebuild the boot sector that contains the config information. You're on your own.
/sbin/fdisk -l /dev/sdb
/sbin/fdisk /dev/sdb
There are number of simple commands that you can use: "m" - gives help; "d" - deletes a partition; "n" - creates a new one. Presumably, you are just going to need one partition but you may have to delete old ones, if you are reusing the disk. The "n" command will use the first available cylinder for the start of the partition and the last available cylinder for the end, by default.
When you are done partitioning the disk, the "w" command writes the new partition table and exits. If you change your mind, "q" exits without saving.
/sbin/mkfs.ext3 -j -T news /dev/sdb1
You'll want to think very carefully about using the "-L" (label) parameter. If you make a mistake and add the wrong label to the partition, you can remove it using the "-L" parameter of tune2fs but you'll have to boot the system without mounting the partition (which may require the use of a standalone system such as Knoppix) and there doesn't seem to be any percentage to adding a label in the first place. And, under no circumstances should you use something like "-L /" as this can easily result in the boot loader trying to boot or mount the wrong partition.
Incidentally, if you are not enamored of the fact that fsck, by default, is going to check the file system every so often, thereby delaying your boot, usually when its least convenient, you should change the check parameters like this:
/sbin/tune2fs -c 0 -i 0 /dev/sdb1
Once you are all done, you can verify the new file system with:
/sbin/dumpe2fs -h /dev/sdb1
mkdir /users
/dev/sdb1 /users ext3 defaults 0 2
After you've added the new drive to fstab, you can check that it mounts OK with:
mount -a
So, what do you do if you screw something up and the system won't boot? Well, despite the fact that it says "Kernel Panic", you shouldn't. The most common problem is that the loader boots from the wrong root partition. And, this is caused by the "LABEL=" parameter. Here's how to recover from it.
mount -o remount,rw /
An indispensible tool that can be used for creating new partitions and formatting them (or recovering from mistakes) is the standalone, single-CD bootable Linux variant called Knoppix. Using Knoppix, you can set up and initialize a new disk before it is ever installed in the target system. You can even use it to copy all of the data off of an original, system disk to the new disk without worrying about whether the data is changing while the system is running.
With the new and old disks installed in a machine that has a CD drive, the Knoppix CD is booted. You can use Knoppix to create the new partition(s) and initialize them. Once this is done, the new partition(s) can be populated using dd (if their size isn't to be changed) or they can be mounted, along with the original partition and copied as follows:
cp -R --preserve=all /media/sda1 /media/sdb1
In this case, the first partions on the sda and sdb devices are being copied. It may take a long time for this copy to proceed but it always works, including when the file system type is being changed (e.g. from resierfs to ext3) or the partition size is being altered (e.g. from smaller to larger on an XFS partition, which is not supported by many disk reorganization programs).