Linux notes

IDE drive Fundamentals

Most common hard disk drives are IDE devices. This page describes a few common tasks related to such drives, i.e. installing them and making their contents available to your Linux system.

Hardware installation

The installation I describe here is particular to my VIA EPIA ME-6000 board, although it is extremely similar to installing a new drive in just about any machine. The photographs will show the ME-6000 however.

Like many modern motherboards, the ME-6000 has two IDE interfaces, a primary and a secondary. Each can have two IDE devices attached. The two interfaces are shown below - the one on the left is the primary and the one on the right the secondary. In my unmodified system, two hard drives are attached to the primary IDE interface. What we will do now is to add a third hard drive on the secondary IDE interface (which currently has no devices attached to it).

Attaching a hard drive to the IDE interface is simple. Simply plug in a standard IDE ribbon cable - this is a 40 pin cable that generally has three connectors, as shown below. The isolated connector at one end goes to the motherboard; the two connectors are few inches apart connect to the IDE devices. With the computer off (yes, people do forget!), attach the new drive to one of the connectors at the far end of the cable (conventionally, devices are added from the end of the cable first). Don't forget to connect up the power cable to the drive also.

Masters and slaves

IDE hard drives can be set as master, slave or unassigned. This is normally done by fitting the appropriate jumper over pins on the back of the hard drive, near the other drive connectors. There is normally a drawing on the drive label to tell you how to configure it.

Masters and slaves are a means of indicating which drive has priority on a particular IDE port. In our case, we only have one drive, so it will be the de facto master. There is no need to set the drive jumpers to indicate master status; they can simply be left off. Note that the drive must not be assigned as a slave - either master or unassigned.

BIOS configuration

Check the BIOS to make sure that the new drive will be detected when the system boots. How the BIOS setup screens are accessed varies depending on your machine - in the VIA boards the Delete key must be pressed during the initial phase of the boot process, when the 'VIA Mainboard' logo is shown. The BIOS screens will then be entered.

Once in the main Phoenix BIOS screen, choose 'Standard CMOS Features' and choose the 'IDE Secondary Master' menu. Make sure that the menu items 'IDE Secondary Master' and 'Access Mode' options are set to 'Auto'. If not, change them. You can also try 'IDE HDD Auto-Detection' if you like, although the BIOS will do this anyway next time the system boots.

Now that the BIOS is configured to look for a hard drive master on the secondary IDE port, exit the BIOS, making sure you choose the options to save your settings.

Linux configuration

The next task is to reboot and see if we can see the new drive in Linux. If so, we need to make it available to the system so that we can use it.

Checking visible IDE devices

After rebooting the system with the new drive attached, it is possible to make a quick check (as root) to see what IDE devices the system has detected. The new drive must show up at this point, in order for it to be used.

> ls /proc/ide
drivers  hda  hdb  hdc  ide0  ide1  via
Our new drive shows up as 'hdc'. Note that 'hd' means that the drive is an IDE device; 'c' means that it is the master drive on the secondary interface of the first IDE controller. You can have more than one IDE controller, as shown below. In our system, we see hda and hdb - the two disk drives on the primary interface of the first IDE controller, and now also hdc - the disk drive on the secondary interface of the first IDE controller. The VIA board only has one IDE controller (unless we add another), so if we added yet another drive it would appear as hdd.

Partitions: how is the drive divided up?

A disk partition is an area of the hard drive's available storage that can be used independent of other partitions on the same physical disk drive. A single hard drive can be (and often is) divided up into multiple partitions. In Linux, each partition is identified by a number appended to the hard drive identified mentioned above. So, for example, a partition might appear as 'hdc1' or similar.

Available partitions on a disk drive can be shown with the command:

> fdisk -l /dev/hdc
This will list the partitions into which the disk has been divided.
Disk  /dev/hdc: 2111 MB, 2111864832 bytes
128 heads, 63 sectors/track, 511 cylinders
Units = cylinders of 8064 * 512 = 4128768 bytes

Device		Boot	Start	End	Blocks	Id	System
/dev/hdc1	*	1	511	2060320+	FAT16
In this case, there's just one partition, hdc1. It's a boot partition and was formatted as FAT16 (probably DOS).

Mounting: accessing the disk drive partitions

In order to access the disk drive for reading and writing files in Linux, it must be mounted. This is a source of confusion to Windows users, where no such process exists - the disks are either available or not.

The process of mounting a drive means 'connecting the file system existing on a drive partition to a directory somewhere on your machine'. This directory is called a mount point, and it is where you will go to, after mounting, to see the data on the mounted drive. An example will make all this clear.

We want to work with the files that are on the hard drive hdc, in particular those in partition 'hdc1'. This is probably an old DOS disk from a PC, as we saw above. To do this, we need to create a mount point, which is simply an empty directory somewhere where we will eventually see the files on the partition hdc1. New mount points are typically created under the directory mnt, but they don't have to be. However, we'll follow this convention and make a directory called old_drive under mnt.

>mkdir /mnt/old_drive
If you examine the contents of /mnt/old_drive, you'll see it is empty - no sign of the contents of our recently added disk drive:
>ls /mnt/old_drive
returns nothing.

What we need to do is mount the drive with the mount command.

>mount /dev/hdc1 /mnt/old_drive
This command connects the file system on the IDE device /dev/hdc1 (our recently added hard drive and its first partition) to our newly created directory (mount point) /mnt/old_drive. Having done this, let's go back and examine the contents of our mount point again:
>ls /mnt/old_drive
anotherfile.txt	somefile.txt
These files exist on the recently added drive, and you can do anything you like with this drive simply by accessing it at /mnt/old_drive.

Unmounting

When you are finished using a mounted partition, you should unmount it. This cleanly breaks the connection you established between the disk drive partition and the mount point. The command to unmount is rather confusingly named umount - not unmount as you might expect.
>umount /mnt/old_drive
If you go back and look at the contents of the /mnt/old_drive directory after issuing this command, you'll see it is empty once more - the link with hdc1 has been removed, and the files are no longer accessible unless you mount it again.

Mounting a different type of filesystem

Sometimes the disk drive partition you want to mount will be of a different type than the one you are working on - for example, you may want to mount a Windows partition on a Linux machine in order to copy over some files. This can be done safely with the use of an argument to the mount command that specifies the type of file system to expect on the partition you are about to connect. The argument is -t , where type may be one of many things, most commonly: This can be combined with other arguments to mount to ensure the partition is handled properly. For example, an appropriate mount command for a Windows 98 or NT FAT partition would be:
>mount -t vfat -o iocharset=koi8-r, codepage=866 /dev/hdc1 /mnt/old_drive
whereas one for a FAT partition created under Windows 98, Windows 2000 or Windows XP would be:
>mount -t vfat -o iocharset=koi8-r, codepage=866, uni_xlate=1, /dev/hdc1 /mnt/old_drive