-3

Consider the following case: a disk has two very large files stored one after the other - the first being slightly smaller than the second. As far as I know (and please correct me if I'm wrong) - If I delete the first - defragmenting the drive will NOT move the second to where the first was. Is there any way to tell the defragmenter to do that?

I want to store disk images on a drive, and that when I create a new one, and delete an old one - the defragmenter will compact them (-move them close together), so that there will be room for the next one, so that every image will be stored sequentially (-all of its bytes). If the files will not be "compacted" (in the sense mentioned above) - when the drive will have files till close to its end - it will start fragmenting the files. Which is what I want to avoid.

No 3rd party tools please.

ispiro
  • 1,501
  • 4
  • 29
  • 48
  • 1
    If it is not available an option as _keep file together_, you can just a trick valid if you have almost no more space on the device: you can try to delete the 1st file, copy the 2nd with a new name (it will be copyed almost all over the position used before from the 1st), then delete the 2nd file and start the defragmentation (it should work only on the last part on the new copy of the second file...) – Hastur Jan 25 '15 at 12:10
  • @Hastur Nice workaround. I'll still be looking for a direct way of doing this. But not bad! – ispiro Jan 25 '15 at 12:12
  • 1
    Can anyone please explain what's wrong with the question so I can edit it? – ispiro Jan 26 '15 at 12:30
  • Related: http://serverfault.com/questions/782/do-i-need-to-defrag-unix-filesystems – killermist Jan 26 '15 at 18:04
  • http://geekblog.oneandoneis2.org/index.php/2006/08/17/why_doesn_t_linux_need_defragmenting Mostly talks about how unix-like filesystems work, but some translates to NTFS. I don't mention these to try to explain how to do what you're trying to do, but instead to explain that what you're trying to do is probably totally unnecessary. That might be a reason you're getting downvotes. I use ZFS on my NAS, and with that, I don't have performance issues unless I unwisely fill a pool to more then 80% full. – killermist Jan 26 '15 at 18:13
  • Why do you think you need to do this? – Keltari Jan 26 '15 at 18:48
  • @killermist `I don't have performance issues unless I unwisely fill a pool to more then 80% full` - I want to store as many disk images as I can to serve as a makeshift "system restore"-system (because system restore _does_ delete user files (such as JavaScript files).) So yes, it _will_ be very full. – ispiro Jan 26 '15 at 18:58
  • @Keltari See my previous comment. I'm worried about slow performance (mainly while backing up. I'm hoping restoring will be kept to a minimum, of course) because of disk fragmentation. – ispiro Jan 26 '15 at 19:00
  • @ispiro This isnt 1990. Defragmenting drives, even in Windows, is almost unnecessary. – Keltari Jan 26 '15 at 19:15
  • @Keltari I disagree. Most of the talk about Windows 7 not needing defragging is because it's done regularly. Not the case with an external drive, and even with the internal drive there are issues... (I recently defragged a "0% fragmented" drive. It took over an hour.) – ispiro Jan 26 '15 at 19:23
  • @ispiro you can disagree all you want, you would still be wrong. There are tons of articles showing that defragging is no longer necessary. – Keltari Jan 26 '15 at 19:41
  • @ispiro Under the right situations, defragmenting a drive with 0% fragmentation can take a VERY LONG time because each and every file on the drive has to be read and rewritten to a new location to consolidate the free space to one monolithic block. Rewriting/moving 1.6Tb of files that were already not fragmented is a waste of time. And "fragmentation" (ooh, scary, BOO!) is not the malignant cancer it is portrayed to be. You may have done or be doing more harm by defragmenting than you think. Proper caching is one of the reasons that fragmentation is fairly meaningless. – killermist Jan 26 '15 at 19:48
  • @killermist Let's assume you're right. But is asking such a question a reason for downvotes? Is it _that_ bad despite [a question on this site](http://superuser.com/questions/200290/do-i-need-to-manually-defrag-a-windows-7-pc) having 3 answers, all of them not dismissing defragging? I'm ***not*** arguing that it _is_ needed. I'm asking whether it's so bad to ask something, assuming something that others here agree with. (And again, I'm not arguing about defragging here. Maybe you're right about that.) – ispiro Jan 26 '15 at 19:59
  • The question did not seem to initially be useful, but I withheld judgment on the question while offering comments, hoping that the usefulness of the question would increase. That didn't happen, and (to me) the question is not useful, so I voted as I saw fit. Nothing personal about it. I'm not going to go serial downvote your other questions or anything. This one just isn't useful. – killermist Jan 26 '15 at 20:04
  • @killermist OK. No problem. I was just surprised about the bad rep. Anyway, thanks for the feedback. – ispiro Jan 26 '15 at 20:14

2 Answers2

1

First things first, you wont ever realistically be able to get the files perfectly side by side and may i ask why would you want to?

Secondly you need to tell us what filesystem it is for ntfs leave a small amount of freespace near the files to deal with expansion (but often it doesnt work well enough)

But the only way to realistically do it is to juggle the files around and force the system to have no other option but to override the files (overall so much effort)

  • `you wont ever realistically be able to get the files perfectly side by side` - Why not? `what filesystem it is` - NTFS. `small amount of freespace ... deal with expansion` - I don't understand that - What expansion? – ispiro Jan 25 '15 at 12:15
  • Let's suppose you have a text file in which you keep a log. The program that use the log will increase that file size over the sector size and will require new space (Darkshadow called it expansion). Since it is not a so rare case some filesystems try to optimise it leaving sector free after the physical end of the file... – Hastur Jan 25 '15 at 12:19
  • Well Why not is because the way ntfs actually writes files to a disk it leaves a small amount of size on either side of the file, So lets say if you edit a text document it has space to be written to the disk and not have to be written to another completely random part of the hdd... – Darkshadow2913 Jan 25 '15 at 12:19
  • 1
    Read this it might help explain it http://www.howtogeek.com/115229/htg-explains-why-linux-doesnt-need-defragmenting/ – Darkshadow2913 Jan 25 '15 at 12:19
  • Thanks. Anyway, I don't have to have it _perfectly_ side by side. My goal is just to avoid filling up the drive quickly and then starting to fragment every new disk image. But thanks for the information! – ispiro Jan 25 '15 at 12:22
  • @Hastur Thanks. By the way - if you don't add "@ispiro" in your comment. I don't get notified of your post. – ispiro Jan 25 '15 at 12:23
  • @Darkshadow2913 See my previous comment. – ispiro Jan 25 '15 at 12:24
  • Laziness (mine) ... you were here to wait your answer... I was sure you read it... – Hastur Jan 25 '15 at 12:24
  • Nice to know, might keep it in mind for future posts – Darkshadow2913 Jan 25 '15 at 12:25
0

You can't make Windows 7's defragmenter do exactly what you're asking for, so you'd have to look at 3rd party tools.

However, why are you so worried about a bit of fragmentation? Fragmentation is normal and a small amount of it will cause you absolutely no appreciable loss in performance.

misha256
  • 11,298
  • 6
  • 53
  • 69
  • [You wrote](http://superuser.com/questions/869759/will-a-large-block-size-affect-speed-noticeably/869847#comment1156532_869847)`...the primary benefit in choosing larger cluster sizes is that it will reduce the likelihood of fragmentation in larger files.` - implying that fragmentation _does_ matter. Besides - with time - fragmentation might be quite large here. (You can see the discussion in the comments directly under the question.) – ispiro Jan 26 '15 at 23:44