Skip to main content

Creating & converting ext2 3 4


ext2, ext3, ext4 filesystems creation on Linux

Ext2, ext3 and ex4 are most popular file systems on Linux, Ext2 was introduced in 1993 and was the first default file system in several linux distro like RedHat, Debian etc..
Here few examples show you how to create these filesystems.

Spearate journal and data on different device

In most of cases, and it is default, the journal(if there is) and data device are on the same block device. Seperate journal and data brings performance improvement, on the other hand, introduce the management complexity and the chance of data inconsistency risk.

Prepare block device

You can use a whole disk/lun for a filesystem, or partition it into different partitions by fdisk or parted

Create ext2 filesystem

    Maximum file size is 16GB – 2TB.
    Journaling feature is not available.
You can use any one of the command to create an ext2 filesystem
#mkfs -L <volume-label> -t ext2 /dev/sdxx

#mkfs.ext2 -L <volume-label> /dev/sdxx

#mke2fs -L <volume-label> -t ext2 /dev/sdxx
-t stands for filesystem type, default is ext2
-L stands for filesystem volume label

Create ext3 filesystem

    Ext3 file system was introduced in 2001 and same was integrated in Kernel 2.4.15 with journaling feature, which is to improve reliability and eliminates need to check file system after unclean shutdown.
    Max file size 16GB – 2TB.
    Provide facility to upgrade from Ext2 to Ext3 file systems without having to back up and restore data.
#mkfs -L <volume-label> -t ext3 /dev/sdxx

#mkfs.ext3 -L <volume-label> /dev/sdxx

#mke2fs -L <volume-label> -t ext3 /dev/sdxx

#mke2fs -L <volume-label> -j /dev/sdxx
-t stands for filesystem type, default is ext2
-L stands for filesystem volume label
-j stands for journal(as if using -t ext3 )

Created ext4 filesystem

    On October 2008, Ext4 as stable code were merged in the Kernel 2.6.28 which contains Ext4 file system.
    Backward compatibility.
    Max file size 16GB to 16TB.
    Ext4 file system have option to Turn Off journaling feature.
    Other features like Sub Directory Scalability, Multiblock Allocation, Delayed Allocation, Fast FSCK etc.
#mkfs -L <volumelabel> -t ext4 /dev/sdxx

#mke2fs -L <volume-label> -t ext4 /dev/sdxx

#mkfs.ext4 -L <volume-label> /dev/sdxx

Check a filesystem type

To tell a filesystem type, simply run
# df -T 

Filesystem           Type  1K-blocks    Used Available Use% Mounted on

/dev/sda2            ext4    1477292  391364   1009220  28% /

tmpfs                tmpfs   4030604   44456   3986148   2% /dev/shm

/dev/sda1            ext4     197157   59247    127519  32% /boot

/dev/mapper/vg0-home ext4   50281156 5702696  42017644  12% /home

/dev/mapper/vg0-opt  ext4     999320    2152    944740   1% /opt

/dev/mapper/vg0-tmp  ext4     499656     460    472984   1% /tmp

/dev/mapper/vg0-usr  ext4    3966144 3058724    702620  82% /usr

/dev/mapper/vg0-var  ext4    9964080  369196   9082068   4% /var
To list specific filesystem mounted, simply run
# df -t tmpfs

Filesystem     1K-blocks  Used Available Use% Mounted on

tmpfs            4030604 44456   3986148   2% /dev/shm
Utility tune2fs offers more options to let you display, set filesystem parameters




Convert ext2 to ext3, ext4
Can they be converted to each other ? answer is yes
Generally speaking, file system is divided into two segments called User Data and Metadata, luckily so far ext filesystems are made backward compatibility, so that they can be converted to each others.
Before start convertion
Convertion between ext2 to ext3, ext2 to ext4 can be done on the fly, however, it is always better to unmount file system and convert. I got into trouble once when converting ext2 to ext4, not a big deal, fixed by fsck.
All conversion can be done by utility tune2fs
Supported convertion:
Ext2 --> Ext3
Ext3 --> Ext2
Ext2 --> Ext4
Ext3 --> Ext4
Note: Ext4 to Ext2/3 convertion is kind of possible, but not supported and recommded.
Create an ext2 file system
# mkfs -L testfs -t ext2 /dev/mapper/vg0-lvol0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=testfs
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done                          
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
And, I saved a filesystem parameter list for this ext2 filesystem
#tune2fs -l /dev/mapper/vg0-lvol0 >ext2.parameters
Convert Ext2 to Ext3
Change an ext2 file system to ext3 by enabling the journal feature
# tune2fs -j /dev/mapper/vg0-lvol0
tune2fs 1.41.12 (17-May-2010)
Creating journal inode: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
What has been change?
# diff ext2.parameters ext3.parameters
< Filesystem features:      ext_attr resize_inode dir_index filetype sparse_super large_file
> Filesystem features:      has_journal ext_attr resize_inode dir_index filetype sparse_super large_file
< Free blocks:              2574545
> Free blocks:              2541744
> Journal inode:            8
> Journal backup:           inode blocks
Note: I excluded timestamp different
Convert Ext3 to Ext2
Just remove the journal
 # tune2fs -O ^has_journal /dev/mapper/vg0-lvol0
