- 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”
- Команда mkfs в Linux
- Синтаксис
- Опции
- Типы файловых систем
- Выбор файловой системы
- Создание файловой системы
- Выводы
- How to Create XFS File System in Linux (Step by Step)
- Create XFS file system and internal log on same disk
- Create XFS file system and Internal Log on separate disk
- Create XFS File system on LVM
- Mount XFS File system
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
Команда mkfs в Linux
Команда mkfs (Make file system) используется в Linux чаще всего для создания файловой системы в разделе жёсткого диска.
Синтаксис
mkfs [параметры] [-t ] [параметры ФС] []
Опции
-t, —type= <тип>Тип файловой системы; ext2, если ничего не указано fs-options Параметры для программы создания реальной файловой системы Путь к используемому устройству Число используемых блоков устройства -V, —verbose Подробная информация о выполняемых действиях; указание параметра -V более одного раза приведет к тестовому запуску
Типы файловых систем
Вы можете увидеть список файловых систем, доступных для создания вашим дистрибутивом Linux. Для этого следует набрать в терминале команду и дважды нажать клавишу Tab:
Эти варианты предлагают дистрибутивы Arch Linux и Ubuntu
Выбор файловой системы
Самой популярная файловая система Linux в настоящее время — Ext4. Она проверена, надёжна и является стандартной для ряда дистрибутивов. Ext4 позволяет уменьшить фрагментацию файлов и работать с очень большими дисками, разделами и файлами.
Создание файловой системы BFS вряд когда-либо потребуется, так как она является загрузочной и создаётся при установке Linux.
Системы MSDOS и FAT являются устаревшими и мало кому-нибудь нужны.
Система VFAT обычно используется на внешних носителях: флеш-накопителях, картах памяти.
Файловая система NTFS может потребоваться тем пользователям, которые хотят получить совместимость с операционной системой Windows.
Создание файловой системы
Помните! Все данные, находившиеся ранее на разделах будут безвозвратно утеряны!
Создаём файловую систему ext2 на /dev/sdb1 :
oleg@mobile:~:$ sudo mkfs -t ext2 /dev/sdb1 mke2fs 1.46.5 (30-Dec-2021) /dev/sdb1 contains a ext2 file system created on Sat Jul 2 11:34:38 2022 Proceed anyway? (y,N) y Creating filesystem with 3781376 4k blocks and 946560 inodes Filesystem UUID: d1be6ca8-ecd2-4e35-af67-5cceb323cb4e Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208 Allocating group tables: done Writing inode tables: done Writing superblocks and filesystem accounting information: done
При создании файловой системы ext2 можно использовать команду mkfs и так:
Утилита mkfs без опций также создаст файловую систему ext2 по умолчанию.
При создании других файловых систем необходимо указывать их тип.
Проверка устройства хранения на наличие бед-блоков:
oleg@mobile:~:$ sudo mkfs -c /dev/sdb1 mke2fs 1.46.5 (30-Dec-2021) /dev/sdb1 contains `DOS/MBR boot sector' data Proceed anyway? (y,N) y Creating filesystem with 3781376 4k blocks and 946560 inodes Filesystem UUID: d1cf78a6-aa45-41d7-9889-2e23c8103f06 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208 Checking for bad blocks (read-only test): done Allocating group tables: done Writing inode tables: done Writing superblocks and filesystem accounting information: done
Подобная проверка занимает значительное время.
Проверка типа файловой системы носителя:
oleg@mobile:~:$ sudo file -sL /dev/sdb1 /dev/sdb1: Linux rev 1.0 ext2 filesystem data, UUID=d1be6ca8-ecd2-4e35-af67-5cceb323cb4e (large files)
Выводы
Использование команды Linux mkfs не представит серьёзных трудностей даже при недостатке опыта. Необходимо лишь быть очень внимательным, ведь по ошибке можно навсегда распрощаться с данными, находившимися ранее на разделах диска.
How to Create XFS File System in Linux (Step by Step)
XFS is a 64-bit journaling file system and used where high performance is required. XFS file system is available in most of the linux distribution like Ubuntu, Debian and RHEL. In RHEL based distributions XFS is the default file system.
In guide, we will learn how to create XFS file system from the scratch step by step and then also learn how to mount and use it. For managing file system in Linux, we need a user with sudo privileges. For the demonstration purpose, I have attached 10 GB (/dev/sdb) disk to my linux system. I would be creating XFS file system on it.
Let’s deep dive into the steps,
Create XFS file system and internal log on same disk
Use mkfs.xfs command to create xfs file system and internal log on the same disk, example is shown below:
Create XFS file system and Internal Log on separate disk
If you want to place journal on another disk while creating xfs file system, then it is also possible. Let’s assume I have /dev/sdc disk where I want to store journal of xfs file system. Run beneath command,
$ sudo mkfs.xfs -l logdev=/dev/sdc,size=10000b /dev/sdb
To overwrite the existing xfs file system, use ‘ -f’ option on mkfs.xfs command
$ sudo mkfs.xfs -f -l logdev=/dev/sdc,size=10000b /dev/sdb
In above command, value after size parameter shows that number of blocks (10000)
Create XFS File system on LVM
To create LVM based file system, refer the following steps,
1 ) Create Physical Volume (PV)
Create pv on disk /dev/sdb, run
Run beneath vgcreate command to volume group on pv /dev/sdb,
$ sudo vgcreate vg01_xfs /dev/sdb
3) Create LV (Logical Volume) from VG
Use below lvcreate command to create logical volume of size 10 GB,
$ sudo lvcreate -L 9.9G -n lv01_xfs vg01_xfs
4) Format LV (logical volume) with XFS file system
Run below mkfs.xfs command to format lv (/dev/vg01_xfs/lv01_xfs) with xfs file system,
$ sudo mkfs.xfs /dev/vg01_xfs/lv01_xfs
Output of above commands would look like below:
Mount XFS File system
To mount a file system in linux, first we must have mount point, let’s create the mount point as ‘ /var/data ’, run
Now run following mount command to mount xfs file system,
$ sudo mount /dev/vg01_xfs/lv01_xfs /var/data/ $ df -Th /var/data/ Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vg01_xfs-lv01_xfs xfs 9.9G 103M 9.8G 2% /var/data $
This is a temporary mount, so to mount the xfs file system permanently add following entries in /etc/fstab file.
/dev/vg01_xfs/lv01_xfs /var/data xfs defaults 0 0
To access the file system, go to the mount point and try to create a file,
$ cd /var/data/ $ sudo touch testfile $ ls -l total 0 -rw-r--r-- 1 root root 0 Jan 10 10:31 testfile $
Great, above confirms that we have successfully able to write on xfs file system. That’s all from this guide, please do share your feedback and queries in below comments section.