3

I am trying to run bad blocks on macOS High Sierra 10.13.6. I installed bad blocks using macports. I keep encountering errors when attempting to run it and I am not sure how to even get bad blocks running

sudo badblocks -c 4096 -s -w -o /Users/mcbeav/Desktop/blocks.txt /dev/disk0s2

This keeps returning the error

badblocks: Resource busy while trying to determine device size

If I try

sudo badblocks -c 4096 -s -w -o /Users/mcbeav/Desktop/blocks.txt /dev/disk0

I get the error

badblocks: Value too large to be stored in data type invalid end block (7813820416): must be 32-bit value

Can anyone please help me out?

mcbeav
  • 11,893
  • 19
  • 54
  • 84
  • Can you try the second command without -c option? What is the size of /dev/disk0? – Amol Dec 04 '18 at 05:16
  • You might be able to circumvent MacOS preventing writes to the disk, by using the non-destructive read-write mode (-n instead of -w). – gregory Dec 05 '18 at 05:39
  • @amol it’s an 8TB drive. I’ll give it a try without the -c flag when I get a moment. Thanks for the suggestion – mcbeav Dec 05 '18 at 05:40
  • @gregory I could give it a try and see what happens, but my intensions are to basically burn in the disk to see if it’s going to fail. It’s brand new, and because of the circumstances I won’t get into, I’d like to run badblocks writing each sector of the disk with random bits and then stress test it using bonnie++ – mcbeav Dec 05 '18 at 05:42
  • @mcbeav, Ok; well then I'd use diskutil to unmount the drive: `diskutil unmount /Volumes/foo` and then try running badblocks. – gregory Dec 05 '18 at 05:52
  • @gregory I also did try this. In disk utility I just clicked the drive, clicked the unmount button, but then there was no disk to pass to the badblocks command. would I just pass it by using the volume's name like you specified /Volumes/volumeName ? – mcbeav Dec 05 '18 at 05:56
  • @mcbeav, are you saying this is the only drive you have? You're going to need a drive with OSX and drive/thumb drive for badblocks. If this isn't possible, I'd use a linux bootable drive to run it. See here for details: https://apple.stackexchange.com/questions/57869/what-free-or-open-source-software-can-i-use-with-mac-hardware-to-verify-integrit – gregory Dec 05 '18 at 06:08

3 Answers3

2

My recommendation is that you:

a) Run badblocks via the Mac OS X console in Recovery Mode

High Sierra (10.13+) along with APFS (file format system) prevent certain operations on disk. You'll have to be in recovery mode or turn off disk protection to do as you propose.

Turn off your Mac (Apple > Shut Down).
Hold down Command-R and press the Power button. ...
Wait for OS X to boot into the OS X Utilities window.
Choose Utilities > Terminal.
Enter csrutil disable.
Enter reboot.

Mac OS X Workaround:

My sense from past experience is that you are hitting the MacOSX security features (Disk protection and app certification).

Booting to Ubuntu (USB Stick) and running the badblocks test that way is going to be easier. (In my opinion)

I hope this points you in the right direction.

Technophobe01
  • 8,212
  • 3
  • 32
  • 59
  • I ran the csrutil disable command from recovery mode before I ever tried to run badblocks. I’ll have to try and run badblocks from recovery and see if that works – mcbeav Dec 05 '18 at 05:33
  • @mcbeav Can you share your Mac Machine version and disk setup? For example, are you using flash disks or rotating disks? My sense is that recovery mode will remove the risk of disk contention. – Technophobe01 Dec 05 '18 at 05:51
  • it's actually a "Hackintosh" So, I'm not sure exactly how much that information would help, but that really shouldn't affect much of anything. The 8TB is a WD Red NAS drive, connected via a SATA port. The OS boots from an SSD. I can boot into windows, but I don't have much experience using the linux terminal in windows now that it is apparently available? – mcbeav Dec 05 '18 at 05:54
  • You may want to review this answer: https://apple.stackexchange.com/questions/57869/what-free-or-open-source-software-can-i-use-with-mac-hardware-to-verify-integrit - for example, boot to Ubuntu and run badblocks from that OS on your disk. [Idea] – Technophobe01 Dec 05 '18 at 05:55
  • Unfortunately I can't test anything out for a couple of days now. The post is a bit old, and some of the information is incorrect, however overall, I think I'm probably going to end up just booting Linux from a USB stick and running bad blocks like that. I don't really want to waste anymore time messing with it. I'm going to try whatever is suggested in the thread and if nothing works go for the Linux route. – mcbeav Dec 05 '18 at 05:58
  • @mcbeav - My sense from past experience is that you are hitting the MacOSX security features (Disk protection and app certification). Booting to Ubuntu (USB Stick) and running the badblocks test that way is going to be easier. (In my opinion) – Technophobe01 Dec 05 '18 at 06:02
  • this is probably what I will end up doing, Thanks for the advice and help! – mcbeav Dec 05 '18 at 06:03
1

I had the same issue. But then I opened Disk Utility and pressed Eject on the physical device (make sure it's the hard drive and not the volume). This will unmount the volumes but will keep the device still available, which you can check by running:

diskutil list

Now run the badblocks command again and it should work fine.

Saifur Rahman Mohsin
  • 929
  • 1
  • 11
  • 37
0

I was able to get badblocks working for OSX 10.15 by

1) disabling csrutil, as explained here

2) unmounting the badblock-desired drive via Disk Utility

3) running badblocks: sudo badblocks -b 4096 -w -s -v "$MOUNT_POINT" > "badblocks.info", where MOUNT_POINT=/dev/disk2


I installed badblocks via brew install e2fsprogs, as described here


Tangentially, I also did this in order to query the USB-connected drive via smartctl.

sam-6174
  • 3,104
  • 1
  • 33
  • 34