Saturday, July 14, 2007

add new harddisk to existing linux system

This page is intended for everyone who has existing rpm-based linux system from their harddrive and wants to add and install a new harddisk for more storage capacity. I am going to cover the simplest way to add a new harddisk in temrinal mode.

First, you need to confirm that you have physically connected the new harddisk to your system and you are currently inside the existing linux system.

Let us show your current harddisk parameter using fdisk.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[root@ver ~]# fdisk -l

Disk /dev/sda: 80.0 GB, 80025280000 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 5864 47102548+ 83 Linux
/dev/sda2 * 5865 5877 104422+ 83 Linux
/dev/sda3 5878 8185 18539010 83 Linux
/dev/sda4 8186 9729 12402180 5 Extended
/dev/sda5 8186 9467 10297633+ 83 Linux
/dev/sda6 9468 9729 2104483+ 82 Linux swap / Solaris

Disk /dev/sdb: 40.0 GB, 40019582464 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 2422 19454683+ 7 HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sdb2 2423 4865 19622925 f W95 Ext'd (LBA)
Partition 2 does not end on cylinder boundary.
/dev/sdb5 2423 4865 19622893+ 7 HPFS/NTFS

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As you can see, /dev/sda is my existing harddisk with linux installed from it and
my newly plugged harddisk /dev/sdb with existing 3 window$ partition on it namely
/dev/sdb1, /dev/sdb2, /dev/sdb5 .

I am going into more detailed contents of the new harddisk by doing so:


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[root@ver ~]# fdisk /dev/sdb

The number of cylinders for this disk is set to 4865.
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)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And press M for menus:


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Press p to view current partition tables with the new harddisk like so


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Command (m for help): p

Disk /dev/sdb: 40.0 GB, 40019582464 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 2422 19454683+ 7 HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sdb2 2423 4865 19622925 f W95 Ext'd (LBA)
Partition 2 does not end on cylinder boundary.
/dev/sdb5 2423 4865 19622893+ 7 HPFS/NTFS

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


which shows 3 window$ partition. Let us erase them by press d for deletion like so:


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Command (m for help): d
Partition number (1-5): 1

(1 stand for first partition)

Command (m for help): d
Partition number (1-5): 2

(2 for second partition and view the partition back again.)

Command (m for help): p

Disk /dev/sdb: 40.0 GB, 40019582464 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

which shows and confirms that those partitions were deleted from fdisk memory table. We need to write them permanently to disk like so:


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Drops you back to shell.

Since the partition were now deleted, here I am going to create a new linux ext3 partition like so :


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[root@ver ~]# fdisk /dev/sdb

The number of cylinders for this disk is set to 4865.
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): p

Disk /dev/sdb: 40.0 GB, 40019582464 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System


p show no partition at all, so we are going to proceed on creating a new table by pressin n .

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

and using the maximum storage capacity that fdisk found, which is 4865. I just hit ENTER for default values. Let me examine the partition table again:

Command (m for help): p

Disk /dev/sdb: 40.0 GB, 40019582464 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 4865 39078081 83 Linux

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


As you can see, /dev/sdb1 is now added with type ext3 (83) as chosen file system .

Back to shell, let us view all the harddisk and their parition again by issuing

# fdisk -l

which would show us similar lines like these

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Disk /dev/sda: 80.0 GB, 80025280000 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 5864 47102548+ 83 Linux
/dev/sda2 * 5865 5877 104422+ 83 Linux
/dev/sda3 5878 8185 18539010 83 Linux
/dev/s


da4 8186 9729 12402180 5 Extended
/dev/sda5 8186 9467 10297633+ 83 Linux
/dev/sda6 9468 9729 2104483+ 82 Linux swap / Solaris

Disk /dev/sdb: 40.0 GB, 40019582464 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 4865 39078081 83 Linux

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


which show my first and second hardisk with their corresponding partition tables and numbers.

Basically, we have just prepared the harddisk and allocates the number of partition we need.
For now, we have just created a single partition with the new installed harddisk . The old
window$ parition were totally deleted as well.

We are not done yet, we need to initialize and format the hardisk with journaling system while checking for bad blocks as well, like so:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[root@ver ~]# mkfs.ext3 -c -j /dev/sdb1

mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
4889248 inodes, 9769520 blocks
488476 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
299 block groups
32768 blocks per group, 32768 fragments per group
16352 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624

Checking for bad blocks (read-only test): done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you are in a hurry, you can just issue :

# mkfs.ext3 /dev/sdb1

Now, the harddisk is ready. You can mount it like

# mkdir /mnt/new

# mount /dev/sdb1 /mnt/new

Adding them to /etc/fstab would make the mounting permanently.

Now, enjoy your new harddisk.

Hope this helps.

EDITED:
Attached is another redo of adding a new harddisk uploaded to youtube. :)



0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy