4 Managing the Ext File System
WARNING:
Oracle Linux 7 is now in Extended Support. See Oracle Linux Extended Support and Oracle Open Source Support Policies for more information.
Migrate applications and data to Oracle Linux 8 or Oracle Linux 9 as soon as possible.
This chapter describes tasks for administering the Ext file system in Oracle Linux.
Converting an Ext2, Ext3, or Ext4 File System to a Btrfs File System
You can use the btrfs-convert utility to convert an
ext2
, ext3
, or ext4
file
system to btrfs
. The utility preserves an image of the original file
system in a snapshot named ext2_saved
. This snapshot allows you to
roll back the conversion, even if you have made changes to the btrfs file system.
Note:
You cannot convert the root file system or a bootable partition, such as
/boot
, to btrfs.
How to Converti a Non-root File System
Caution:
Before performing a file system conversion, make a backup of the file system from which you can restore its state.
ext2
, ext3
, or
ext4
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
, for example:/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 Ext2 File System to Ext3
Caution:
Before performing a file system conversion, make a backup of the file system from which you can restore its state.
To convert a non-root ext2 file system to ext3:
-
Unmount the ext2 file system:
sudo umount filesystem
-
Use fsck.ext2 to check the file system.
bash-4.1# fsck.ext2 -f device
-
Use the following command with the block device corresponding to the ext2 file system:
sudo tune2fs -j device
The command adds an ext3 journal inode to the file system.
-
Use fsck.ext3 to check the file system.
bash-4.1# fsck.ext3 -f device
-
Correct any entry for the file system in
/etc/fstab
so that its type is defined asext3
instead ofext2
. -
You can now remount the file system whenever convenient:
sudo mount filesystem
For more information, see the tune2fs(8)
manual page.
Converting a root Ext2 File System to Ext3
Caution:
Before performing a root file system conversion, make a full system backup from which you can restore its state.
To convert a root ext2 file system to ext3:
-
Use the following command with the block device corresponding to the root file system:
sudo tune2fs -j device
The command adds an ext3 journal to the file system as the file
/.journal
. -
Run the mount command to determine the device that is currently mounted as the root file system.
In the following example, 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 https://edelivery.oracle.com/linux.
-
From the installation menu, select Rescue Installed System. When prompted, choose a language and keyboard, select Local CD/DVD as the installation media, select No to bypass starting the network interface, and select Skip to bypass selecting a rescue environment.
-
Select Start shell to obtain a
bash
shell prompt (bash-4.1#
) at 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,
vg_host01
):bash-4.1# lvchange -ay vg_host01
-
Use fsck.ext3 to check the file system.
bash-4.1# fsck.ext3 -f device
In the previous example, device is the
root
file system device (for example,/dev/sda2
).The command moves the
.journal
file to the journal inode. -
Create a mount point (
/mnt1
) and mount the convertedroot
file system on that mount point, for example:bash-4.1# mkdir /mnt1 bash-4.1# mount -t ext3 device /mnt1
-
Using a text editor, edit the
/mnt1/etc/fstab
file and change the file system type of theroot
file system toext3
, for example:/dev/sda2 / ext3 defaults 1 1
-
Create the file
.autorelabel
in theroot
of the mounted file system.bash-4.1# touch /mnt1/.autorelabel
The presence of the
.autorelabel
file in/
instructs SELinux to recreate the security attributes of all files on the file system.Note:
If you do not create the
.autorelabel
file, you might not be able to boot the system successfully. If you forget to create the file and the reboot fails, either disable SELinux temporarily by specifyingselinux=0
to the kernel boot parameters, or run SELinux in permissive mode by specifyingenforcing=0
. -
Unmount the converted root file system.
bash-4.1# umount /mnt1
-
Remove the boot CD, DVD, or ISO, and reboot the system.
For more information, see the tune2fs(8)
manual page.