Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have two ext3 filesystems that are very old and have been 99% full for a long time, leading to fragmentation. Also, they've been used for running VMs with dynamic disk images and other fragmentation-causing workloads.

I recently converted the filesystems to ext4 using the instructions here, specifically by running:

# tune2fs -O extents,uninit_bg,dir_index /dev/DEV
# e2fsck -fDC0 /dev/DEV

However, the filesystems still don't support e4defrag:

Failed to defrag with EXT4_IOC_MOVE_EXT ioctl:Operation not supported   [ NG ]

I'm guessing the tune2fs command lacks some option, but googling didn't help me figure out what that might be.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

I had the same problem. I found this which had the answer:

https://wiki.archlinux.org/index.php/Ext4#Migrating_files_to_extents

Migrating files to extents

Warning: Do NOT use the following method with Mercurial repository that have been cloned locally, as doing so will corrupt the repository. It might also corrupt other hard link in the filesystem.

Even though the filesystem is now converted to ext4, all files that have been written before the conversion do not yet take advantage of the new extents of ext4, which will improve large file performance and reduce fragmentation and filesystem check time. In order to fully take advantage of ext4, all files would have to be rewritten on disk. A utility called e4defrag is being developed and will take care of this task; however, it is not yet ready for production.

Fortunately, it is possible to use the chattr program, which will cause the kernel to rewrite the file using extents. It is possible to run this command on all files and directories of one partition (e.g. if /home is on a dedicated partition): (Must be run as root)

find /home -xdev -type f -print0 | xargs -0 chattr +e
find /home -xdev -type d -print0 | xargs -0 chattr +e

It is recommended to test this command on a small number of files first, and check if everything is going all right. It may also be useful to check the filesystem after conversion.

Using the lsattr command, it is possible to check that files are now using extents. The letter 'e' should appear in the attribute list of the listed files.

--

Note: I had assumed e4defrag could convert the files to use extents. The failed ioctl is the one that does that afaik, so I am a little confused as to why it doesn't work, but chattr +e did work for me. After you have chattr +e the files, you can then use e4defrag on them. Obviously make sure you have a backup etc just in case (I would have thought this is safe, but you never know - there is a warning here about hardlinks but I find no other reference to known issues with hardlinks).

share|improve this answer
    
Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  Oyibo Dec 2 '12 at 12:56
2  
I have improved the answer as requested. –  Jools Dec 2 '12 at 13:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.