Walker News

How To Create Ext3 Filesystem And Mount It To Linux?

After adding a new hard disk to RHEL, how do you create and auto mount Linux ext3 filesystem? In brief, there are 3 steps, i.e. create Linux partition then create ext3 filesystem and make Linux mount the new filesystem automatically.

Although it is possible to create ext3 filesystem on entire hard disk without create single primary partition, it is better initialize the hard disk with a partition table prior to create filesystem onto it (to avoid unforeseen issue).

Now, let’s go into detail of those 3 steps. The following steps are based on RHEL 5.2 but should be fit for reference if applied on other Linux distributions. Assuming the new hard disk is identified as /dev/sdb (2nd SCSI hard disk):

How to create Linux partition table?

Log in to Linux as root and execute fdisk to create 1 primary partition for entire hard disk, e.g.:
[root@localhost]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel. Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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

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

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

Now, get fdisk to display partition table created in previous step:
[root@localhost]# fdisk -l /dev/sdb

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start     End      Blocks   Id  System
/dev/sdb1          1     261     2096451   83  Linux

How to create Linux ext3 filesystem?

This following command creates ext3 filesystem on the single primary partition (/dev/sdb1) and name the volume label as “/newfs”:
mkfs -t ext3 -L /newfs -v /dev/sdb1

Unless override by -m option, mkfs allocates 5% of the filesystem blocks as reserved space for super-user. Apparently, the default percentage allocates huge amount of reserved blocks on a terabytes hard disk / partition.

How to mount new ext3 filesystem to Linux?

Firstly, create a mount point (directory), e.g. mkdir /newfs. Then, it is ready to mount the ext3 filesystem on /dev/sdb1 partition to /newfs (mount directory):
mount -t ext3 /dev/sdb1 /newfs

If there is no error, it should appear on df command. To unmount it, just execute umount /newfs.

To make it auto mount on each boot-up, just edit /etc/fstab and append this line:
LABEL=/newfs   /newfs   ext3   defaults   1   2

Then, use either one of these two commands to confirm changes made on /etc/fstab:
mount -t ext3 LABEL=/newfs /newfs
mount /newfs

If /etc/fstab errors are not corrected, Linux will not able to boot up until you fix the /etc/fstab file in single-user mode (see previous post on how to edit and save /etc/fstab file in maintenance mode).

Custom Search

2017  •  Privacy Policy