Monday, May 25, 2009

Add A New Harddisk To Linux Using Parted

If you have added a new harddrive, and want to take advantage of it in Linux, parted is a great tool to get you started. Parted is like fdisk, but a bit more challenging. Please note that when following this tutorial you will loose any data on the harddrive in question.

Finding the device name

The first task is to find the devicename of your new harddrive. SCSI disks are usually given device names like /dev/sda, /dev/sdb, /dev/sdc, /dev/sdd and so on (dependening of how many phsyical disks you have got. IDE disks are usually given device names like /dev/hda, /dev/hdb, /dev/hdc, /dev/hdd and so on. In this tutorial we will image we have added a second SCSI disk, we will treat it as /dev/sdb

Using parted

As root, type
parted /dev/sdb
and parted will now startup, expecting to perform work on our new harddrive.

First we create a disk label
(parted) mklabel msdos

Then we need to find the size of the disk, or more correctly the start- and end sector of the disk
(parted) print

The print command should display something like this:

Disk geometry for /dev/sdb: 0.000-102400.000 megabytes
Disk label type: msdos
Minor Start End Type Filesystem Flags

The geometry data will come in handy in our next command where we create a filesystem on the disk
(parted) mkpart primary ext2 0.000 102400.000

We can also make extra sure that we get a ext2 disk with the following command (please note that parted doesn’t support ext3):
(parted) mkfs 1 ext2

Now exit parted:
(parted) quit

Mounting the new drive

First create the mountpoint that you want to use for the new drive:
# mkdir /u01

Change the filesystem from ext2 to ext3:
# tune2fs -j /dev/sdb1
Now edit /etc/fstab and add the following line:
/dev/sdb1 /u01 ext3 defaults 1 1

The mount the new drive on mountpoint /u01:
# mount -a

Finally check that the new drive is mounted:
# df -k

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 5526416 2081024 3164660 40% /
/dev/sda1 101086 8613 87254 9% /boot
none 387852 0 387852 0% /dev/shm
/dev/sdb1 10317828 33460 9760252 1% /u01

No comments:

Post a Comment