Defragmenting on Linux

Every day solutions to every day challenges. + Brilliant stuff

Moderators: b1o, jkerr82508

Forum rules
Please feel free to post your tip it does not have to be advanced. Also ask questions directly related to the tip here. But do not start new threads with questions or ask for help here. That is what the help section is for. forum rules: http://bjoernvold.com/forum/viewtopic.php?f=8&t=568
User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Defragmenting on Linux

Postby viking60 » 30 Nov 2015, 18:53

Yes I know: You don't have to defrag Linux. Mostly mechanisms are built in to take care of it so it will never be absolutely necessary. That does not mean that Linux does not get slightly fragmented though.
It is possible to defrag Linux with Exr2 Ext3 and Ext4 systems though.
To check your filesystems you can do a:

Code: Select all

df -T


Just boot from the Viking Rescue system and start Systemrescuecd.
Check your Partitions:

Code: Select all

fdisk -l

And make a mount-point

Code: Select all

mkdir /mnt/sda1

(My Linux partition was /dev/sda1)
Mount it:

Code: Select all

mount /dev/sda1 /mnt/sda1

Start this command to defrag all your directories:

Code: Select all

e4defrag /mnt/sda1 /


Don't use this on SSD only on HDD.

You may not have to unmount the partition for this so you could try it directly in your terminal.

Code: Select all

e4defrag /home/viking


To repair filesystems you need to unmount the partition so our Rescue System comes in handy.
Fire up Systemrescuecd and do a

Code: Select all

fdisk -l
If the answer is /dev/sda1 then you can check your fragmentation with:

Code: Select all

e2fsck -fn /dev/sda1

It will probably be clean and come up with no fragmentation.

But if this reports fragmentation you can repair it with:

Code: Select all

e2fsck -p /dev/sda1

After that your read write process might be faster.

Again: this works for Ext2 3 and 4 and should not be used on anything other than traditional HDD's - never on SSD.

This is for fine tuning pros - you never actually need to do this I was just bored: so I though I'd write down a tip :-D
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Defragmenting on Linux

Postby viking60 » 30 Nov 2015, 18:55

Btrfs distros like Opensuse do have built in defrag options too:
:A
viewtopic.php?f=3&t=3619&p=19931
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
dedanna1029
Sound-Berserk
Posts: 8780
Joined: 14 Mar 2010, 20:29
Contact:

Re: Defragmenting on Linux

Postby dedanna1029 » 01 Dec 2015, 01:22

Good job.

I will have to find an old link that I had at one time a few years back on defragmenting a reiserfs system (of which I'm still on, it's my "trusty"). I had thought about trying it out so many times then never did lol. It may be next on the agenda, well, after a few other things. :lol:
I'd rather be a free person who fears terrorists, than be a "safe" person who fears the government.
No gods, no masters.
"A druid is by nature anarchistic, that is, submits to no one."
http://uk.druidcollege.org/faqs.html

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Defragmenting on Linux

Postby viking60 » 01 Dec 2015, 13:35

This can be handy when your partition is getting full - like in my case - because there is less space to move things around.
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
dedanna1029
Sound-Berserk
Posts: 8780
Joined: 14 Mar 2010, 20:29
Contact:

Re: Defragmenting on Linux

Postby dedanna1029 » 02 Dec 2015, 16:29

Indeed. I'm also interested in finding out about doing a defrag on Windows from Linux. You know Linux would do it better. ;)
I'd rather be a free person who fears terrorists, than be a "safe" person who fears the government.
No gods, no masters.
"A druid is by nature anarchistic, that is, submits to no one."
http://uk.druidcollege.org/faqs.html


Return to “Tips & Tricks”