Create the file system in linux

How to Create a New Ext4 File System (Partition) in Linux

The ext4 or fourth extended filesystem is a widely-used journaling file system for Linux. It was designed as a progressive revision of the ext3 file system and overcomes a number of limitations in ext3.

It has significant advantages over its predecessor such as improved design, better performance, reliability, and new features. Although it is best suited for hard drives, it can also be used on removable devices.

This article will show you how to create a new ext4 file system (partition) in Linux. We will first of all look at how to create a new partition in Linux, format it with the ext4 file system and mount it.

Note: For the purpose of this article:

  • We will assume that you have added a new hard drive to your Linux machine, in which you will create the new ext4 partition, and
  • If you are operating the system as an administrative user, use the sudo command to gain root privileges to run the commands shown in this article.

Creating a New Partition in Linux

List the partitions using the fdisk -l or parted -l commands to identify the hard drive you want to partition.

List Linux Partitions

Looking at the output in the screenshot above, we have two hard disks added on the test system and we will partition disk /dev/sdb .

Now use parted command to start creating the partition on the selected storage device.

Then create a partition using the mkpart command, give it additional parameters like “primary” or “logical” depending on the partition type that you wish to create. Then select ext4 as the file system type, set the start and end to establish the size of the partition:

Create a New Ext4 Partition

To print the partition table on the device /dev/sdb or detailed information about the new partition, run the print command.

Print Partition Table

Now exit the program using the quit command.

Formatting New Ext4 Partition

Next, you need to properly format the new partition with the ext4 file system type using the mkfs.ext4 or mke4fs command as follows.

Format a New Ext4 Partition

Then label the partition using the e4label command as follows.

Mounting New Ext4 Parition in File System

Next, create a mount point and mount the newly created ext4 partition file system.

Now using the df command, you can list all file systems on your system together with their sizes in a human readable format (-h) , and their mount points and file system types (-T) :

Show Linux Filesystem with Mount Points

Lastly, add the following entry in your /etc/fstab to enable persistent mounting of the file system, even after a reboot.

You might also like to read these following related articles:

That’s all! In this article, we’ve explained how to create a new partition in Linux, format it with ext4 file system type and mount it as a filesystem. For more information or to share any queries with us, use the feedback form below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

Читайте также:  Winmgmt что это за служба windows

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

How to Create, Format and Mount Filesystems in Linux

A filesystem is an organization of data and metadata on the storage device. If you want to access any files in Unix like operating system, 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 a file system, make sure you have enough unallocated disk space ( or free cylinders).

You can check disk space using fdisk -l or parted print free command:

Here you can see 1305 cylinders are present on ‘/dev/sda’ disk and used up to 1147 cylinders. Therefore, we can create a new partition.

You may use fdisk or parted command to create a new partition.

In the following example, I am using fdisk command to create a partition on the hard drive named ‘/dev/sda’ (first hard disk).

Step 2: Set Disk Label on the partition

You can use e2label command to set or change disk labels. The e2label command must be run as root user.

The following command set disk datafiles on the disk partition named ‘/dev/sda3’.

To view the disk label, run the following command:

Step 3: Create a filesystem

In Linux, you can create filesystem using mkfs, mkfs.ext2, mkfs.ext3, mkfs.ext4, mke4fs or mkfs.xfs commands. On RHEL and CentOS system you may install an additional package called e4fsprogs which can manage ext4 filesystem.

The following commands create an ext4 filesystem on the ‘/dev/sda3’ disk partition:

Step 3: Mounting a Filesystem

The most commonly used method for mounting the filesystem is either manually using mount command or by adding entries in /etc/fstab file, so that filesystem gets mounted during boot time.

In the above example, we have mounted ‘/dev/sda3’ partition to ‘/data’ directory.

You can verify by executing the following command:

Also, you can unmount /dev/sda3 using umount command.

Whenever linux system reboots the ‘/data’ filesystem gets unusable. If you want to use the filesystem again, you have to mount it manually.

To avoid this repeated mounting after Linux boot, we have to add entries in /etc/fstab file so it will be persistent over reboots.

Here we will brief about /etc/fstab configuration file. You should add an entry in fstab file as follows:

An example fstab file:

device name: Name of the device/partition or source path (What to mount) /dev/sda3

mount point: Where data is attached to the filesystem (Where to mount) /data

type of the FS: Type of the filesystem are ext2, ext3, ext4, nfs, proc, etc.

options: In this option, you can apply a security policy to the particular file system. For example, when you mount, you can either set no execution of the binaries or you can set read-only filesystem. By default, the filesystem is having rw, suid, rw, exec, auto, nouser and async.

dump: This is used for filesystem backup. If value zero is set, backup is ignored. If 1 is set, the filesystem is backed up.

fsck: This option is to determine on which order the filesystems should be checked.

Display Mount Information

You can run df -h or lsblk command to get mounted device information such as mount point, filesystem size, etc.

The findmnt is a very handy tool to list all mounted filesystem, run the command as below:

Читайте также:  Установка принтера hp 1020 linux роса

Conclusion

In this tutorial, we learn how to create a filesystem in Linux by first creating a partition, formatting, and finally mounted. If you have any questions or feedback, feel free to leave a comment.

Источник

How to create and mount filesystems in Linux

File System Types

