The below article will assume that you have one of the following hardware configurations:
A stand-alone drive which presents itself to the OS as a device name (like /dev/sdc for example)
A RAID Array configured on a RAID device, which presents itself to OS as a device name (like /dev/sdc for example)
Use the below command to initiate fdisk for formatting the disk.
Note: If the disk is over 3TB, and you're running an older version of FDISK, you'll need to use "parted" instead.
root@server:~# fdisk /dev/sdcNow we'll be presented with an fdisk shell on our console. We want to view the current disk's information to see if it's empty. In the example below it's a 480GB SSD drive and we’re using ‘p’ to print the information on-screen:
Command (m for help): p
Disk /dev/sdc: 480.1 GB, 480103981056 bytes
255 heads, 63 sectors/track, 58369 cylinders, total 937703088 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x80ed6cbb
Device Boot Start End Blocks Id System
We've now confirmed we have the right disk, so we’ll move towards creating a partition. Below, you'll find the commands necessary to create a simple full-size partition. (__ denotes "default value - Press Enter")
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): __
Using default value 1
First sector (2048-937703087, default 2048): __
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-937703087, default 937703087):
Using default value 937703087Check the partition has shown up correctly:
Command (m for help): p
Disk /dev/sdc: 480.1 GB, 480103981056 bytes
255 heads, 63 sectors/track, 58369 cylinders, total 937703088 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x80ed6cbb
Device Boot Start End Blocks Id System
/dev/sdc1 2048 937703087 468850520 83 LinuxEverything is looking good based on the information we’ve seen, now we will go ahead and "WRITE" it to apply the changes to the disk directly:
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.So now we have our partition; we want to create an EXT4 Filesystem on it specifically for our example.
root@server:~# mkfs.ext4 /dev/sdc1
mke2fs 1.42 (29-Nov-2011)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
29310976 inodes, 117212630 blocks
5860631 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
3578 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: doneNow that the filesystem has been created, we will move ahead with the next steps required and locate the disk's UUID, create a mount point, mount it, and configure it for mounting on boot.
In the example below we can locate our Disk UUID. We will only need UUID="9262f711-a6ba-4aad-dac4-a73eb92225e0" from the below example (your output will be different):
root@server:~# blkid /dev/sdc1
/dev/sdc1: UUID="9262f711-a6ba-4aad-dac4-a73eb92225e0" TYPE="ext4"We're going to configure to auto-mount it to a folder titled "/db2" in the root file directory of the operating system. Below is a default value. You will need to set the UUID (as shown above), mount point, and filesystem type.
root@server:~# echo "UUID=9262f711-a6ba-4aad-dac4-a73eb92225e0 /db2 ext4 defaults 0 0" >> /etc/fstabNow we want to create the mount point and mount our new drive:
root@server:~# mkdir /db2
root@server:~# mount /db2As you can see below, it's now mounted, and available in the below directory:
root@server:~# df -h /db2
Filesystem Size Used Avail Use% Mounted on
/dev/sdc1 441G 199M 418G 1% /db2