Know you should upgrade your Linux filesystem but can’t face the aggravation? Here’s how to convert ext2 and ext3 to ext4 without the upheaval of a complete re-install.
If you were polite, you’d call the ext3 file system venerable, launching as it did way back in 2001. As for poor old ext2, that filesystem hails from 1993, and there’s no word for it other than ancient. In computer terms, ext3 is an antique. And ext2 is an archaeological find.
The modern filesystem in the Linux world is ext4 which was released in 2008. It is faster, less prone to fragmentation, capable of handling larger filesystems—and larger files—it has more accurate file date stamps and did we mention it’s faster? A lot faster.
OK, I’m Sold—Let’s Do This
Let’s think this through. Actually, you probably don’t want to upgrade your filesystem.
It makes more sense to upgrade your entire Linux system instead. By upgrade we mean take a couple of data backups, wipe your system, re-install a modern distribution, and restore your data. Go for the complete refresh. Get the benefits of a modern Linux distribution with updated software, as well as a clean, current, and newly installed filesystem.
If you cannot run a modern Linux on your hardware, even one of the lightweight distributions like Lubuntu, LinuxLite or CrunchBang++, and you absolutely have to stick with the Linux you’ve got, there are still caveats.
To upgrade your filesystem to ext4, you have to be using kernel version 2.6.28 or later. So if you don’t have that version of the kernel or a later version, you must upgrade your kernel first.
Warning: Don’t even think about trying this without satisfying that kernel version requirement. You’ll end up with an unbootable computer. Check which kernel version you’re using before continuing.
Make sure you have an install disk for the version of Linux you’re currently using and keep it on stand by. Upgrading your filesystem is not without dangers.
Backups are your safety net. Before you do anything, make a couple of data backups to different backup media, and make sure you have that old Linux install disk handy. If something goes badly wrong, you can then re-install your old Linux and restore your data.
You’re also going to need a current Live CD/DVD of a modern Linux distribution to perform the filesystem upgrade with. So make sure you have one of those to hand too.
Incidentally, this article was researched using an install of Ubuntu Jaunty Jackalope, which was released in April of 2009. It used ext3 as the file system.
Still With Us?
John Wayne said courage was being terrified but still saddling up anyway. I admire your guts.
The first thing we’re going to do is check the kernel version with
uname command can display different types of system information.
On your old Linux computer open a terminal window and type the following command. Type
uname , a space,
-r, then hit Enter.
The version of Linux on this computer is using kernel version 2.6.28-11, so we’ve met the kernel version requirement.
Seriously, If you haven’t met this requirement, stop now. Close enough just isn’t enough. You must meet or exceed this kernel version number.
Now we’ll check the disk identifiers with
blkid, which identifies the block devices on the system.
This system has a single hard drive (sda) which has a file system on it (sda1) which is mounted at /dev/sda1. This is an ext3 filesystem. This is the filesystem we are going to convert.
There is also a filesystem called swap, but that doesn’t interest us.
Reboot with the Live CD
Insert the Live CD and reboot your computer. You may need to press a key during the reboot to make the computer boot from the CD. The key to press will be displayed during the early stages of the boot-up process. Be quick – the window of opportunity doesn’t last long. If you miss it, reboot and try again.
When you have booted into the Live CD environment, make sure you don’t accidentally start an installation. Take time to read the options you are provided with, and if there is one that says something similar to “Try DistributionName,” select that option.
Open a terminal window and type the following command. This effectively makes you root and means you don’t need to type
sudo in front of every command.
Note that the command prompt has changed. You are root. Tread carefully.
Identify the Filesystems
We need to identify the filesystems once more to see how they show up in this instance of Linux.
You’ll see some output similar to the following.
The filesystem we previously identified as sda1 has been found and recognized by the Live CD Linux. That’s the first mini-milestone.
The second is converting the filesystem.
Converting the Filesystem
There are two commands listed here, one for converting from ext2 to ext4 and one for converting from ext3 to ext4. Make sure you use the right one for you!
To convert from ext2 to ext4 use this:
tune2fs -O extents,uninit_bg,dir_index,has_journal /dev/sda1
To convert from ext3 to ext4 use this:
tune2fs -O extents,uninit_bg,dir_index /dev/sda1
It’s slightly underwhelming as not a lot appears to happen. You are returned to the command prompt. If you do see some output, it is probably going to be error messages. So no news is good news here.
Check the Filesystem
Even though no errors were flagged, let’s be thorough and check the whole filesystem for problems. We will use a command called
e2fsck. This is a tool used to check the integrity of filesystems. It can also attempt to repair any issues it finds. The
e2fsck tool works with ext2, ext3, and also ext4 filesystems.
-p (preen) option causes e2fsck to attempt to repair errors and the
-f (force) option causes
e2fsck to check the filesystem even if the filesystem seems clean.
e2fsck -pf /dev/sda1
No errors were reported. We can now try to mount the filesystem.
Mounting the FIlesystem
We need to adjust the file system table (fstab) and the grub bootloader to work with the converted filesystem. To do this, we must mount the filesystem. We shall mount it on /mnt. We identified the filesystem as sda1 earlier, so our command is:
mount -t ext4 /dev/sda1 /mnt
Now that it is mounted we should be able to list the filesystem. Let’s check that. The root of the filesystem is going to be at the mount point, /mnt.
That’s encouraging. It looks like we’d expect it to.
We need to edit the fstab file and change any references of ext3 (or ext2, if that’s the file system you’ve converted from) to ext4.
The Live CD used in this example has the
nano editor on it. It’s a simple little editor, so we’ll use that. If
nano is not available on your Live CD there will be another editor that will have been bundled by the Linux distribution on the CD.
nano editor window will appear. You need to look for occurrences of the string “ext3” or “ext2” and change them to “ext4”. In this example, there was one occurrence of ext3, which is highlighted.
The ext3 was replaced by ext4.
You need to save the file and exit from the editor. In
nano Ctrl+O will save the file, and Ctrl+X will close the editor.
Because we have mounted the sda1 filesystem on /mnt, the pathways to the directories in the filesystem have effectively all been moved one level deeper than usual. That’s why the path we provided to nano was /mnt/etc/fstab instead of the usual /etc/fstab.
Because grub expects to find things in certain places, we need to make the filesystem appear as though it were mounted normally. We need the root of the filesystem to be at / and not at /mnt. The chroot command allows us to run a command shell and to specify the root point we wish to use.
The command we use is:
Note that the command prompt has changed.
We can now issue the
update-grub command to have grub read the fstab file and reconfigure itself.
Once grub has reconfigured itself, we need to install a new instance of grub on the hard drive. Note this is the hard drive sda, not the filesystem sda1. Don’t include the “1”, just type “sda”.
Rebooting Your Linux
Reboot your system and remove the Live CD. When your system has rebooted, open a terminal window, and enter the following command:
As we can see, the filesystem is now an ext4 filesystem.
The machine that this article was researched on took so long to reboot (over ten minutes) it was assumed something had gone wrong and that it would never come back up.
Perhaps it was because it was a virtual machine, or perhaps some of the filesystem conversion takes place during that first boot up. Either way, patience won out, and it eventually did resurface. If your machine does something similar, wait it out. All might not be lost.
Subsequent reboots were as quick as normal.
Upgrade Your Linux Instead
Well, we got there. But you’re still left with a non-standard hybrid using an old Linux release on a modern filesystem.
If moving to a new filesystem is important to you, and your hardware can take it, moving to a current Linux distribution is the best route to take. You will enjoy all of the other security and software advantages that come from doing so.
Still, if there’s nothing else for it—and sometimes we don’t have the options we wish we did—these steps will allow you to upgrade your filesystem.
- › How to Use the chroot Command on Linux
- › Should You Turn Up the Transmit Power on Your Wi-Fi Router?
- › Don’t Buy a Wi-Fi Extender: Buy This Instead
- › Which Smartphone Accessories Are Worth Buying?
- › 10 New Windows 11 Features You Should Be Using
- › 10 YouTube Features You Should Be Using
- › Can a Magnet Really Damage My Phone or Computer?