0

Access a physical Ext3 drive under Windows host system for defrag?


Note: Debunking the myth of Linux Filesystems not getting fragmented. http://www.webupd8.org/2010/03/install-defrag-defragmentation.html

But that's a common misconception and in some cases you do have to defragment your Linux filesystems. This is even [confirmed by an Ubuntu developer on a very recent post][1] I stumbled upon just a few minutes ago about ureadahead on the ubuntuforums.
From: Ubuntu Forums Post: http://ubuntuforums.org/showthread.php?t=1434502
The only way to avoid this is defragmenting your disk.

But Linux filesystems don't need defragmenting!

Whoever told you that is deeply mistaken, this is one of the most common myths of Linux.

What is true is that Linux filesystems avoid, where possible, fragmenting their inode tables. This means that the index of how files are split up (fragmented) across the disk, and where those parts are, tends to be kept together as a whole.

That's a good thing; fragmentation of inode tables is a big problem for other filesystems (FATs in that filesystem, etc.) so by keeping them together, it wins a lot of performance.

But the data itself is still fragmented, and spread all over your disk in a random order. And unfortunately during boot, it's the data we need.

One of the future things we want to do is use the ureadahead analysis of what we need during boot to feed into a defragmenter, so everything we need is in one big block on the disk.


Kind of the opposite of this:
https://askubuntu.com/questions/59007/defragging-ntfs-partitions-from-linux

  • Maybe via a Linux (Mint etc.) VM?
  • Maybe via Windows Subsystem for Linux>?
  • Some other Subsystem/ package that can run under Windows and do so?

Would it be possible to access a physical drive some way to execute a Linux defrag tool/ utility, all under a Windows Host OS?

https://en.wikipedia.org/wiki/Ext3#Defragmentation

While ext3 is resistant to file fragmentation, ext3 can get fragmented over time or for specific usage patterns, like slowly writing large files.[23][24]

  • 1
    WSL can't do that. – Michael Homer Apr 14 '17 at 4:03
  • 1
    ext3 and ext4 don't need any defrag. – cylgalad Apr 14 '17 at 7:36
  • @cylgalad - en.wikipedia.org/wiki/Ext3#Defragmentation "While ext3 is resistant to file fragmentation, ext3 can get fragmented over time or for specific usage patterns, like slowly writing large files.[23][24]" – Alex S Apr 15 '17 at 3:14
  • 1
    Still, defrag isn't really useful anyway (including for windows) and totally useless (even harmful) with SSDs. – cylgalad Apr 15 '17 at 8:11
3

This is possible, using a Linux virtual machine. In this article, I will assume you have setup Linux as a virtual machine in VirtualBox, and know how to use Linux defragging tools.

  1. Plug in the hard drive. DO NOT CLICK FORMAT in the dialog box that pops up.
  2. Hit Win + R. And type

diskmgmt.msc

  1. Scroll down in the bottom section to your drive. Note the Disk NumberDiskmanagement
  2. Close any open VirtualBox windows.
  3. Open command prompt as administrator, by hitting Win + X, and clicking Command Prompt (Administrator)
  4. Now type

cd %programfiles%\Oracle\VirtualBox

or wherever you installed VirtualBox

  1. Now type

VBoxManage internalcommands createrawvmdk -filename C:\usb.vmdk -rawdisk \.\PhysicalDrive#

where # is your disk number. C:\usb.vmdk can be any location you want.

  1. Open Virtual Box as administrator. (Right Click > Run as Administrator)
  2. On your Linux virtual machine, right click and hit settings. Then choose, storage, and add SATA hard disk. Then click choose existing disk.Stuff
  3. Navigate to your .vmdk hard disk file, and click Ok. Assuming you did it right, it should look something like this.Preview Click "Ok"
  4. Boot up your Linux virtual machine, and the drive will appear in Linux.

[EDIT]

Note that the "Run as administrator commands" are specific to Windows 10. Also, the disk will NOT work if it is not in administrator mode.

  • Thanks for posting this reply, but I do not have a VMDK, I am talking about a legitimate Linux Hard Disk with Ext3 and other volumes. PS: I use Hyper V under windows so wondering if a Linux VM can load/ add the entire HDD as a Disk and I can run relevant Linux tools on it. – Alex S Apr 14 '17 at 5:01
  • Is step 7 where you are loading the physical HDD? (but its being represented by a .VMDK even though there is not actual VMDK?) – Alex S Apr 14 '17 at 5:03
  • 2
    Yes. The .vmdk being loaded is a "pretend" virtual hard disk. It is just a reference to the attach hard drive. – Modelmat Apr 15 '17 at 4:14
  • If this is the correct answer, could you mark it so? This has worked? – Modelmat Apr 16 '17 at 3:52
  • I will be trying it out soon. Need to set it up – Alex S Apr 16 '17 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.