A filesystem is an organization of data and metadata on the storage device. If you want to access any files in unix-like OS, the filesystem has to be mounted where the file resides. The well-know Linux filesystems are Ext, Ext2, Ext3, Ex4, BtrFS, ReiserFS, ZFS, XFS, JFS and Swap.
Let's create a partition on Linux, create a filesystem and learn how to mount that filesystem.
Step 1: Create a Partition
Before creating make sure that you should have free cylinders. You can check by using the following command:
# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1020 8193118+ 83 Linux
/dev/sda2 1021 1147 1020127+ 82 Linux swap / Solaris
Here you can see 1305 cylinders are present on /dev/sda disk and used up to 1147 cylinders. Hence, we can create new partition using fdisk.
Fdisk command can be used to create a new partition
# fdisk /dev/sda
Press “Enter” for default starting cylinder”
Now Change the partition type to 83 and finally reboot the system.
Step 2: Create filesystem
In Linux, you can create filesystem using mkfs, mkfs.ext2, mkfs.ext3 or mkfs.ext4 commands (mke4fs).
# mkfs.ext3 /dev/sda3
mke2fs 1.39 (29-May-2006)
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
26208 inodes, 104420 blocks
5221 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
2016 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
Step 3: Mounting Filesystem
# mount /dev/sda3 /dat
In the above example, we have mounted /dev/sda3 partition to /dat directory.
You can verify by executing following command:
# mount | grep -i sda3
/dev/sda3 on /data type ext3 (rw)
Also, you can unmount /dev/sda3 using umount command.
# umount /data
Whenever linux system reboots /data filesystem unusable. If you want to use filesystem again, you have to mount it manually. To avoid this repeated mounting after Linux boot, we have to add entries in /etc/fstab. Fstab (filesystem table) file is filesystem configuration file.
Here we will brief about /etc/fstab configuration file.
# cat /etc/fstab
#device name mountpoint Type of fs options dump fsck
LABEL=/ / ext3 defaults 1 1
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
LABEL=SWAP-sda2 swap swap defaults 0 0
/dev/sda3 /data ext3 defaults 0 0
Name of the device/partition or source path (What to mount) /dev/sda3
Where data is attached to the filesystem (Where to mount) /data
-type of the FS
Type of the filesystem are ext2, ext3, nfs, proc, etc..
In this option, you can apply a security policy to the particular filesytem. For example, when you mount, you can either set no execution of the binaries or you can set read only filesystem. By default filesystem is having rw, suid, rw, exec, auto, nouser and async.
This is used for filesystem backup. If value zero is set, backup is ignored. If 1 is set, filesystem is backed up.
This option is to determine on which order the filesystems should be checked.
In this tutorial we learn how to create a filesystem in Linux by creating a partition, creating filesystem and then mounted. If you have any questions or feedback, feel free to leave a comment.