Partitioning and Creating and Ext3 or Ext4 filesystem CentOS

We will install a new serial ATA hard drive into our system, and it’s hooked to the second SATA port, thus making our drive “sdb.” Enter the following as root:

# fdisk /dev/sdb

This brings up how many cylinders are on your hard disk, and of course opens up the fdisk program that will allow us to partition our new hard disk.

The next step is to simply enter a “p” to show the partition table. This is useful to see what partitions are already setup on the disk.

Command (m for help): p

Disk /dev/sdb: 50.0 GB, 50019202560 bytes
255 heads, 63 sectors/track, 6081 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System

Command (m for help):

There are no partitions on it. If any partitions are present we’ll just go ahead and delete them by pressing “d.”

Next we’ll need to partition our drive. We’ll keep it simple and mount this drive with a large, single primary partition, just like a backup drive. To do that enter “n” at the command line to create a new partition.

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

Command (m for help):

As you can see, I hit “n” and it asked if I’d like to create a primary (P) or an extended partition (E) I hit P for a primary partition, entered “1″ for it being my first partition on the drive. Your first cylinder will be “1″ and the last one in our case will be “6081.” Most times you will be able to hit enter and use the default cylinder counts.

Verify that we’ve done everything correctly up until this point. At the command prompt enter “p” to check the partition table again:

Command (m for help): p

Disk /dev/sdb: 50.0 GB, 50019202560 bytes
255 heads, 63 sectors/track, 6081 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/sdb1             1      6081  48845601   83  Linux

Command (m for help):

Now you can see that we’ve added a partition to the drive, but we’re not done yet. No changes have been written to the disk yet, everything is just in memory. If everything looks right, go ahead and enter the “w” command which will write the changes to the disk.

Creating an ext3 file system

Now that our disk is partitioned to sdb1 we’ll need to format it. You can format your drive to any filesystem you want, but for our purposes here I’m going to format it with ext3, the most common today. To format your drive:

root@laxmi [~]# mkfs -t ext3 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
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
7331840 inodes, 29304560 blocks
1465228 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
895 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

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

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


Using the mk2fs (make file system) command, we specified the type (using the -t) ext3 using the device and partition name (/dev/sdb1). You have successfully partitioned and formatted your new drive. We need to mount this partition to make it usable, and add an entry in the file “/etc/fstab”

We’re going to add this entry in the fstab file because on reboot, our drive that we just mounted will need to be remounted. By adding a simple entry in the fstab file our drive will be mounted every time on startup. To do this we’re going to add the following code on the last line of the file “/etc/fstab”

/dev/sdb1               /backup                  ext3    defaults        1 2

Once you’ve added that to the last line in the file, save it and issue this final command as root:

# mount /dev/sdb1

The mount command mounts the drive for immediate use, and the /dev/sdb1 is our drives partition name.

Creating an ext4 file system

The easiest way to create a file system on a partition is to use the mkfs.ext4 utility which takes as arguments the label and the partition device:

YOU MAY GET THIS IS YOU DO NOT SPECIFY THE NUMBER…

# mkfs.ext4 -L /backup /dev/sdd
mke2fs 1.41.12 (17-May-2010)
/dev/sdd is entire device, not just one partition!

# /sbin/mkfs.ext4 -L /backup /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=/backup
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2097152 inodes, 8388352 blocks
419417 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
256 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

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

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

Mounting a File System

Now that we have created a new file system on the Linux partition of our new disk drive we need to mount it so that it is accessible. In order to do this we need to create a mount point. A mount point is simply a directory or folder into which the file system will be mounted. For the purposes of this example we will create a /backup directory to match our file system label (although it is not necessary that these values match):

# mkdir /backup

The file system may then be manually mounted using the mount command:

# mount /dev/sdb1 /backup

Configuring CentOS 6 to Automatically Mount a Ext4 File System

In order to set up the system so that the new file system is automatically mounted at boot time an entry needs to be added to the /etc/fstab file.

For ext 4 find the UUIS:

# blkid /dev/sdd1
/dev/sdb1: LABEL="/backup" UUID="6043e3e8-f0a3-405b-9905-9a6087fd02fe" TYPE="ext4"

Add to fstab

UUID=6043e3e8-f0a3-405b-9905-9a6087fd02fe /backup     ext4    1       1

The following example shows an fstab file configured to automount our /backup partition:

/dev/mapper/vg_centos6-lv_root /            ext4    defaults        1 1
UUID=0d06ebad-ea73-48ad-a50a-1b3b8ef24491 /boot  ext4    defaults        1 2
/dev/mapper/vg_centos6-lv_swap swap         swap    defaults        0 0
tmpfs                   /dev/shm            tmpfs   defaults        0 0
devpts                  /dev/pts            devpts  gid=5,mode=620  0 0
sysfs                   /sys                sysfs   defaults        0 0
proc                    /proc               proc    defaults        0 0
LABEL=/backup /backup      ext4    defaults        1 2

cPanel comes with a built in handy utility that will automatically detect, format, and partition your new drive with just a few clicks.

To install your new hard drive through cPanel you’ll need to login to WHM as root, and find the button on the left called “Format/Mount a new hard drive” under the drives tab about 3/4 the way down. Click on that. The next page will show you the newly detected drives and have a button next to the drive to select it. Once you select your new drive follow the onscreen instructions, and hit enter.

Leave a Comment