ext2, ext3, ext4 filesystems creation on LinuxExt2, 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 deviceIn 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 deviceYou can use a whole disk/lun for a filesystem, or partition it into different partitions by fdisk or partedCreate ext2 filesystemMaximum 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 filesystemExt3 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 filesystemOn 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 typeTo 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% /varTo list specific filesystem mounted, simply run # df -t tmpfs Filesystem 1K-blocks Used Available Use% Mounted on tmpfs 4030604 44456 3986148 2% /dev/shmUtility 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
Post a Comment