ok

12/12/10

Convert EXT2 or EXT3 to EXT4 Without Reformatting Your Hard Drive

Convert EXT2 or EXT3 to EXT4 Without Reformatting Your Hard Drive
   If you've been running Linux for a while, you're probably using the now slightly-outdated EXT2 or EXT3 file system. Technology blog Ghacks has a guide to converting those formats to the newer, faster, EXT4 without doing a clean install.
While many of us prefer to do a reformat every year or two, if you don't feel like reorganizing all your data but would like the speed and stability of EXT4, you can convert your file system without losing your data. That said, you'll of course want to back everything up before doing this—just because you shouldn't lose your data doesn't mean something can't go wrong. It's fairly simple if you're comfortable with the Terminal, which, if you've been a Linux user that long, is pretty likely.
   And then Let’s say you’re a little bit behind the times. You’ve wanted to do some upgrading of your Linux machines but you’ve just not really had the time. Or let’s say you did do some upgrading of your Linux system but you didn’t make any changes to your file system and you’re still running a machine with either ext2 or ext3. Now that’s not necessarily a bad thing as both file systems work and work well. But let’s say you do want to take advantage of some of the features of ext4.
In this article I am going to show you how to migrate your ext2 or ext3 partition to ext4. I will use a Ubuntu machine as an example. I want to warn you that you could lose data by doing this so, following good administrative practices, back up your data! Once you are certain you have that backup of your data, it’s time to begin.
Kernel pre-requisite
You must be certain you have a kernel that is at least 2.6.28-11-generic or higher. If not, do NOT continue on with this. To find out what kernel you are running issue the command uname -r. If your kernel is lower thatn 2.6.28-11 stop where you are and close your browser.
Step 1
The first step is to boot from a Ubuntu Live CD. You do this because you can’t convert a file system that has been mounted. If you are converting a second drive on your machine (one that doesn’t contain your OS or your ~/ (home) directory, you can always just unmount that drive and do this without booting the Live CD.
Step 2:
Now it’s time to convert. We’re going to use /dev/sda1 as an example for converting. You will want to know the exact name of the drive and/or partition you are wanting to covert. If you are converting from ext2 to ext4 issue the following commands:
sudo bash
tune2fs -O extents,uninit_bg,dir_index,has_journal /dev/sda1

If you are wanting to convert ext3 to ext4 issue the following commands:
sudo bash
tune2fs -O extents,uninit_bg,dir_index /dev/sda1

NOTE: After you enter either of the sudo bash commands you will have to enter your sudo password.
Step 3:
Regardless of which conversion you are doing you will want to check the drive (or partition) after the conversion and repair any issues. Do this with the command:
e2fsck -pf /dev/sda1
Step 4:
Now you need to make sure the partition will mount. Do this with the command:
sudo mount -t ext4 /dev/sda1 /mnt
Hopefully you won’t see any errors. You should now see the contents of that drive listed in the /mnt directory.
Step 5:
It’s time to edit your /etc/fstab file to reflect the change. Open this file up with your favorite text editor and look for the line that corresponds to the drive/partition you just changed. In that line you will reference to either ext2 or ext3. Change that reference to ext4. Save and close that file.
Step 6:
Now you need to refresh grub. Depending upon how your boot partition is will determine how you do this. If your boot partition is SEPARATE, do the following:
sudo bash
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot
grub-install /dev/sda --root-directory=/mnt --recheck

If your boot partition is NOT separate, do the following:
sudo bash
mount /dev/sda1 /mnt
grub-install /dev/sda --root-directory=/mnt --recheck

Step 7:
Reboot. Once up and running you will now be using the ext4 file system!
Final thoughts
If you are leery of any of the above, don’t worry…you don’t HAVE to do this. Your system will run fine with ext2 or ex3. But if you love to get your hands dirty with your machines…then you will enjoy converting a working file system from one type to another. Just remember BACK UP YOUR DATA!

0 comments: