New 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:

(parted) mkpart Partition type? primary/extended? primary File system type? [ext2]? ext4 Start? 1 End? 20190

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.

# mkfs.ext4 /dev/sdb1 OR # mke4fs -t ext4 /dev/sdb1

Format a New Ext4 Partition

Then label the partition using the e4label command as follows.

# e4label /dev/sdb1 disk2-part1 OR # e2label /dev/sdb1 disk2-part1

Mounting New Ext4 Parition in File System

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

# mkdir /mnt/disk2-part1 # mount /dev/sdb1 //mnt/disk2-part1

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) :

Читайте также:  Команды linux для hdd

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.

/dev/sdb1 /mnt/disk2-part1 ext4 defaults 0 0

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.

I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Parted Command in Linux

TLDR Man Pages for Linux Commands

apt-get Command Examples

Ubuntu apt-cache Commands

apt Command Examples

Funny Linux Commands

13 thoughts on “How to Create a New Ext4 File System (Partition) in Linux”

Hello, I don’t know how Ravi Saive found out the size of the partition, but I’ve found you can use percent to size the partition (you can reply 100% to the question End? and it uses the whole free space available) Reply

Another thing that is missing is what sector size should be considered (physical or logical). In this example, it did not matter because both were the same. However, in my case the two are not the same. Which to choose? I would think that it is the logical sector size, but if we are dealing with /dev/sda (in my case), perhaps this indicates the use of the physical sector size. Reply

This would be a wonderful tutorial if I knew how you got the size for the new partition. It seems that you pulled the number 20190 out of thin air! How do I get the right number if I want to use the whole disk? Reply

0% and 100% as start and end work. Looks like the author copied some really old instructions. mklabel gpt should be your go-to today, otherwise, you will get errors with disks over 2.5ishTB Reply

Thanks for this article. Is there a way of renaming /mnt/disk2-part1 to something else than “disk2-part1“? Reply

# e2abel /dev/sdb1 disk2-part1

I prefer to use GParted to do my disk manipulations. With GParted I do not need to learn and remember cryptic, unintuitive commands. With a GUI application, there is much less chance of using the wrong option or misspelling a command and completely wiping out the entire disk. Reply

People for whom these instructions would be beneficial do not use servers. OTOH, people who use or deal with servers have this procedure memorized. Judging by the questions and comments so far, it seems that the posters have very little idea of what is being done. By using a GUI tool like GParted, they would SEE what is happening with the disk they are trying to partition rather than having to imagine it. I am all for using CLI but when it is actually an improvement on GUI. This is 2021 and, in the 30 years of Linux’s existence, many CLI procedures have been released as GUI tools. For some reason, Linux tech writers are pushing the command line as if it was The Greatest Thing Since Sliced Bread. Sure, CLI may be l33t but it certainly IS NOT inviting and encouraging to new Linux users. How many articles are there extolling the virtues of MS-DOS or even the current Windows command line? Reply

Читайте также:  Linux while on command line

Источник

How to Create a New Ext4 File System in Linux?

The hard disk in a computer is formatted with specific file system so that the operating system can read and write into it. For UNIX based systems we have various type of file systems. In this article we will see how to format a new partition in hard disk with ext4 file system.

Available Filesystem types

First we see what are the different file systems available for the current operating system. The below command lists all those file systems.

Running the above code gives us the following result −

/sbin/mkfs /sbin/mkfs.bfs /sbin/mkfs.cramfs /sbin/mkfs.ext2 /sbin/mkfs.ext3 /sbin/mkfs.ext4 /sbin/mkfs.ext4dev /sbin/mkfs.fat /sbin/mkfs.minix /sbin/mkfs.msdos /sbin/mkfs.ntfs /sbin/mkfs.vfat

Look at the Current Partitions

Next let’s look at the the current hard disk and their partitions available to the operating system. Based on this output we can decide to add a new hard disk or create a new partition in the existing desk and format it as ext4.

$ sudo fdisk -l [sudo] password for ubuntu:

Running the above code gives us the following result −

Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x06807e05 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 33554431 33552384 16G 83 Linux /dev/sda2 33556478 41940991 8384514 4G 5 Extended /dev/sda5 33556480 41940991 8384512 4G 82 Linux swap / Solaris

