Skip to content

Instantly share code, notes, and snippets.

@waynegraham
Last active May 30, 2018 13:23
Show Gist options
  • Save waynegraham/17b12832f9cb5613c1c170a85af920d6 to your computer and use it in GitHub Desktop.
Save waynegraham/17b12832f9cb5613c1c170a85af920d6 to your computer and use it in GitHub Desktop.
Repair Hard Drive

I ran in to a problem with a new Western Digital hard drive (2TB) for use as a Time Machine backup drive on High Sierra. After plugging it in, I kept getting errors like "MediaKit reports not enough space on device for requested operation." After some digging, it appeared that this is an issue in macOS with initializing APFS from an NTFS partition.

Pulling out some old utils, I used diskutil and dd to fix the issue:

$ disktuil list
...
/dev/disk4 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *2.0 TB     disk4
   1:                  Apple_HFS                         2.0 TB     disk4s1

I know that this is disk4 now so I can perform the following commands to umount it, write 0s to the disk, then partition it with HFS+.

$ diskutil unmountDisk force disk4
Forced unmount of all volumes on disk4 was successful

$ sudo dd if=/dev/zero of=/dev/disk4 bs=1024 count=1024
Password:
1024+0 records in
1024+0 records out
1048576 bytes transferred in 0.836656 secs (1253294 bytes/sec)

$ diskutil partitionDisk disk4 GPT JHFS+ "Backup Drive" 0g
Started partitioning on disk4
Unmounting disk
Creating the partition map
Waiting for partitions to activate
Formatting disk4s2 as Mac OS Extended (Journaled) with name Elements
Initialized /dev/rdisk4s2 as a 2 TB case-insensitive HFS Plus volume with a 155648k journal
Mounting disk
Finished partitioning on disk4
/dev/disk4 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *2.0 TB     disk4
   1:                        EFI EFI                     209.7 MB   disk4s1
   2:                  Apple_HFS Elements                2.0 TB     disk4s2

This fixed the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment