Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have put a very generic title to my question because i have a number of questions related to it I hope that would be fine.
So the idea is that I would like to check the fragmentation on my Linux server witch is in production mode (CentOs), So after googling for a while I ended up thinking that the best/easiest way to run fsck would be by restarting the machine with fsck on :
Code:
shutdown -Fr now
Since the server is in production mode I couldn't take the risk.
So I tried the same command above but on a test server (Ubuntu), the server was restarted correctly .
My questions :
I read in many posts that fragmentation is not a problem on linux based systems , But i still would like to see that information anyhow (I mean i would like to see how fragmented my server is)does this make sens ?
After I run the command
Code:
shutdown -Fr now
On Ubuntu , I wanted to check the status, So i was hoping for something like 'This was fixed ....that was fixed ....' is this possible ? How can I do it ?
After I run the command
Code:
shutdown -Fr now
On Ubuntu , I tried to validate that fsck was run and i figured out (from google) that it could be checked by executing the following command :
which returned:
Last checked: Fri Aug 21 18:56:37 2015 (I run the check today)
Does this mean that It was not run ? why ?
I would like to know from you guys if you have tried this before , is it totally a safe operation to do , whats the best practice in this case ? Do i have to have a failover server in case something goes wrong ?
Does it make any difference to execute this command on Ubuntu or Centos ?
Code:
shutdown -Fr now
If we say i run the command above, how can i after the restart check that a defragmentation was run and correctly
Last question, when I restarted the test machine the down time was minutes does it depend on the machine ? i mean should i expect it to take more time on a different machine ?
Finally, I hope that there are some hero's on the other side to enlighten my understanding.
By no means am I an expert on file systems, but you may wish to install and try out S.M.A.R.T. tools. There's one which scans your drive and gives information about the integrity of it from a hardware perspective. Recent hard drives contain SMART technology which allows these programs to interact with the drive and understand the points of problems, or not. I also believe in "defense in depth". Things like a NAS array storage device for data and some form of reliable, recall-able backup of system and user information.
Linux doesn't need a fragmentation tool, really. Unlike Windows, which writes files across sectors all over the disk, Linux writes the files in contiguous space, with some room to grow. When the disk gets to 85 or 90 full, some fragmentation may occur, but it still handles it more intelligently than Windows.
When you reboot a linux machine, there is a script that runs and looks for a file called "forcefsck" in the root of the file system. If it exists, it does an fsck before the disk is mounted.
You rarely need to shutdown to achieve a result in Linux - not unknown, but unlikely. There is always another way to do it as the perl folks remind us.
First things first - read my sigline.
"fsck" is different for each fileystem, even between ext3 and ext4. Generally it is best to allow the "system" to decide when/if it needs to run. For ext[234] the mount count is now ignored, and fsck will run automagically if needed at mount time (i.e. the decision is made every boot).
"shutdown" parameters (particularly -F) are handled differently by different systems - Ubuntu vs CentOS. Even differs between CentOS 6 and CentOS 7 (where it will be handled much differently by systemd). So you need to be careful with Internet searches.
As for fragmentation, it exists, but again you shouldn't carry worries over from Windoze. Linux ain't Windoze.
To allay your concerns, for ext4 filesystems as root/sudo try "e4defrag -c <filesystem device>"
Where <filesystem device> will be a partition or lv.
Basically relax, and find some real problem(s) to worry about ....
As others have pointed out, fsck doesn't defrag a filesystem. For ext4, there is a tool named e4defrag, but fragmentation seems to be one of the least worries of Linux sysadmins.
fsck checks the root filesystem at boot time only under one or more of the following conditions:
the system hasn't been shut down in a clean way, thus the filesystem wasn't unmounted before reboot
a certain time has passed since the last check (180 days? It's configurable with tunefs)
the system has rebooted a certain number of times (again, configurable)
the file /forcefsck exists (Debian- and Redhat-basd systems prior to systemd it would seem)
So, the easiest way to force fsck is point 4 - just create that file.
Thanks all for your output here,And for the valuable information, I have choose to go with syg00 suggestion, and on a Ubuntu with ext4 file system this command : "e4defrag -c <filesystem device>" worked like a charm, It said that the system was fine .
Now the other Linux server I mainly wanted to defragment have 'ext3' File system, So i could not run that tool on it, I decided to postpone this operation for now as it apparently will demand more research and testing.
(On the bright side i, at least know how to do it on 'ext4' with an online system, pretty fair for me)
Last edited by ITareliteralyMyInitials; 11-05-2015 at 03:54 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.