Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create a disk image from a directory in the Terminal UNIX
Apple's Disk Copy program, located in /Application -> Utilities, lets you create a disk image from a folder by drag and drop. You can accomplish the same thing from the command line, but it requires several steps. Here is the procedure to follow; in this example I make a disk image from my Documents directory. First, you need to find out how much disk space the directory holds:
% du -s ~/Documents
65576   /Users/kirk/Documents
The du -s command returns the number of sectors for the directory specified as an argument. This tells you how big the disk image must be. In the above example, there are 65,576 sectors. Add about 5% to this for meta-data: this gives 69,000 rounded up. Now, create the disk image file:
% hdiutil create -sectors 69000 -fs HFS+ -volname Documents ~/Documents
This creates a disk image called Documents in the current working directory. The disk image is formatted in HFS+ and has 69,000 sectors. Next, mount the disk image file:
% hdiutil mount Documents.dmg
Copy the contents of the directory to the disk image. Use ditto and the -rsrcFork option to maintain any resource forks that may exist:
% ditto -rsrcFork ~/Documents /Volumes/Documents
Now that you're finished, you can unmount the disk image:
% hdiutil unmount /Volumes/Documents
It took five commands to create a disk image from a directory. That's a bit more than dragging a folder onto Disk Copy, but it's still pretty quick. And with a little work, you can create a shell script to do this automatically.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[7,522 views]  

Create a disk image from a directory in the Terminal | 2 comments | Create New Account
Click here to return to the 'Create a disk image from a directory in the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create a disk image from a directory in the Terminal
Authored by: dylanjames on May 14, '03 07:17:52PM
"...with a little work, you could write a shell script..." Indeed! Somebody already has. Check out: buildDMG.pl

[ Reply to This | # ]
Create a disk image from a directory in the Terminal
Authored by: peterneillewis on May 15, '03 02:00:15AM

Although it doesn't fully automate the task, you can also do

open -a '/Applications/Utilities/Disk Copy.app' ~/Documents

Disk Copy will launch and ask you to save the disk image and off it goes.



[ Reply to This | # ]