Add a new disk to a Linux system

This is the procedure I use to add a disk to any of my fedora / centos / redhat systems.

Step 1: Hardware installation

Shutdown the machine. Add the disk as normal (in hardware terms) Update BIOS and make sure the machine sees the disk. Reboot the machine.

The first thing you’ll notice is that Fedora does not prompt you that a new disk has been added. Kudzu, the tool which checks for hardware changes, ignores HDDs. So we’ll have to do it manually. Trust me, it doesn’t take long.

Open a shell and su to root.

Step 2: Create the partition on the disk

Type in the command as follows. Replace my device name /dev/hdc with yours as appropriate. Linux labels IDE hard drives as follows:

Primary master = /dev/hda Primary slave = /dev/hdb Secondary master = /dev/hdc Secondary slave = /dev/hdd

So in my case the drive is /dev/hdc and so the command is:

fdisk /dev/hdc

if you are installing a large disk you will receive warnings – ignore them.

You are now within fdisk so to create a partition type in

n (new partition)
p (primary partition)
1 (partition number 1)
<enter> (take default start cylinder in my case 1)
<enter> (take default end cylinder in my case 48641)
w (rewrite partition table to the disk)

the last command will also exit fdisk

Step 3: Format the partition

OK I have my partition but it is not formatted. The command to do this in my case is

mkfs.ext3 -L /share2 /dev/hdc1

mkfs.ext3 actually creates the partition. -L /share2 is the label of the partition, I normally label mine to match the mount point, keeps things cleaner. /dev/hdc1 – notice the change? Not using /dev/hdc any more. That’s because I’m formatting a partition, not a disk. /dev/hdc1 is, logically, the first partition on the secondary master drive /dev/hdc. Simple

This command will just run, give you a few facts and figures, then exit. Congrats! We’re formatted!

Step 4: Create a mount point and change the system to mount automatically

Linux partitions are mounted on directories, so we need to create the directory entry before we can mount. In my case I want to mount this new drive on /share2, so the command is:

mkdir /share2

That’s the mount point taken care of. Now I want to make sure the machine mounts the partition at reboot, so I need to edit the file systems table, /etc/fstab. I use vi, if you have a preferred text editor use it.

I added a line to /etc/fstab as follows:

LABEL=/share2 /share2 ext3 defaults 1 2

Translation: LABEL=/share2 – filesystem labelled /share2 – see step 3 – now perhaps you see why I label to match mount points /share2 – mount on directory /share2 ext3 – the filesystem type defaults – use default permission handling 1 2 – “1” =- available to the Linux dump command ( a backup utility), “2” – fsck behaviour, normally a value of “1” is used for boot filesystems and “2” for all others.

That’s it! Reboot and enjoy all those extra bytes

source

If the disk is larger than 2TB

the game changes at 2TB as we hit the MBR limits. We need to use GPT instead :

greater than 2TB disk use gnu parted to overcome mbr limitation in MBR

parted -a optimal /dev/sdb
 mklabel gpt
 mkpart primary ext4 1 -1
 print
 quit

mkfs.ext4 -L /data /dev/sdb1

fdisk /dev/sda
p
n
primary
default
default
w
quit

reboot
mkfs.ext4 -L /data2 /dev/sda4

vi fstab
add the following:
/dev/sdb1               /data/store             ext4    defaults        1 2
/dev/sda4               /data/data2             ext4    defaults        1 2
Posted on July 13, 2012 at 7:05 by simon · Permalink
In: Linux · Tagged with: , , , , , ,

Leave a Reply