Fedora Linux Support Community & Resources Center
  #1  
Old 27th October 2009, 10:45 PM
waterfoul Offline
Registered User
 
Join Date: Jan 2009
Posts: 7
linuxfedorafirefox
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?
Reply With Quote
  #2  
Old 28th October 2009, 02:15 AM
coffee412 Offline
Registered User
 
Join Date: Aug 2005
Location: Ask the Government.
Posts: 458
linuxfedorafirefox
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 :)
Reply With Quote
  #3  
Old 28th October 2009, 07:01 AM
waterfoul Offline
Registered User
 
Join Date: Jan 2009
Posts: 7
linuxfedorafirefox
Quote:
Originally Posted by coffee412 View Post
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
Reply With Quote
  #4  
Old 28th October 2009, 08:04 AM
SlowJet Offline
Registered User
 
Join Date: Jan 2005
Posts: 5,059
linuxfedorafirefox
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
Reply With Quote
  #5  
Old 28th October 2009, 08:16 AM
diamond_ramsey Offline
Registered User
 
Join Date: Aug 2009
Posts: 790
linuxfedorafirefox
:) 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.
__________________
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

Last edited by diamond_ramsey; 28th October 2009 at 08:20 AM.
Reply With Quote
  #6  
Old 18th August 2010, 07:06 AM
mathan Offline
Registered User
 
Join Date: Sep 2007
Location: in your heart
Posts: 238
windows_7opera
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
Reply With Quote
  #7  
Old 18th August 2010, 07:57 AM
stevea
Guest
 
Posts: n/a
linuxfedorafirefox
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.
Reply With Quote
  #8  
Old 18th August 2010, 07:58 AM
sidebrnz Offline
Registered User
 
Join Date: Oct 2007
Location: Freedonia
Age: 67
Posts: 3,005
linuxfedorafirefox
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.
Reply With Quote
  #9  
Old 27th December 2011, 05:40 PM
kc9aop Offline
Registered User
 
Join Date: Nov 2004
Posts: 2
windows_7chrome
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
Reply With Quote
  #10  
Old 27th December 2011, 05:53 PM
DBelton Offline
Administrator
 
Join Date: Aug 2009
Posts: 8,453
linuxfirefox
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.
Reply With Quote
  #11  
Old 5th May 2012, 12:17 AM
bkorb Offline
Registered User
 
Join Date: Jul 2006
Posts: 28
linuxfirefox
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......
Reply With Quote
  #12  
Old 5th May 2012, 12:37 AM
sidebrnz Offline
Registered User
 
Join Date: Oct 2007
Location: Freedonia
Age: 67
Posts: 3,005
linuxfirefox
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.
Reply With Quote
  #13  
Old 5th May 2012, 12:45 AM
bkorb Offline
Registered User
 
Join Date: Jul 2006
Posts: 28
linuxchrome
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.
Reply With Quote
  #14  
Old 5th May 2012, 11:23 AM
george_toolan Offline
Registered User
 
Join Date: Dec 2006
Posts: 2,088
linuxfirefox
Re: How do I defrag ext4?

Can't you just copy the files to a new virtual drive?
Reply With Quote
  #15  
Old 5th May 2012, 04:37 PM
bkorb Offline
Registered User
 
Join Date: Jul 2006
Posts: 28
linuxchrome
Re: How do I defrag ext4?

Quote:
Originally Posted by george_toolan View Post
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.
Reply With Quote
Reply

Tags
defrag, ext4

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to defrag Angela Using Fedora 11 11th November 2004 09:38 AM
defrag butters Using Fedora 12 14th September 2004 08:44 AM


Current GMT-time: 16:54 (Saturday, 19-08-2017)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat