Linux make file system on

mkfs Command in Linux with Examples

The mkfs command stands for “make file system” is utilized to make a file system (which is, a system for organizing a hierarchy of directories, subdirectories, and files) on a formatted storage device usually, a partition on a hard disk drive (HDD) or it can also be a USB drive, etc. A partition is logically an autonomous part of an HDD. An organized segment is one to which a low-level arrangement or format, additionally called a physical format(organization), has been applied. It comprises separating the disk’s tracks into a predetermined number of divisions and filling the information zone of every segment with dummy bytes.

These outcomes in the demolition of any current information on the disk. Formatting(organizing) of new HDD and floppy plates is done at the manufacturing plant. It is seldom important to do a low-level format on an HDD. The creation of a file system is also known as high-level formatting or logical formatting. It includes making a table of contents for the partition or disk, but in this case, the data already present on the disk or segment is not destroyed. Basically, “mkfs” is just a front-end for the various specific file system creation programs that are available in Linux, such as mke2fs, mkfs.ext3 and mkfs.vfat, etc. When the “mkfs” command is compiled, then a precise list of standard directories is created, and therefore the specified program is searched for from the same list.

Syntax for mkfs command:

mkfs [ -V ] [ -t fstype ] [ fs-options ] filesys [ blocks ]
  • The items in the square brackets are discretionary, but the main obligatory argument is “filesys”. filesys is the name of a device document (i.e., a record that the system uses to execute admittance to a physical device), for example, /dev/hda3, the third segment on the primary HDD, or/dev/fd0, the principal floppy disk. It can likewise be the mount point (i.e., where it is joined to the system) for the new file system.
  • The most commonly used option is “-t”, which is utilized for specifying the type of file system to be created. If this option is not used, the default filesystem created will be ext2 (second extended file system) from the other types of file systems that can be created like ext3, minix, msdos, vfat and xfs.
  • The -V option is used to produce verbose output, and also includes all file system-specific commands that are executed. By specifying this option more than once, the execution of any file system-specific commands can be prevented.
  • The “-c” option, will check the storage device for bad blocks before creating the file system, and the “-l” option, will read the bad blocks list from a file whose name follows it.
  • “fs-options” stand for file system-specific options that are to be passed to the real file system creation program (i.e., the program for which mkfs is serving just as a front end).
Читайте также:  Виртуальная машина удаленный линукс

Journaling

It is a significant idea in file systems. The file system records the awaiting file keeps in touch with a diary. As each file is composed of, the diary is refreshed, and the unresolved setup accounts are refreshed. This permits the file system to fix broken, halfway composed files that have happened because of a disastrous occasion, for example, a power cut. A portion of the more seasoned file systems doesn’t uphold journaling. Those that don’t, keep in touch with the disk, less regularly in light of the fact that they don’t have to refresh the diary. They might give a faster performance, yet they are more inclined to harm because of interrupted file writes.

  • In the modern era, the way of utilizing mkfs is to type “mkfs.” and then the name of the file system you wish to create.
  • Now, in order to see all the file systems offered by the “mkfs” command, hit the Tab key twice.
  • The list of all available file systems available in the Linux distribution being used will be displayed in the terminal window. The screenshot is from Ubuntu 18.04 LTS. Other distributions may have more or fewer options:

mkfs journaling

To make a File System on a USB:

1. Finding the required device on the OS through the terminal. Type in the following command, and it will show all the disk nodes that are currently mounted. Be always sure in choosing the right disk or otherwise, you can remove the storage device and then again plug it in if the above command is not showing it in the list, thereafter again run the above command to list all the nodes. Here, our required disk is “/dev/sdb” which is of 3.7 GiB.

USB filesystem makemkfs make file system

2. Un-mounting the USB drive’s partition

Un-mounting the storage drive is necessary before performing the format. Run the following command, but remember to replace “sdb1″ with your USB drive’s partition label, and then press Enter.

3. Erasing all the data on the drive (discretionary)

You can erase everything on the drive by entering the following command. But, remember to supplant “sdb” with your USB drive’s name.

sudo dd if=/dev/zero of=/dev/sdb bs=4k status=progress && sync

erase all data

4. Creating a new partition table

Type in the following command, by replacing “sdb” with your USB drive’s label, and then press Enter.

Creating a new partition table

Enter “o” for creating an empty partition table.

Creating a new partition table

Enter the option “n” for creating a new partition.

Creating a new partition table

Enter “w” to write the table and exit.

Creating a new partition table

5. Execute the following command for viewing the partition.

6. Formatting the new volume created

Enter the following command and press Enter for formatting the drive as ext4. Remember to, replace “sdb1” with your partition’s label:

Читайте также:  Linux все запущенные демоны

7. Verifying the newly created filesystem

Run the following command in the terminal:

verifying created file system

8. Lastly, execute the following command for ejecting the drive when finished.

eject device file system

