How to convert and create ext2, ext3, ext4 file system in Linux

convert and create ext2, ext3, ext4 file system
Convert and create ext2, ext3, ext4 file system

How to convert and create ext2, ext3, ext4 file system in Linux Intro

There are file system in Linux like ext2, ext3, ext4. As Linux support many file system, this makes Linux very flexible. File system are used to regulate the way data is stored and accessed in any system. In this tutorial we will learn about the fundamentals of these file systems, we will also learn about how to convert from one files system to another. We are also going to discuss the features of each of these file systems.
Note: Please note that this tutorial is for educational purpose and it is advised to use the given commands very cautiously. 

What is File System?

File system is a structure that your Operating System uses to organize files on disks.
All Operating System has its own file system. Microsoft Windows uses FAT and NTFS as its file system. Similarly Linux uses ext2, ext3, ext4 etc. as its file system. 

Difference between ext2, ext3 and ext4 file system and which one is better?

Ext2- ext2 or Second extended file system. This file system is a replace of ext (extended file system). This file system is a default file system in many Linux kernel.

  • Ext2 file system does not have any journaling feature (A journaling feature is a feature that is used to repair any inconsistencies in a file that happens due to improper shutdown of any computer system)
  • In ext2 individual file size allowed is 16GB to 2TB.
  • In ext2 the full file system size allowed is 2TB to 32TB.
  • Ext2 file system is generally used for USB drive and SD card.

Ext3- Ext3 is third extended file system. ext3 file system was available starting from Linux kernel 2.4.15

  • Ext3 file system does have a journaling feature.
  • Here individual file size allowed is 16GB to 2TB
  • Full file system size allowed is 2TB to 32TB in ext3
  • Ext2 file system can be easily converted to Ext3 file system.

Ext4- Ext4 is fourth extended file system. ext4 file system was available starting from Linux kernel 2.6.19

  • Ext4 has the advantages of keeping the journaling feature on or off.
  • Ext4 has allowable individual file size is 16GB to 16TB.
  • Many new features have been added to ext4 file system like journal checksum, fast fsck, multiblock allocation, delayed allocation, sub directory scalability etc.
  • You can also easily mount ext3 file system as ext4.

How to know what file system you are using?

To know what file system your Linux OS is using use the below command. Look at the red bold text 'ext4', yes that's the file system what my computer system is using. you can do the same to find out file system of your Linux system.

# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root ext4       20G   16G  2.5G  87% /
devtmpfs                devtmpfs  483M     0  483M   0% /dev
tmpfs                   tmpfs     492M  2.4M  490M   1% /dev/shm
tmpfs                   tmpfs     492M   57M  436M  12% /run
tmpfs                   tmpfs     492M     0  492M   0% /sys/fs/cgroup
/dev/sda1               ext4      2.9G  153M  2.6G   6% /boot
/dev/mapper/centos-home ext4       68G   43G   22G  66% /home
tmpfs                   tmpfs      99M   12K   99M   1% /run/user/1000
tmpfs                   tmpfs      99M     0   99M   0% /run/user/0

How to create an ext2 file system?

You can create an ext2 file system using the command 'mke2fs'. You have to give the name of your device when running the command. To know the name of your device in Linux, type the below command.

# fdisk -l
Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 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
Disk label type: dos
Disk identifier: 0x5eb97f8e
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 968430329 484214141 83 Linux
/dev/sda2 968430336 976768064 4168864+ 82 Linux swap / Solaris
Disk /dev/sdb: 500.1 GB, 500107862016 bytes, 976773168 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
Disk label type: dos
Disk identifier: 0x7bcb6fa2
Device Boot Start End Blocks Id System
/dev/sdb1 * 2048 4743167 2370560 83 Linux

 

Now, to create file system, use the below command as given . In place of 'sda'  it could be 'sdb', 'sda1' or 'sda2'.


# mke2fs /dev/sda

How to create an ext3 file system?

To create an ext3 file system you have to use either mke2fs command or mkfs.ex3 command. See the example given below.

# mke2fs -j /dev/sda

or

# mkfs.ext3 /dev/sda


How to create ext4 file system?

For creating an ext4 file system you need to use command mke2fs or mkfs.ext4

# mke2fs -t ext4 /dev/sda

or

# mkfs.ext4 /dev/sda


How to convert one file system to another?

You also have the option of converting one file system to another. With the following examples you can easily convert from ext2 to ext3 or ext3 to ext4 etc.


File system convert from ext2 to ext3

To convert from ext2 to ext3 file system use the below command.

# tune2fs -j /dev/sda

To fix and repair use the below command

# e2fsck -pf /dev/sda


File system convert from ext3 to ext4

The below example is given for converting from ext3 to ext4 file system.

# tune2fs -O extents,uninit_bg,dir_index /dev/sda

To fix and repair use the below command

# e2fsck -pf /dev/sda

 


This is it with How to convert and create ext2, ext3, ext4 file system in Linux.

Download Our Free eBook now

Linux and UNIX Shell scripting ebook

Be the first to comment

Leave a Reply

Your email address will not be published.


*


shares