Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to run fsck on a disk image before I use it to restore (replace) a corrupted volume. Using Terminal, what would be the proper command, syntax, and options for this operation?

I've just recently become acquainted with Terminal and line commands, so syntax and specific options aren't part of my computing vocabulary. I'm using Terminal 2.1.2, bash, OS 10.6.8.

Ultimately, I'm trying to restore an image to a secondary startup volume (external drive). The image is mounted on my desktop and I want to check it for errors before I use it. Disk Utility runs "repair disk" successfully but the integrity of the image is suspect.

share|improve this question
I suggest that any answers should include how to find out the device node as fsck argument. – Daniel Beck Sep 2 '11 at 19:22

You first need to associate the image with a device, then pick the correct fsck tool for the file system type and run it against the device.

Using hdid to map the dmg to a device:

# hdid Silverlight.dmg 
/dev/disk1              Apple_partition_scheme          
/dev/disk1s1            Apple_partition_map             
/dev/disk1s2            Apple_HFS                       /Volumes/Silverlight

Note the Apple_HFS on disk1s2. Now we can fsck it:

# fsck_hfs /dev/disk1s2 
** /dev/rdisk1s2 (NO WRITE)
   Executing fsck_hfs (version diskdev_cmds-540.1~34).
** Checking Journaled HFS Plus volume.
fsck_hfs: Volume is journaled.  No checking performed.
fsck_hfs: Use the -f option to force checking.
share|improve this answer
Thanks for your comments. Results: $ fsck /dev/disk4 ** /dev/rdisk4 BAD SUPER BLOCK: MAGIC NUMBER WRONG LOOK FOR ALTERNATE SUPERBLOCKS? [yn] y $ fsck -b 32 /dev/disk4 Alternate super block location: 32 ** /dev/rdisk4 BAD SUPER BLOCK: MAGIC NUMBER WRONG Looks like there are other solutions which I may pursue later. But this was helpful to get me a bit further into UNIX. – mvizual Sep 3 '11 at 22:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .