Defragging an APFS hard disk.
I have an external Hard Disk (NOT AN SSD). I have it formatted in APFS. How do I defrag the drive or know if the drive is de-fragmented or not?
MacBook Pro 13”, macOS 10.14
Apple Event: May 7th at 7 am PT
I have an external Hard Disk (NOT AN SSD). I have it formatted in APFS. How do I defrag the drive or know if the drive is de-fragmented or not?
MacBook Pro 13”, macOS 10.14
Okay, I messed around with diskutil's manual and got it done with the following command.
diskutil APFS defragment /dev/<yourdiskloaction> status
If it says disabled, enter the following command to enable it.
diskutil APFS defragment /dev/<yourdisklocation> enable
Okay, I messed around with diskutil's manual and got it done with the following command.
diskutil APFS defragment /dev/<yourdiskloaction> status
If it says disabled, enter the following command to enable it.
diskutil APFS defragment /dev/<yourdisklocation> enable
If the drive is mounted, then APFS will automatically defrag the drive, and there is nothing for you to do. That was also true for HFS+ formatted drives.
You can use Disk Utility First Aid on that drive to ensure that it has no other issues (e.g. green status).
The operating system is not going to report to you that the APFS drive is defragmented. It is a continuous process, not an end condition, and is a leap of faith on your part to believe it is occurring. Disk Utility First Aid checks the drive for other potential maladies, and is not a defragging tool.
No, that's now how APFS works. I ran this on my APFS volume and got the following output.
$ diskutil APFS defragment /dev/disk2s1 status
APFS Volume defragmentation is currently disabled
So, now, my question is how do I turn it on?
I am a long linux based user, so I am good with DIY and usual experiments. To be honest, I would like a LITTLE bit more control on how macOS manages MY FILES. Nothing else. Cause my old hard disk slowed down immensely because it was not defragmented. I do not want the same thing to happen again.
Plus, I am a terminal (both, UNIX and Linux) power user. I just can't get my head over how to achieve this.
Unix ex2,3,&4 formats leave space between the files, it's a preemptive alternative to defragmentation, if your disk is hitting ~90% capacity you might expect some fragmentation. I'm not entirely sure but HFS+ and AFPS avoid defragmentation all together. On a Mac formatted rotational drive it's unnecessary wear and tear, on an SSD it can cause damage and decrease the lifetime of the device.
If you have to defrag something then format NTFS and run windows and defrag away. On macOS you are opening a can of worms.
Okay, I understand that the file system will automatically defrag the hard disk in background, but how do I know if it is de-fragmented or not? Or do I just have to rely on Disk Utility's First Aid?
You are an old Windows user right? The Mac does not need you to mannually get involved in the defrag operation that was commonly needed on older Windows operating systems.
Defragging an APFS hard disk.