Now, We have successfully formatted the USB storage device and have also created a file system with a partition.

Источник

How to create filesystem on a Linux partition or logical volume

In this article I will share the steps to create filesystem on a linux partition or a logical volume and mount it persistently or non-persistently in your Linux system.

On a UNIX system, everything is a file; if something is not a file, it is a process

This statement is true because there are special files that are more than just files (named pipes and sockets, for instance), but to keep things simple, saying that everything is a file is an acceptable generalization. A Linux system, just like UNIX, makes no difference between a file and a directory, since a directory is just a file containing names of other files. Programs, services, texts, images, and so forth, are all files. Input and output devices, and generally all devices, are considered to be files, according to the system.

How to create a filesystem on a Linux partition or logical volume in Linux

In computing, a filesystem controls how data is stored and retrieved and helps organize the files on the storage media. Without a filesystem, information in storage would be one large block of data, and you couldn’t tell where one piece of information stopped and the next began. A filesystem helps manage all of this by providing names to files that store data and maintaining a table of files and directories—along with their start/end location, total size, etc.—on disks within the filesystem.

Create filesystem

Before we create filesystem we need a partition. For the sake of this article I have added a virtual disk to my vm and created a partition /dev/sdb . You can verify the list of available partitions using below command

[root@node1 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 30G 0 disk ├─sda1 8:1 0 512M 0 part /boot └─sda2 8:2 0 27.5G 0 part ├─centos-root 253:0 0 25.5G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 2G 0 disk └─sdb1 8:17 0 2G 0 part sr0 11:0 1 1024M 0 rom

You can also get the list of available disks and partitions using lsblk

[root@node1 ~]# cat /proc/partitions major minor #blocks name 11 0 1048575 sr0 8 0 31457280 sda 8 1 524288 sda1 8 2 28844032 sda2 8 16 2097152 sdb 8 17 2096128 sdb1 253 0 26738688 dm-0 253 1 2097152 dm-1 9 0 2094080 md0

Decide what kind of filesystem you want to create, such as ext4, XFS, or anything else. Here are a few options:

[root@node1 ~]# mkfs. mkfs mkfs.cramfs mkfs.ext3 mkfs.fat mkfs.msdos mkfs.xfs mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.vfat

For this article I will use mkfs.ext4 to create filesystem with ext4 type.

[root@node1 ~]# mkfs.ext4 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 131072 inodes, 524032 blocks 26201 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=536870912 16 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done

Mount a filesystem

After you create filesystem using mkfs, you must mount it in your operating system to be able to use it for storing data.

Читайте также:  Thunderbird перенос профиля linux windows

First, identify the UUID of your new filesystem. Issue the blkid command to list all known block storage devices and look for /dev/sdb1 in the output:

[root@node1 ~]# blkid /dev/sdb1 /dev/sdb1: UUID="dac636ff-cde2-4f26-8bfc-a2d7b7ab5aa4" TYPE="ext4"

Create a mount point for this newly created filesystem

[root@node1 ~]# mkdir /mount_point_for_sdb1

Next mount your partition /dev/sdb1 on this mount point

[root@node1 ~]# mount -t ext4 /dev/sdb1 /mount_point_for_sdb1

The df -h command shows which filesystem is mounted on which mount point.

[root@node1 ~]# df -h /mount_point_for_sdb1 Filesystem Size Used Avail Use% Mounted on /dev/sdb1 2.0G 6.0M 1.9G 1% /mount_point_for_sdb1

Substitute it with the UUID identified in the blkid command. Also, note that a new directory was created to mount /dev/sdb1 under /mount_point_for_sdb1 .

A problem with using the mount command directly on the command line (as in the previous step) is that the mount won’t persist across reboots. To mount the filesystem persistently, edit the /etc/fstab file to include your mount information:

UUID=dac636ff-cde2-4f26-8bfc-a2d7b7ab5aa4 /mount_point_for_sdb1 ext4 defaults 0 0

After you edit /etc/fstab , you can umount /mnt/mount_point_for_dev_sda1 and run the command mount -a to mount everything listed in /etc/fstab .

[root@node1 ~]# umount /mount_point_for_sdb1/

Next check if /dev/sdb1 is unmounted properly

[root@node1 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 25G 4.0G 20G 17% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 9.2M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 488M 198M 255M 44% /boot tmpfs 379M 12K 379M 1% /run/user/42 tmpfs 379M 0 379M 0% /run/user/0

Next run mount -a to mount all the partitions declared in fstab

If everything went right, you can still list df -h and see your filesystem mounted:

[root@node1 ~]# df -h /mount_point_for_sdb1/ Filesystem Size Used Avail Use% Mounted on /dev/sdb1 2.0G 6.0M 1.9G 1% /mount_point_for_sdb1

Lastly I hope the steps from the article to create filesystem and mount it persistently or non-persistently on Linux was helpful. So, let me know your suggestions and feedback using the comment section.

Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Источник

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