- How to Create a New Ext4 File System (Partition) in Linux
- Creating a New Partition in Linux
- Formatting New Ext4 Partition
- Mounting New Ext4 Parition in File System
- Related Posts
- 13 thoughts on “How to Create a New Ext4 File System (Partition) in Linux”
- How to Create a Virtual HardDisk Volume Using a File in Linux
- Create a New Image to Hold Virtual Drive Volume
- Removing Virtual Drive Volume
- Creating a filesystem on a file in linux for software development purposes
- 1 Answer 1
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.
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
To print the partition table on the device /dev/sdb or detailed information about the new partition, run the print command.
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
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) :
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.
Related Posts
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
How to Create a Virtual HardDisk Volume Using a File in Linux
Virtual Hard Disk (VHD) is a disk image file format which represents a virtual hard disk drive, capable of storing the complete contents of a physical hard drive. It’s a container file that acts similar to a physical hard drive. The disk image replicates an existing hard drive and includes all data and structural features.
Just like a physical hard drive, a VHD can contains a file system, and you can use it to store and run an operating system, applications, as well as store data. One of the typical uses of VHDs in VirtualBox Virtual Machines (VMs) to store operating systems and application, and data.
In this article, we will demonstrate how to create a virtual hard disk volume using a file in Linux. This guide is useful for creating VHDs for testing purposes in your IT environment. For the purpose of this guide, we will create a VHD volume of size 1GB, and format it with EXT4 file system type.
Create a New Image to Hold Virtual Drive Volume
There are number of ways you can do this, but the most easiest way is using the following dd command. In this example, we will be creating a VHD volume of size 1GB image.
$ sudo dd if=/dev/zero of=VHD.img bs=1M count=1200
- if=/dev/zero: input file to provide a character stream for initializing data storage
- of=VHD.img: image file to be created as storage volume
- bs=1M: read and write up to 1M at a time
- count=1200: copy only 1200M (1GB) input blocks
Next, we need to format the EXT4 file system type in the VHD image file with the mkfs utility. Answer y , when prompted that /media/VHD.img is not a block special device as shown in the following screenshot.
$ sudo mkfs -t ext4 /media/VHD.img
In order to access the VHD volume, we need to mount to a directory (mount point). Run these commands to create the mount point and mount the VHD volume, respectively. The -o is used to specify options for mounting, here, the option loop indicates the device node under the /dev/ directory.
$ sudo mkdir /mnt/VHD/ $ sudo mount -t auto -o loop /media/VHD.img /mnt/VHD/
Note: The VHD filesystem will only remain mounted until the next reboot, to mount it at system boot, add this entry in the /etc/fstab file.
/media/VHD.img /mnt/VHD/ ext4 defaults 0 0
Now you can verify the newly created VHD filesystem with mount point using the following df command.
Removing Virtual Drive Volume
If you don’t need the VHD volume anymore, run the following commands to unmount the VHD filesystem, then delete the image file:
$ sudo umount /mnt/VHD/ $ sudo rm /media/VHD.img
Using the same idea, you can also create a swap area/space using a file in Linux.
That’s all! In this guide, we have demonstrated how to create a virtual hard disk volume using a file in Linux. If you have any thoughts to share or questions to ask, reach us via the comment form below.
Creating a filesystem on a file in linux for software development purposes
This question originally start at Superuser.com https://superuser.com/questions/130032/available-filesystems-for-linux-that-are-case-insensitive Summary: My client has a PHP web application that was written and is served from a Windows environments. Unfortunately the past developer didn’t obey naming conventions so file includes are of the form «/file/At/SomethingHere.php» when on disk the path is actually «/File/at/Somethinghere.php». I do not want to use Windows for development but the filesystems I use (ext2, ext3 ) are case sensitive. I think the solution will be to create a filesystem like FAT 32 or similar, but I am somewhat clueless how to accomplish that. Starting to read up on DD and fdisk to figure out if those are the correct tools I will need. update: I totally agree that it would be better to fix the real problem then use a potentially unstable fix. But the client isn’t really receptive to the idea of paying me to make their code base linux friendly when it works fine for their Windows server.
1 Answer 1
I think you would be better off fixing the root cause rather than working around it. However, you can create a filesystem in a file using the following commands. This example creates a FAT32 filesystem. You can vary the format command and mount type parameter for other filesystem types.
# Create a 100 MB file named fatfs to store the filesystem dd if=/dev/zero of=fatfs bs=1M count=100 # Format the file system as FAT32 mkdosfs -F 32 fatfs # Mount the filesystem using the loop device mkdir fatmount mount -t vfat -o loop fatfs fatmount
Using the seek predicate of dd and a count of 0 will allow you to create a sparse file, which will only use up blocks in the underlying filesystem that are actually in use at the cost of having to allocate them as the inner filesystem is written to.