Adding a new partition

Using the same command but choosing a different argument as shown below. We see all the available formats that the OS can support and available for formatting.

$ sudo fdisk /dev/sda Command (m for help): l

Running the above code gives us the following result −

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT- 4 FAT16 

Next we choose the n option to create a new partition.

Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) First sector (39849982-41940991, default 39849982): Using default value 39849982 Last sector, +sectors or +stze(K,M,G> (39849982-41940991, default 4 1940991): Using default value 41940991

Now we issue the below command to make the sda5 partiton as a ext4 partition.

Источник

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

Filing papers and documents

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.

In Linux, when you create a hard disk partition or a logical volume, the next step is usually to create a filesystem by formatting the partition or logical volume. This how-to assumes you know how to create a partition or a logical volume, and you just want to format it to contain a filesystem and mount it.

Create a filesystem

Imagine you just added a new disk to your system and created a partition named /dev/sda1 on it.

    To verify that the Linux kernel can see the partition, you can cat out /proc/partitions like this:

[root@localhost ~]# cat /proc/partitions major minor #blocks name 253 0 10485760 vda 253 1 8192000 vda1 11 0 1048575 sr0 11 1 374 sr1 8 0 10485760 sda 8 1 10484736 sda1 252 0 3145728 dm-0 252 1 2097152 dm-1 252 2 1048576 dm-2 8 16 1048576 sdb
[root@localhost ~]# mkfs. mkfs.btrfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs 
[root@localhost ~]# mkfs.ext4 /dev/sda1 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=8191 blocks 194688 inodes, 778241 blocks 38912 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=799014912 24 block groups 32768 blocks per group, 32768 fragments per group 8112 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done
  1. In the previous step, if you want to create a different kind of filesystem, use a different mkfs command variation.

Mount a filesystem

After you create your filesystem, you can mount it in your operating system.

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

[root@localhost ~]# blkid /dev/vda1: UUID="716e713d-4e91-4186-81fd-c6cfa1b0974d" TYPE="xfs" /dev/sr1: UUID="2019-03-08-16-17-02-00" LABEL="config-2" TYPE="iso9660" /dev/sda1: UUID="wow9N8-dX2d-ETN4-zK09-Gr1k-qCVF-eCerbF" TYPE="LVM2_member" /dev/mapper/test-test1: PTTYPE="dos" /dev/sda1: UUID="ac96b366-0cdd-4e4c-9493-bb93531be644" TYPE="ext4" [root@localhost ~]#
[root@localhost ~]# mkdir /mnt/mount_point_for_dev_sda1 [root@localhost ~]# ls /mnt/ mount_point_for_dev_sda1 [root@localhost ~]# mount -t ext4 /dev/sda1 /mnt/mount_point_for_dev_sda1/ [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 7.9G 920M 7.0G 12% / devtmpfs 443M 0 443M 0% /dev tmpfs 463M 0 463M 0% /dev/shm tmpfs 463M 30M 434M 7% /run tmpfs 463M 0 463M 0% /sys/fs/cgroup tmpfs 93M 0 93M 0% /run/user/0 /dev/sda1 2.9G 9.0M 2.7G 1% /mnt/mount_point_for_dev_sda1 [root@localhost ~]#
UUID=ac96b366-0cdd-4e4c-9493-bb93531be644 /mnt/mount_point_for_dev_sda1/ ext4 defaults 0 0
root@localhost ~]# umount /mnt/mount_point_for_dev_sda1/ [root@localhost ~]# mount -a [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 7.9G 920M 7.0G 12% / devtmpfs 443M 0 443M 0% /dev tmpfs 463M 0 463M 0% /dev/shm tmpfs 463M 30M 434M 7% /run tmpfs 463M 0 463M 0% /sys/fs/cgroup tmpfs 93M 0 93M 0% /run/user/0 /dev/sda1 2.9G 9.0M 2.7G 1% /mnt/mount_point_for_dev_sda1
[root@localhost ~]# mount | grep ^/dev/sd /dev/sda1 on /mnt/mount_point_for_dev_sda1 type ext4 (rw,relatime,seclabel,stripe=8191,data=ordered)

Now you know how to create a filesystem and mount it persistently or non-persistently within your system.

Источник

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