tune2fs 1.41.12 (17-May-2010)
Converting Ext2 to Ext4
Change an ext2 to ext4 file system by enabling the latest journaling feature. Run the following command.
# tune2fs -O dir_index,has_journal,uninit_bg /dev/mapper/vg0-lvol0
tune2fs 1.41.12 (17-May-2010)

Please run e2fsck on the filesystem.
After running this command we MUST run fsck to fix up some on-disk structures that tune2fs has modified.
# e2fsck /dev/mapper/vg0-lvol0
e2fsck 1.41.12 (17-May-2010)
One or more block group descriptor checksums are invalid.  Fix<y>? yes

Group descriptor 0 checksum is invalid.  FIXED.
...
Group descriptor 79 checksum is invalid.  FIXED.
testfs contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
testfs: 11/655360 files (0.0% non-contiguous), 79696/2621440 blocks

# tune2fs -O dir_index,has_journal,uninit_bg /dev/hdXX
After convertion, see the parameters changes
# diff ext2.parameters ext4.parameters
< Filesystem features:      ext_attr resize_inode dir_index filetype sparse_super large_file
> Filesystem features:      has_journal ext_attr resize_inode dir_index filetype sparse_super large_file uninit_bg
> Journal inode:            8
> Journal backup:           inode blocks
Convert ext3 to ext4
Convert an ext3 to ext4 filesystem, use the command.

# tune2fs -O extents,uninit_bg,dir_index /dev/mapper/vg0-lvol0
tune2fs 1.41.12 (17-May-2010)

Please run e2fsck on the filesystem.
After running this command we MUST run fsck to fix up some on-disk structures that tune2fs has modified.

# e2fsck /dev/mapper/vg0-lvol0
e2fsck 1.41.12 (17-May-2010)
One or more block group descriptor checksums are invalid.  Fix<y>? yes

Group descriptor 0 checksum is invalid.  FIXED.
...
Group descriptor 79 checksum is invalid.  FIXED.
testfs contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
testfs: 11/655360 files (0.0% non-contiguous), 79696/2621440 blocks

WARNING: You cannot revert or mount back to ext3 filesystem once you run above command.



Comments

Popular posts from this blog

sed

Sed Command in Linux/Unix with examples SED command in UNIX is stands for stream editor and it can perform lot’s of function on file like, searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace. By using SED you can edit files even without opening it, which is much quicker way to find and replace something in file, than first opening that file in VI Editor and then changing it. o     SED is a powerful text stream editor. Can do insertion, deletion, search and replace(substitution). o     SED command in unix supports regular expression which allows it perform complex pattern matching. Syntax: sed OPTIONS... [SCRIPT] [INPUTFILE...] Example: Consider the below text file as an input. $cat > geekfile.txt unix is great os. unix is opensource. unix is free os. learn operating system. unixlinux which one you choose. unix is easy to learn.unix ...

initramfs" file is deleted or corrupted on your RHEL or CentOS 7

Initrd/Initramfs image provides the capability to load a RAM disk by the boot loader. This RAM disk can then be mounted as the root filesystem and programs can be run from it. Afterwards, a new root file system can be mounted from a different device. The previous root filesystem which was mounted from initrd/initramfs is then moved to a directory and can be subsequently unmounted. Their are chances that either you might have accidentally deleted "initramfs" file from the /boot partition or it is corrupted due to some reason.  Then boot process will get interrupted and you will see below error: error: file '/initramfs-3.10.0-957.el7.x86_64.img' not found. Good news is you can still recover this "initramfs" by following below steps: Step 1 :  Mount RHEL or CentOS 7 ISO image on your physical server and boot from it. In case you are using HPE Prolient server you can mount this ISO image on iLO, if this is virtual environment then mount it accordingly and reboot...

nw commands

troubleshoot commands in Linux.   1. ifconfig ifconfig (interface configurator) command   is use to initialize an interface, assign IP  Address to interface and enable or disable  interface on demand. With this command  you can view IP Address and Hardware / MAC   address assign to interface and also MTU (Maximum transmission unit) size. # ifconfig   eth0       Link encap:EthernetHWaddr 00:0C:29:28:FD:4C inet addr:192.168.50.2   Bcast:192.168.50.255   Mask:255.255.255.0           inet6 addr: fe80::20c:29ff:fe28:fd4c/64 Scope:Link           UP BROADCAST RUNNING MULTICAST   MTU:1500   Metric:1           RX packets:6093 errors:0 dropped:0 overruns:0 frame:0  ...
# # #