Converting an ext3 root partition to ext4 in Fedora 10
by
Rehan Khan
—
last modified
Jan 21, 2009 10:58 AM
—
filed under:
Post-Install Solutions
This how-to describes a method to migrate an ext3 partition to ext4. There are two variations, 1) with backward compatibility to ext3 or 2) without backward compatibility to ext3 and describes the pro/cons of each.
Applicable to Fedora Versions
- Fedora 10
Requirements
1. A standard install of Fedora 10 (/boot and / partitions are ext3).
2. A Fedora 10 Install DVD.
3. If you have data you want to keep then a fresh backup. The method is not usually data destructive but you never can tell.
Doing the Work
- Alter the /etc/fstab file to say thet the / partition
is ext4. This is a preparation step. Fedora will still mount the
partition as ext3 at this stage. This step is needed to save some
fiddling later. Using your favourite editor edit /etc/fstab and change
the ext3 to ext4 in the /dev/VolGroup00/LogVol00 line (This is the
default setting in the fstab. If you installed your / partition some
other way then change this accordingly). If you reboot now Fedora
should boot normally. the mount command will say the / drive is ext4
but this is false as for example system-config-lvm will correctly say
the / drive is ext3. For example after editing /etc/fstab will look
like this (changed line in bold):
- The next step is to re-make the initrd so that it includes the ext4 driver. If the drive is converted to ext4 before we do this then we might not be able to boot! To find out the current kernel version and re-make the initrd for the current kernel execute the following in a terminal:
- At this point the file system has been marked as ext4 in fstab and initrd has the ext4 driver and the new fstab. We can stop here if we want to maintain backwards compatibility with ext3. All that is required is a reboot. We do however get the benefits of the new ext4 filesystem driver e.g. delayed allocation improves performance and reduces fragmentation somewhat and multiblock allocation also improves performance amongst other things. These improvements are particularly noticeable on older hardware and slower disks (e.g. laptop disks). So if you want to be compatible with ext3 you are done! Use the following steps to continue to a fully converted ext4 filesystem. Note this will not be ext3 compatible at all.
- To
fully convert the file system to ext4 we need to boot from Fedora
Install CD/DVD. Select the Rescue Installed System option from the
CD/DVD's grub boot menu. Select your language and keyboard and say no
to starting the network interfaces (unless you have a need for network
access). At the "find linux installation" dialog select Read Only (i.e
try and mount Fedora read only). Ideally we should not mount the file
system but if we don't then we cannot easily see the partition we want
to convert. Restrict yourselves to only following this how-to from now
on and don't do any other unrelated maintenance tasks. Select OK at the
dialog that tells you where your hard disks file systems have been
mounted.
- You will be dropped to a shell. Use the mount
command to see which device name you need to use to convert your root
partition. On a default Fedora install look for the line that looks
like:
/dev/mapper/VolGroup00-LogVol00 on /mnt/sysimage type ext4 (ro,barrier=1,noextents,data=ordered)
This line effectively tells you that this volume wants to use the ext4 filesystem driver (ext4), is read only (ro), has barriers enabled (barriers=1), does not use extents (noextents) and that data is stored using the ordered method (data=ordered). Some of these will change when the filesystem is fully converted to ext4. Note that up to now we have
only asked linux to use the ext4 driver to read this device. The ext4 driver will see that no ext4 features are enabled on the filesystem and will treat it as ext3 maintaining compatibility. - With this information we can execute the command that will
actually convert the ext3 on-disk format to the ext4 on-disk format enabling the default ext4 features usually used by Fedora (as defined in /etc/mke2fs.conf). Note we will be using
the tune2fs binary that we yum updated earlier:
/mnt/sysimage/sbin/tune2fs -I 256 -O has_journal,extents,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize /dev/mapper/Volgroup00-LogVol00
- If the above command does not tell you to run fsck and reboot
then it has failed and not been applied. You will have to remove the
option that tune2fs reports. E.g it is likely to fail by saying that
inodes are already 256 so remove the -I 256 section and so on. Sorry
but I can't find a better way to do this (easily) and it ensures all
the default F10 options have been applied.
- With this done
we now need to 'fix' the volume with these new settings. To do this we
will fsck the volume. Answer Y to the question that follows this
command. (Some errors might be displayed).
fsck -pf /dev/mapper/Volgroup00-LogVol00
- That should be all that needs to be done. Reboot by issuing the reboot command.
#
# /etc/fstab
# Created by anaconda on Wed Jan 7 17:04:17 2009
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or vol_id(8) for more info
#
/dev/VolGroup00/LogVol00 / ext4 defaults 1 1
UUID=5548e17b-7d19-4056-8fef-44230b52f8ae /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
su
yum upgrade mkinitrd e2fsprogs <-- make sure we have the latest versions of some tools
mv /boot/initrd-`uname -r`.img /boot/initrd-`uname -r`.img.old
mkinitrd -v --with=ext4 /boot/initrd-`uname -r`.img `uname -r`
Troubleshooting
How to test
- If the following command produces output starting with Filesystem Features then ext4 has been enabled.
tune2fs -l /dev/VolGroup00/LogVol00 | grep extent
example output:
[root@localhost ~]# tune2fs -l /dev/VolGroup00/LogVol00 | grep extent
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
More Information
1) Note that this conversion method doesn't 'convert' files that were previously on the ext3 partition. Only newly created files will use the ext4 on disk format. Until the ext4 defragmentation feature is available this will remain the case. The ext4 defragmentation tool will be able to 'convert' the ext3 format files to ext4 format. For practical purposes this should not concern you overly.
2) You may see the following notice during boot :
jbd: barrier-based sync failed on dm-0Barriers is a feature of certain filesystems which increase the integrity of the data on the disk. Ext4 supports this as a default setting. At present the barrier feature does not work with devicemapper device. Redhat/Fedora, by default, uses Logical Volume Management to create flexible partitions/filesystems and LVM uses device mapper. thus the feature will be disabled by the kernel during boot and the message displayed. See this kernel bug for more information.
3) You may want to add ext4 to the top of the /etc/filesystems file for completeness. This will have no practical consequense as we are already loading ext4 in the initrd and this information will be handled by the kernel.
Disclaimer
We test this stuff on our own machines, really we do. But you may run into problems, if you do, come to #fedora on irc.freenode.net

