FedoraForum.org - Fedora Support Forums and Community
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Jan 2009
    Posts
    7

    How do I defrag ext4?

    fsck reports 18905 non-contiguous files (20.9%) and 40 non-contiguous directories (0.0%) on an ext4 file system so I would really like to defragment it. Is there any way?

  2. #2
    Join Date
    Aug 2005
    Location
    Ask the Government.
    Posts
    458
    Make really, really, really sure that the file system is not mounted. usually boot from install disk. Then run this command:

    Code:
    fsck.ext4 -P /dev/sdXX
    X= Your partition info


    Of course for further info just type this:

    Code:
    man fsck.ext4
    Fedora20 AMD X6 1090T - 8GIG RAM - Nvidia GTX-650 - LXDE. Linux since 1995 - No Gnomes allowed.
    Mythbuntu - Mythtv .27 - AMD 6core- 8 gigs ram Nvidia GTX-650 Ceton 4 port tunner
    Mint 17 64bit - Dual Core AMD 5200 2gig ram -GT 9400
    Galaxy Blaze 4G ICS ClockworkMOD :)

  3. #3
    Join Date
    Jan 2009
    Posts
    7
    Quote Originally Posted by coffee412
    Make really, really, really sure that the file system is not mounted. usually boot from install disk. Then run this command:

    Code:
    fsck.ext4 -P /dev/sdXX
    X= Your partition info


    Of course for further info just type this:

    Code:
    man fsck.ext4
    Didn't do anything

  4. #4
    Join Date
    Jan 2005
    Posts
    5,059
    He wants to defrag the files and dir's.

    I think the issue is very mute and he would need to know what file are involved.
    #e2freefrag /dev/mapper/VolGroup-LogVol will show he extent sizes with numbers
    #frrefrag /home/useryou/Documents/* shows fragmetaion of files; drill down as needed
    man pages available,

    #e2defrag or online defrag or background defrag is not installed.
    There may be one that works, it may need kernel patches and compiled, and it may contain bugs.
    But officially, there is no ext4 defrag yet.

    SJ
    Do the Math

  5. #5
    Join Date
    Aug 2009
    Posts
    790

    :) waterfoul, review the e2freefrag instructions by SlowJet. :)

    waterfoul, disregard my above post, review the e2freefrag instructions by SlowJet.

    man 8 e2freefrag

    I misunderstood about wanting to do a fsck, deleting my post now.
    Last edited by diamond_ramsey; 28th October 2009 at 08:20 AM.
    2 dual cores, 11 GB RAM, F18 Spherical Cow - 3.11.10-100.fc18.x86_64 / i686
    2 dual cores, 11 GB RAM, F19 Schrödinger's Cat - 3.14.25-100.fc19.x86_64 / i686
    2 dual cores, 11 GB RAM, F20 Heisenbug - 3.17.4-200.fc20.x86_64 / i686
    2 dual cores, 11 GB RAM, F21 - 3.17.4-300.fc21.x86_64 / i686
    80 x86_64 computing cores, 144 GB RAM & 8 SATA Seagate 7200.12 500 GB harddisks

  6. #6
    Join Date
    Sep 2007
    Location
    in your heart
    Posts
    238

    Re: How do I defrag ext4?

    i use this command in root prompt , but its say unable to umount the disk error

    i wanna defrag to root filesystem drive
    ASUS M3N78-EM, AMD Phenom™ X4 Quad-Core 9650+, 6GB DDR2 RAM, 160GB x 2 RAID0 HDD, Nvidia Geforce8300 Hybrid SLI
    Run @ Fedora12 x86_64,& Windows7 Ultimate x64

    [SIGPIC][/SIGPIC]

    (Akmods-nvidia @ rpmfusion)


    R.Mathan MCA, MCITP, MCTS

  7. #7
    stevea Guest

    Re: How do I defrag ext4?

    To manually defrag or fsck root you want to boot a live CD or similar and manipulate the umounted filesystem.

  8. #8
    Join Date
    Oct 2007
    Location
    Freedonia
    Age
    68
    Posts
    3,042

    Re: How do I defrag ext4?

    Of course you can't unmount the root filesystem when it's in use. Boot from a LiveCD and try it that way.

    You're actually better off backing up your drive, reformatting and restoring. Linux normally spreads files out all over the drive, both to avoid fragmenting and to lower the average seek time. Defragging packs them all at one end, the way Windows stores them. Not only do they get fragmented faster, the average seek time goes up. Backing up, nuking and restoring keeps them spread out, the way they're supposed to be. HTH, HAND.
    Registered Linux user #470359 and permanently recovered BOFH.

    Any advice in this post is worth exactly what you paid for it.

  9. #9
    Join Date
    Nov 2004
    Posts
    2

    Re: How do I defrag ext4?

    If you want to defrag/check the root file system do this:

    1. touch /forcefsck
    2. reboot

    The file forcefsck will cause a file system check at boot time.

    Jim

  10. #10
    Join Date
    Aug 2009
    Posts
    8,472

    Re: How do I defrag ext4?

    actually, with ext4, you can defrag while online (mounted)

    just use the e4defrag program (included in the e2fsprogs package.)

    just run:

    e4defrag /dev/sdXx (where sdXx is the partition of the filesystem you wish to defrag, like sda4)

    The forcefsck at boot will check the filesystem, but won't defrag it.

    Edit:

    Forgot to mention that you have to run e4defrag with the -test parameter for now, since it isn't a fully tested version. it requires the -test parameter, I guess just to make certain that you realize it's still a test version.
    Last edited by DBelton; 27th December 2011 at 06:19 PM.

  11. #11
    Join Date
    Jul 2006
    Posts
    28

    Re: How do I defrag ext4?

    Something to consider: the disk someone wants to defrag may be virtualized. My goal is to minimize the rolled up size of an entire virtual machine. I could zero out all the unused file space, but then the unrolled machine will take up all the space of the virtual disks with real zeros. So, yes, I really do want to move all the data to one end of the virtual disk. Then I can shut the virtual machine down and run a virtual machine host tool to delete the unused file system pages. viola' my machine image is smaller. I do wish my e2fsprogs actually did have the e4defrag thingy......

  12. #12
    Join Date
    Oct 2007
    Location
    Freedonia
    Age
    68
    Posts
    3,042

    Re: How do I defrag ext4?

    Yes, that will work, right up to the moment when you need to write something to that partition, such as a new kernel, and you find out that there's no room because you've very cleverly removed all of the free space. Some things really are better left alone.
    Registered Linux user #470359 and permanently recovered BOFH.

    Any advice in this post is worth exactly what you paid for it.

  13. #13
    Join Date
    Jul 2006
    Posts
    28

    Re: How do I defrag ext4?

    Compacting the files has no effect on that. These are unroll-often, ugrade-rarely VM's. So trans-global distribution time is actually an issue. OS upgrades causing fragmentation, not so much. I also realized you thought I would resize the partition. Nope. Just compact the data so it both uses less host disk space and compresses better.

  14. #14
    Join Date
    Dec 2006
    Posts
    2,088

    Re: How do I defrag ext4?

    Can't you just copy the files to a new virtual drive?

  15. #15
    Join Date
    Jul 2006
    Posts
    28

    Re: How do I defrag ext4?

    Quote Originally Posted by george_toolan
    Can't you just copy the files to a new virtual drive?
    Yes, indeed, that works. If there were an e4defrag-er out there, it would be easier. I've found references to such a beast, but no working links to it. Creating a new bootable disk with a swap and an fs partition is a nuisance, so, I thought I'd ask. Thank you.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. How to defrag
    By Angela in forum Using Fedora
    Replies: 11
    Last Post: 11th November 2004, 09:38 AM
  2. defrag
    By butters in forum Using Fedora
    Replies: 12
    Last Post: 14th September 2004, 08:44 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •