Format and Mount a new drive in RHEL (or any RedHat based Linux)

The first step is adding the disk. You can either do this by attaching a local drive to the server, zone a SAN drive to it or to add a virtual disk through VMWare. Either way the process for formatting and mounting will be the same.

1. Make sure you have privileged rights either by sudo or logging in as root.

2. Type fdisk -l

  • This will show you the physical disks detected by the OS. As you can see /dev/sda is the primary disk that the OS was installed to and it is already formatted with ext3 (Id 83).
  • /dev/sdb is the new disk that the OS has detected. This is not formatted and does not have any partitions.

3. Since /dev/sdb is the assigned device name–that is what we will format.

In this mode you can hit M at any time if you need help

4. We are creating a new partition. To do this, type N

5. Since this is a new “physical” disk, I am going to make it a primary partition, it is not a partition on an existing disk. To do this all I need to type is p.

6. It will then ask you what partition number you want to assign the disk. Anything in the range that it will allow will work. Linux allows you 4 primary partitions, after that they have to be extended.  Since this is the first partition on that disk assign it 1. This will make the partition /dev/sdb1.

7. Use defaults for the rest of the settings:

8. Type (p). This will show you the partition you just created.

9. When you are all done, type (w) to save your changes. If you do not do this, everything that you have done will not take effect.

10. If you enter df –h you will still not see the new partition you created. Why? Because it does not have a filesystem. You will have to create one.

11. Enter fdisk –l, you will see the new partition you created. The operating system labeled the device as /dev/sdb1 so this is what we will format.

12. To do so we need to run the mke2fs command. Enter the /sbin/mke2fs -j /dev/sdb1 command. (-j is just ext2 with journaling which is ext3). You will see the following if you did everything correctly.

13. Now that the filesystem is created, you need to mount it. To start this process you need to first create a directory to mount to. mkdir /u01 is what I do. If you need to mount it to something specific you can.

14. Now you need to label the partition. Do this by entering e2label /dev/sdb1 /u01. 

15.  Now you can finally mount the filesystem! To do this just enter mount /dev/sdb1 /u01. This will modify the /etc/mtab file.

16. After you enter the command if you type df –h you will see the new drive.

17. The filesystem will not auto mount the drive when the OS gets rebooted. To do this modify the /etc/fstab file. Use the bottom line from the example below as a reference.

Advertisements
Format and Mount a new drive in RHEL (or any RedHat based Linux)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s