A filesystem is an organization of data and metadata on storage device. If you want to access any files in unix-like OS, the filesystem has to be mounted where the file resides. There are two ways to mount the filesystem and they are manual using mount command and boot time mounting.
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 following command.
[[email protected] ~]# 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 tool can be used to create new partition
[[email protected] ~]# 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 and mkfs.ext3.
[[email protected] ~]# 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
Most commonly used method for mounting filesystem is either manually using mount command or by adding entries in /etd/fstab, so that filesystem mount during boot time.
[[email protected] ~]# mount /dev/sda3 /dat
In above example, we have mounted /dev/sda3 partition to /dat directory. You can verify by executing following command.
[root[email protected] ~]# mount | grep -i sda3
/dev/sda3 on /dat type ext3 (rw)
Also, you can unmount /dev/sda3 using umount command.
[[email protected] ~]# umount /dat
Whenever Linux system reboots /dat 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.
[[email protected] ~]# 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
Name of the device/partition or source path (What to mount) /dev/sda3
Where data is attached to the filesystem (Where to mount) /dat
-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.
- How to Create Partition in Linux using fdisk Tool
- How to Forcefully Unmount NFS Mounted Directory in Linux
- Find Detailed NFS Mount Options in Linux