4 Managing the Ext File System
The extended file system, or Ext, is the first file system that was written for the Linux kernel and is in common usage across many Linux distributions. Ext has evolved through several successive updates and is available as the Ext4 file system, which is largely backward compatible with previous Ext file system releases but includes many added features. Key features available in Ext4, include:
- Large file system support: Ext4 can theoretically support volumes with sizes up to 1 EiB and single files with sizes up to 16 TiB.
- Use of extents instead of block mapping: improves large file performance and reduces fragmentation.
- Recognizes
fallocate
for persistent preallocation of on-disk space for a file: improves performance and helps to ensure contiguous disk allocation for a file. - Use of allocate-on-flush: helps with performance and reduces fragmentation by delaying disk space allocation until the moment that data is flushed to disk.
- Checksum functionality: ensures data integrity.
For more information, visit https://ext4.wiki.kernel.org/index.php/Main_Page.
This chapter describes tasks for administering the Ext file system in Oracle Linux 8. For an overview of local file system management, see About File System Management.
Converting an Ext File System to a Btrfs File System
You can use the btrfs-convert utility to convert an
ext
file system to a Btrfs file system. The utility preserves an image of
the original file system in a snapshot named extN_saved
,
such as ext4_saved
. With this snapshot, you can roll back the conversion,
even if you have modified the btrfs
file system.
Note that you can't convert the root file system or a bootable partition, such as
/boot
, to Btrfs.
Note:
The conversion to Btrfs isn't supported on the Arm (aarch64) platform. If you're running Oracle Linux 8 on the aarch64 platform, you can migrate data from one file system to another file system.
If you convert the root file system to Btrfs, you can use snapshots to roll back changes such as upgrades that you have made to the file system.
Converting a Non Root File Ext File System to a Btrfs File System
Caution:
Before performing a file system conversion, back up the file system from which you can restore its state.
To convert an ext
file system other than the
root file system to Btrfs:
-
Unmount the file system.
sudo umount mountpoint
-
Run the correct version of fsck (for example, fsck.ext4) on the underlying device to check and correct the integrity of file system.
sudo fsck.extN -f device
-
Convert the file system to a btrfs file system.
sudo btrfs-convert device
-
Edit the file
/etc/fstab
, and change the file system type of the file system tobtrfs
./dev/sdb /myfs btrfs defaults 0 0
-
Mount the converted file system on the old mount point.
sudo mount device mountpoint
Converting a Non Root Ext File System to a Later Version
Caution:
Before performing a file system conversion, make a backup of the file system from which you can restore its state.
-
Unmount the current file system:
sudo umount filesystem
-
Check the system by running the fsck command appropriate to the file system. For example, if the file system is
ext2
, you would use fsck.ext2 as follows:sudo fsck.ext2 -f device
-
Use the following command with the block device corresponding to the file system:
sudo tune2fs -j device
This command adds an
ext3
journal inode to the file system. -
Check the file system by using the fsck command appropriate to the higher version. For example, if the new file system is
ext3
, you would use fsck.ext3 as follows:sudo fsck.ext3 -f device
-
Correct any entry for the file system in the
/etc/fstab
file so that its type is defined as the later file system version, for example,ext3
instead ofext2
. -
Remount the file system.
sudo mount filesystem
For more information, see the tune2fs(8)
manual
page.
Converting a Root Ext File System to a Later Version
Caution:
Before performing a root file system conversion, make a full system backup from which you can restore its state.
-
Use the following command with the block device that corresponds to the root file system:
sudo tune2fs -j device
-
Identify which device is mounted as the root file system by running the mount command.
For example, the output of the following command shows that the root file system corresponds to the disk partition
/dev/sda2
:sudo mount
/dev/sda2 on / type ext2 (rw)
-
Shut down the system.
-
Boot the system from an Oracle Linux boot CD, DVD, or ISO.
You can download the ISO from the Oracle Software Delivery Cloud at https://edelivery.oracle.com/linux. For convenience, these images are also available from the Oracle Linux yum server at https://yum.oracle.com/oracle-linux-isos.html.
-
From the installation menu, select Rescue Installed System.
-
Select a language and keyboard, when prompted.
-
Select Local CD/DVD as the installation media.
-
Select No to bypass starting the network interface.
-
Select Skip to bypass selecting a rescue environment.
-
-
Select Start shell to obtain a
bash
shell promptat the bottom of the screen. -
If the existing root file system is configured as an LVM volume, use the following command to start the volume group, for example. If the volume group is
vg_host01
, type:sudo lvchange -ay vg_host01
-
Check the file system by using the fsck command appropriate to the new file system. If the later version is
ext3
, you would type the command as follows:sudo fsck.ext3 -f device
In the previous command, device is the root file system device,
/dev/sda2
.The command moves the
.journal
file to the journal inode. -
Create a mount point,
/mnt1
, and mount the converted root file system on it.sudo mkdir /mnt1 sudo mount -t ext3 device /mnt1
-
Edit the
/mnt1/etc/fstab
file to change the root file system type toext3
./dev/sda2 / ext3 defaults 1 1
-
Create the
.autorelabel
file in the root of the mounted file system.sudo touch /mnt1/.autorelabel
The presence of the
.autorelabel
file in/
instructs SELinux to re-create the security attributes of all the files on the file system.Caution:
If you don't create the
.autorelabel
file, booting the system might not succeed. In the file isn't created and the reboot fails, you can either disable SELinux temporarily by specifying theselinux=0
value in the kernel boot parameters; or, you can run SELinux in permissive mode by specifyingenforcing=0
. -
Unmount the converted root file system.
sudo umount /mnt1
-
Remove the installation media, then reboot the system.
Checking and Repairing an Ext File System
You use the fsck utility to check and repair file systems. For file
systems other than root
(/
) and /boot
,
mount invokes file system checking if more than a specified number of
mounts have occurred or more than 180 days have elapsed without checking having being
performed. You might want to run fsck manually if a file system hasn't
been checked for several months.
The following procedure describes how to check and repair an Ext file system.
Attention:
Running fsck on a mounted file system can corrupt the file system and cause data loss.
-
Unmount the file system:
sudo umount filesystem
-
Use the fsck command to check the file system:
sudo fsck [-y] file-system
In the previous example, file-system specifies a device name, a mount point, a a label, or UUID specifier, for example:
sudo fsck UUID=ad8113d7-b279-4da8-b6e4-cfba045f66ff
By default, the fsck command prompts you to choose whether it should apply a suggested repair to the file system. If you specify the -y option, the command assumes a yes response to all such questions.
For the ext3
, and ext4
file system types, other commands
that are used to perform file system maintenance include dumpe2fs and
debugfs. dumpe2fs prints super block and block group
information for the file system on a specified device. debugfs is an
interactive file system debugger that requires expert knowledge of the file system
architecture. Similar commands exist for most file system types and also require expert
knowledge.
For more information, see the fsck(8)
manual page.
Changing the Frequency of File System Checking for Ext File Systems
Note:
The following procedure applies to Ext file systems only. XFS file systems, which are the default file system type in Oracle Linux 8, detect errors automatically and don't require periodic file system checks at boot time.
To change the number of mounts before the system automatically checks the file system for consistency, use the following command syntax:
sudo tune2fs -c mount_count device
In the previous command, device specifies the block device that corresponds to the file system.
A mount_count of 0
or -1
disables automatic checking, based on
the number of mounts.
Tip:
Specifying a different mount_count value for each file system reduces the probability that the system checks all the file systems at the same time.
To specify the maximum interval between file system checks, use the following command syntax:
sudo tune2fs -i interval[unit] device
In the previous command, unit can be d for days, w for weeks, or m for months.
The default unit is d (for days). An interval of
0
disables checking, based on the time that has elapsed after the last
check. Even if the interval is exceeded, the file system isn't checked until it's next
mounted.
For more information, see the tune2fs(8)
manual page.