In How To Build A Headless Server I wrote about building a Ubuntu server that hosts my web development as well as Windows 2000 Advanced server running in a virtual server. The box that I used to build the server is a Compaq D51C (P2.4GHz, 40G HD, 256M RAM) box that I purchased at a auction from a local school district. I added a couple of Gig of RAM and tried to run W2K as well as XP in the virtual server but it maxed out the CPU and really slowed down the performance. So I dropped the RAM to 1.23GB and am just runing LAMP and the W2K server.

Since the 40GB hard drive quickly filled up and one can never have enough storage I purchased a 320GB hard drive. In this article I'll walk through adding this second hard drive to the server.

...

After physically installing the drive and firing up the machine the first step is to determine what Linux sees. This is accomplished using the fdisk command.


jim@HDT-Svr:~$ sudo fdisk -l

Disk /dev/sda: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x799c799c

Device Boot Start End Blocks Id System
/dev/sda1 * 1 4681 37600101 83 Linux
/dev/sda2 4682 4865 1477980 5 Extended
/dev/sda5 4682 4865 1477948+ 82 Linux swap / Solaris

Disk /dev/sdb: 320.0 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xdce67914

Device Boot Start End Blocks Id System

fdisk -l lists the second drive as /dev/sdb. So the next step is to add a partition. Again the fdisk command will be used. After you run the command it will display a prompt that you may press m for the help screen as shown below.


jim@HDT-Svr:~$ sudo fdisk /dev/sdb

The number of cylinders for this disk is set to 38913.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help):

Since we are going to partition the whole drive using one partition we will make the partition a Primary partition. To add a new partition use the 'n' command, enter p to select the primary partition and enter 1. After the partition is created, print the partition table to check your work. If all looks well use the 'w' command to save the changes and exit.


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

Command (m for help): p

Disk /dev/sdb: 320.0 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xdce67914

Device Boot Start End Blocks Id System
/dev/sdb1 1 38913 312568641 83 Linux

Command (m for help): w

Now that we have a partition defined we need to create format the partition using the EXT3


jim@HDT-Svr:~$ sudo mkfs.ext3 /dev/sdb1

By default, ext2 and ext3 filesystems reserve 5% of the capacity of the partition for root, such that if the users fill up the partition, services running as root (as well as commands the root user runs) don't fail right away. Since this is going to be a data drive we are going to reduce the reserve to 1%.


jim@HDT-Svr:~$ sudo tune2fs -m 1 /dev/sdb1

Now the only thing left to do is mount the drive and share it so it can be used across the network. The first thing to do is to make a directory to mount the drive to. I'm going to be real creative here, but you can create a directory anywhere you like. Then I'll add the line in /etc/fstab that will automatically mount the partition to the directory.


jim@HDT-Svr:~$ sudo mkdir /hdb

jim@HDT-Svr:~$ sudo vi /etc/fstab
.....
# /dev/sdb1 = 320GB
/dev/sdb1 /hdb ext3 relatime,errors=remount-ro 0 1

Now I'll mount the partition.

jim@HDT-Svr:~$ sudo mount -a

As you can see adding a second hard drive is not rocket science. Just use a little care and common sense and you will be fine.