Loading...
 

How to Format and Mount a new disk


There are a series of steps you must complete in order to utilize a newly installed disk in Linux.

1. Use the following command to list all disks detected by the server:

# fdisk -l | grep '^Disk'

This will list all your disks as such:

Disk /dev/sda: 251.0 GB, 251000193024 bytes
Disk /dev/sdb: 251.0 GB, 251000193024 bytes

2. Use fdisk to partition the new disk, in this example we will use /dev/sdb.

# fdisk /dev/sdb

Command (m for help): n (This will create a new partition)

Command action

e extended

p primary partition (1-4)

p (Selecting to create a primary partition, select this if you have less than 4 partitions)

Partition number (1-4): 1

First cylinder (1-36481, default 1): 1

Last cylinder or +size or +sizeM or +sizeK (1-36481, default 36481): 36481 (This will default to the entire disk, enter a specific size if needed)

3. Use the 'p' command in fdisk to print the partition layout and ensure everything is setup correctly.

Command (m for help): p

Disk /dev/sdb: 250.0 GB, 251000193024 bytes

255 heads, 63 sectors/track, 36481 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start       End    Blocks   Id  System

/dev/sdb1             1      36481 292929210  83  Linux

4. Once all changes are verified, write the changes.

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

5. Format the new partition with a Linux filesystem (ex: ext3).

# mkfs.ext3 /dev/sdb1

6. Mount the new disk.

# mkdir /new_disk

# mount /dev/sdb1 /new_disk

# df -H

7. Setup /etc/fstab to mount the new disk on boot.

# vim /etc/fstab

Add the line:

/dev/sdb1 /new_disk ext3 defaults 1 2

then save and quit using :wq

You should now be able to access your new partition as well as it automatically mounting when the server has been rebooted.