Writing directly to a USB disk in OS X

Disclaimer : This procedure erases all data on the target volume so use the volume relevant to your setup, eg. that of your USB disk. I and my associates at meinit do not take responsibility if you overwrite the wrong volume and lose your music, movies, thesis, world peace plan etc. And there might be an easier way to do this, I await comments.

Today I would like to share a short note on how to write a raw disk image to a USB memory stick in OS X. The raw disk image can, for example, be a bootable filesystem image for a OS installer. In my case Fedora 8's "diskboot.img".

The main problem is that I was used to Linux's way of device naming but under OS X if you wish to write directly to a disk you need to use the "raw" version of the device. For example /dev/disk1 has raw device /dev/rdisk1.

The other issue I encountered is that when I insert the USB memory stick then /dev/disk1 exists but is mounted so I cannot write to it directly. If I eject the disk then the device node also disappears and I can't write to it. So we need to use the "Disk Utility" to properly unmount the volume, this utility is contained in Applications -> Utilities. Start this up, making sure your USB stick is plugged in. Once started you will see a list of storage devices, much like below :

screenshot of Disk Utility

Here you can see the USB storage quite easily. Highlight the partition within your storage media and click "eject". Now the device node still exists and you can use "dd" to write to the disk directly, /dev/disk1 in my case. My command to write to the disk was :

$ sudo dd if=./diskboot.img of=/dev/disk1 bs=8k

Adjust as required. Good luck and happy new year! :-)

Comments

This problem occurs when your

This problem occurs when your USB disk is not mounted properly and when you start trying to transfer files than the old files will be erased or overwritten with the same file names this will cause you to lose your data as per rush essay articles. It is better to keep a safe copy of your data and see that the disk is mounted properly or not.

open a terminal and do the

open a terminal and do the following:

% diskutil list
...
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *962.5 Mi   disk2
   1:                 DOS_FAT_16 KINGSTON                962.0 Mi   disk2s1
...

Find your usb stick in the output (i've included mine as an example)

% diskutil unmountDisk /dev/disk2
Unmount of all volumes on disk2 was successful
% sudo dd if=your-image-file-name.img of=/dev/rdisk2 bs=1m
946+1 records in
946+1 records out
992837632 bytes transferred in 187.554888 secs (5293584 bytes/sec)

This will take a while. But it'll be much faster (and healthier for the life of your USB flash stick) to use rdisk instead of disk and a large buffer size to minimize the number of flash erase and rewrites that the stick must do.

Finally, before you pull it out:

% diskutil eject /dev/disk2

Thank you. :)

Thank you. :)

If you click on a volume

If you click on a volume inside the USB device (in Disk Utility), you will see where it is mounted (eg. /Volumes/SomeDisk). Use the following:

# sudo diskutil unmount /Volumes/SomeDisk

This will cleanly unmount the volume, but not the disk, and keep the device nodes visible in Disk Utility (they should be grey labels instead of black to show they aren't mounted). Now, you can do a proper restore without getting the 'device busy' nonsense. If you receive an error about 'device does not support this operation', go to the Images menu and select Scan Image for Restore... Try it again and all should work.

I tried ejecting the

I tried ejecting the filesystem, this didn't work. Next i tried how it would work using the command line, this is another solution if your eject-button in disk-utility keeps throwing your usb-disk out.

sudo umount -f /dev/disk1s1

This way only the filesystem will be unmounted, not the device.

Grtz Wout

Thx. unmounting only

Thx. unmounting only filesystem was the clue I needed.

Anny other guide unmounted the whole device. Rendering anny dd command useless against a non-existing " /dev/rdisk1"

Thx a bucket.

Brilliant thanks!

Brilliant thanks!

Great article, thanks! btw:

Great article, thanks!

btw: you can find out the bsd block device using 'mount' prior to the unmount. :)

Alex

If you are not sure which

If you are not sure which device node your usb device has, open System Profiler, and open the Hardware / USB entry, then find the disk device in the tree, if you select, it will display a list of properties, the one you are looking for is BSD Name, for example, if BSD Name says disk3, your device node is /dev/disk3

Just check this to make sure you are not overwriting your backup hdd or something...

Hannes

About Consultancy Articles Contact




References Red Hat Certified Architect By Robert de Bock Robert de Bock
Curriculum Vitae By Fred Clausen +31 6 14 39 58 72
By Nelson Manning [email protected]