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.
Q: What makes you think your disk needs to be defragmented?
PS:
We really need more context before we can give you an intelligent answer. So I
PPS:
i92guboj and Didier Spaier are both correct - Linux seldom (never?) needs to be "defragmented".
But VMWare running under Windows might. Or Windows itself might. Or you might have a bona fide performance or system integrity issue that you're misinterpreting as "I need to defragment".
Again - please tell us *why* you believe you need to defragment, please tell us the "context" of your question.
There are no reliable tools to defrag anything in Linux (though a tools for ext4 is in the way, but I doubt you are using ext4 as your file system).
The easiest way to defrag a volume in linux is to backup the whole disk to another location, either using tar, cp or whatever. Make sure you preserve permissions and that you check the validity of the backup after having made it. Then erase your original volume and restore the backup. That will store everything in consecutive blocks and the fragmentation will be gone.
However, may I ask why do you want to defragment? Tipical linux fs's do not get too fragmented unless they are almost full, and the impact on the performance shouldn't be too big either.
The hard drive I have Suse 11.0 on needs to be defraged.
I have no idea how to go about doing this.
Any suggestions and instructions would be appreciated.
Running Suse 11.0 under VMware.
Thanks
The fragmentation level of a virtual drive is dependent on the filesystem type of the virtual drive, and possibly on actions of the host's filesystem. I don't know about VMWare, but in VirtualBox, you have two options for creating a guest filesystem: 1) dynamic and 2) static.
In the case of static, any fragmentation is dependent on how fragmented the drive was when the virtual filesystem was created, but will not get worse based on actions of the host filesystem *unless* the host's filesystem is defragmented.
In the case of a dynamic guest, then in addition to the issues for a static filesystem, there is also the possibility of bad placement during normal expansion of the guest filesystem up to its limits.
The problem is that the guest will not know the level of fragmentation that it inherits from the host OS, and it will not be able to know any fragmentation added or subtracted stemming from a host filesystem defragmentation action. I'd just leave it alone unless you can give some solid evidence that you are suffering from guest filesystem fragmentation.
I think I have some foggy memory about being able to mark a file so it's not touched by the Windows defragmenter (maybe marking it as system file or whatever, I don't really remember). If that's truly possible, you only need to find a way to create a file that uses contiguous blocks (don't ask me how, maybe your VM software can do that for you).
Once you take care of this, you should only have to worry about the fragmentation on the guest SO, inside the VM disk image.
Most 'VM' use containers therefore the file will not be touched by the M$ Win host defragment problem when using GNU/Linux as the client. These containers can be dynamic or fixed length that you would setup during the initial 'VM' install.
Code:
excerpt from 'VirtualBox UserManual.PDF';
By default, VirtualBox uses its own container format for guest hard disks – Virtual Disk
Image (VDI) files.
The VDI files reside on the host system and are seen by the guest systems as hard
disks of a certain geometry. When creating an image, its size has to be specified, which
determines this fixed geometry. It is therefore not possible to change the size of the virtual hard disk later.
...
• If you create a fixed-size image of e.g. 10 GB, a VDI file of roughly the same
size will be created on your host system. Note that the creation of a fixed-size
image can take a long time depending on the size of the image and the write
performance of your hard disk.
• For more flexible storage management, use a dynamically expanding image.
This will initially be very small and not occupy any space for unused virtual disk
sectors, but the image file will grow every time a disk sector is written to for the
first time. While this format takes less space initially, the fact that VirtualBox
needs to constantly expand the image file consumes additional computing resources,
so until the disk has fully expanded, write operations are slower than
with fixed size disks. However, after a dynamic disk has fully expanded, the
performance penalty for read and write operations is negligible.
For either of the above two image types (that is, irrespective of whether an image
is fixed-size or dynamically expanding), you can also specify whether write operations
affect the image directly.
The dynamic would be the one possible mode that could be effected by some form of broken or interleave storage problem for the container. But the fragmentation will not be a problem with fixed length.
There are multiple levels of "defrag". The Windows defrag is under "My Computer, Management, Storage, Disk Fragmenter". It's definitely a good thing to do ... but it won't necessarily help VMWare
Another level is VMWare defrag. With VMWare Workstation, you can find it under:
a) <Select> a VM
b) Settings
c) [Hardware]
e) <Select> a hard disk
f) [Defragment]
There is *not* a defragmentation utility at the final (Linux) level. It's simply not needed.
Now that would be a good reason to use xfs. It is the only linux file system that can be defragmented AFAIK. Not that I have ever seen any need to use it.
Now that would be a good reason to use xfs. It is the only linux file system that can be defragmented AFAIK. Not that I have ever seen any need to use it.
Perhaps, but what would you be accomplishing at the Guest level other than a somewhat random reordering of your filesystem WRT the hardware. Remember, the Guest OS does not have access to the actual hardware. So the Guest filesystem must assume that the Host OS has a reasonable ordering of its filesystem. Of course, it's possible that VMWare gets as many contiguous blocks as possible when it sets up a virtual FS for the Guest.
Well, speaking from my experience installing a copy of XP in vmware, it was 40% fragmented righter after installing. I reduced fragmentation to virtually zero by running the XP defragmentation tool. IOW, it should not be taken for granted that the fragmentation is situated at a lower level than that of the virtualized file system.
Well, speaking from my experience installing a copy of XP in vmware, it was 40% fragmented righter after installing.
What did you use to measure this fragmentation level of 40%, and how did you know that the Guest OS was fragmented 40% WRT the hardware. Or was this 40% measured by the Host OS, and did VMWare take this into account when creating the Guest FS? If it did, did you wind up with a worse-ordered Guest FS after you defragged it? Remember, the Guest OS has its own ideas of what the correct ordering for a file is, and those are layered over whatever the Host gives it to work with. Any relationship between virtual location and physical location are probably coincidental.
I've had some more thoughts about this, and I'm starting to change my mind. Given that VMWare (or Virtual Box) will not be deleting records from a virtual FS, perhaps there won't be the usual fragmentation problems associated with file aging.
I've had some more thoughts about this, and I'm starting to change my mind. Given that VMWare (or Virtual Box) will not be deleting records from a virtual FS, perhaps there won't be the usual fragmentation problems associated with file aging.
The documentation shows that the host does provide the space to the client via a container. Fragmentation would be due to the records controlled by the OS. If the host just provides a container then no fragmentation will be effected by that host but by the efficiency of the client OS.
So if the GNU/Linux is the host providing a container of 10GB to a M$ WinXP, the fragmentation will be accorded by the WinXP OS not GNU/Linux. This would also be true if the host was WinXP with a GNU/Linux client. The container for the GNU/Linux filesystem would perform R/W via the VM host hardware within the container for the GNU/Linux filesystem.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.