Creating a file system writes information to the device and creates order of the empty space. This file system–related data consumes a small percentage of the space. The remaining space on the disk drive is split into small, consistently sized segments called blocks. Linux supports a number of file system types, some of which are described as follows.

Filesystem Description
ext2 High performance for fixed disk and removable media
ext3 Journaling version of ext2
ext4 Supports larger files and file system sizes
vfat MS-DOS file system useful when sharing files between Windows and Linux
XFS High-performance journaling file system
Btrfs Addresses scalability requirements of large storage systems

Creating Filesystems

The command to build a Linux file system on a device, or hard disk partition, is mkfs. The syntax for the command is:

The mkfs command is actually a front end for the different file system builder utilities such as mkfs.ext2 and mkfs.ext4. These utilities are executable directly from the command line. When using the mkfs wrapper, include the -t fstype option to specify the type of file system to be built. If not specified, the default file system type, ext2, is created.

To see which supported file system types are installed, use the ls /sbin/mkfs* command:

The mkdosfs, mkfs.msdos, and mkfs.vfat files are symbolic links to mkfs.fat.

Using mkfs

The default file system type created when using the mkfs command is ext2. As previously mentioned, mkfs is a wrapper that calls other file system build utilities. Therefore, any of the following commands create an ext2 file system on the specified device:

To create an ext3 file system, use any of the following commands:

To create an ext4 file system, use any of the following commands:

Configuration File

A number of options are available to customize block size, fragment size, blocks per group, journal options, number of inodes, and other parameters. Without including any options, the defaults that are specified in the /etc/mke2fs.conf configuration file are used.

File System Labels

A useful option for the file system build utilities is the -L name option. This assigns a label to the partition; this label can be used instead of the device name when mounting the file system. Labels are limited to a maximum size of 16 characters. For existing file systems, the e2label command is used to display or set a label.

File systems are automatically assigned a universally unique identifier (UUID). UUIDs can be used when mounting the file system. To display the UUID, the label, and the file system type, use the blkid command. The following examples illustrate creating different file systems, with and without a label, and displaying the information with the blkid command. To create an ext2 file system and display information, enter:

To create an ext3 file system and display information, enter:

To create an ext4 file system, assign a label name, and display information, enter:

Mounting File Systems

File systems on different partitions and removable devices, such as CDs, DVDs, or USB flash drives, must be attached to the directory hierarchy to be accessed. To attach a partition or device, a mount point must be created. A mount point is simply a directory created with the mkdir command. After a directory, or mount point, is created, attach the partition by using the mount command. Syntax for the mount command is:

The following example creates a mount point (/test) and attaches the partition:

Alternatively, mount the partition or device by referencing the UUID or label. The following example displays the UUID and label, using the blkid command, and mounts the partition by referencing each:

Читайте также:  Установка yii2 advanced linux

The mount command without any options displays all currently attached file systems:

In this example, the /dev/xvdf1 partition is mounted on /test. The file system type is ext4 and is mounted for both reading and writing. The df command also displays mounted file systems. Example:

The information in the proc file system displays mounted file systems. Example:

Mount Options

To specify mount options, use the –o flag followed by a comma-separated string of options. The following are some of the available options for the mount command:

  • auto: Allows the file system to be mounted automatically by using the mount –a command
  • loop: Mounts the image as a loop device
  • noauto: Disallows the automatic mount of the file system by using the mount –a command
  • noexec: Disallows the execution of binary files on the file system
  • nouser: Disallows an ordinary user (other than root) to mount and unmount the file system
  • remount: Remounts the file system in case it is already mounted
  • ro: Mounts the file system for reading only
  • rw: Mounts the file system for both reading and writing
  • user: Allows an ordinary user (other than root) to mount and unmount the file system

For example, to mount the /dev/xvdf1 partition on the /test mount point as read-only with only the root user able to mount and unmount the file system, enter:

To mount an ISO image by using the loop device (assuming that the ISO image is present in the current directory and the mount point exist), enter:

Journaling Mount Options

The ext3 and ext4 file systems have three journaling levels that can be set with the -o option in the mount command or in the options section of /etc/fstab:

  • data=journal: The highest level. The one that does the most journaling. This writes the journal entries for all the data and metadata changes. All data is committed into the journal before being written into the main file system.
  • data=ordered: The default mode. All data is forced directly out to the main file system before its metadata is committed to the journal.
  • data=writeback: The lowest level. Data ordering is not preserved. Data can be written into the main file system after its metadata has been committed to the journal.

Unmounting File Systems

To unmount a file system, use the umount command. The partition name, the device name, or the mount point is used as an argument. Example:

/etc/fstab File

The /etc/fstab file is called the file system mount table and contains all the information that the mount command needs to mount devices. When adding a new file system, create the appropriate entry in /etc/fstab to ensure that the file system is mounted at boot time. The following is an example of entries in the /etc/fstab file:

The first column is the device to mount. The UUID or the label name should be used in place of the device name, because device names could change. The second column is the mount point, except the swap partition entry. The third column is the file system type. The fourth column specifies mount options. The fifth column is used by the dump command. The number 1 means to dump the file system and 0 means the file system does not need to be dumped. The last column is used by the fsck program to determine the order in which file system checks are done at reboot time. The root file system should be specified with a value of 1 and the other file systems should have a value of 2. A value of 0 does not check the file system.

Источник

Оцените статью