/ Technical / Linux / New Harddrive

Installing Extra HDDs

When the HDD is physically installed in the machine you need to partition it before it can be formatted. You will need to be logged in as root to use fdisk and know the device name for your new HDD. If it is an IDE drive it will be /dev/hda, /dev/hdb, /dev/hdc or /dev/hdd depending which cable it is attached to and if it is a master or slave. Equivalent names for SCSI (or SATA) drives are /dev/sda, /dev/sdb, /dev/sdc or /dev/sdd. If it is a USB disk you may need to use the lsusb command to check the machine is seeing the disk.

fdisk /dev/hda

m will show a list of commands - they are all done in memory until you choose to write them to disk, so don't worry about trying them out. Double check the disk is actually empty using p.

Command (m for help): p

Disk /dev/hda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

If the drive came pre-partitioned,use the d command to delete them.

The new disk I am using for this example is to be formatted with one large partition so it can be used for extra file storage. Use n to create a new partition, make it primary, position 1 and maximum size.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-60801, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-60801, default 60801): 
Using default value 60801

You can use p to check the partition was created and if so w will save the changes and exit.

Now to format the new partition. As the device is known as /dev/hda and we only created 1 partition, we need to format /dev/hda1.

mkfs.ext3 /dev/hda1
mke2fs 1.37 (21-Mar-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
61063168 inodes, 122096000 blocks
6104800 blocks (5.00%) reserved for the super user
First data block=0
3727 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000

Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

If you do not have the mkfs.ext3 command on your machine, use mkfs -t ext2 -j /dev/hda1 as it is exactly the same.

HDD is installed, partitioned and now formatted. All that remains is to mount it as a usable disk and make sure this happens each time the machine is rebooted. Add the following line (or something similar) to /etc/fstab. Remember to add a carriage return as well!

/dev/hda1  /mnt/hda1  ext3  default 2 1

Now we can mount the HDD and if it works we know that it will happen on boot from now on.

mount /mnt/hda1