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

Create an encrypted disk image that grows as required System
Not an hint by my own, but worth sharing it I think. Take a look at Make an Encrypted Sparse Disk Image over on themacmind.com. This explains how to use the command line disk utility (hdiutil) to create an encrypted disk image that requires only as much drive space as required by whatever is on the image.

[Editor's note: If you create a disk image in the Finder using the Disk Utility application, it will take up as much space as you allotted it, even when empty. Using the command line as explained in the article, you can create an image that grows as required, though it will not shrink when you remove items from the image.]
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[72,349 views]  

Create an encrypted disk image that grows as required | 15 comments | Create New Account
Click here to return to the 'Create an encrypted disk image that grows as required' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Fragmented Sparse images
Authored by: hmelton on Feb 17, '03 04:36:02PM

While the hint works as advertised, and I am definitely using it, there is a comment in hdiutil's man page that warns about disk fragmentation while using sparse disk images. I assume that the sparseimage's file is locked into place on the real disk and won't move if you attempt to defrag the real disk. In addition, the nature of a sparse disk that grows on demand assures that it will be fragmented. None of these problems are killers since you can always copy the data to a normal disk image, delete the sparse and re-create it and move the data back for a less-fragmented version.



[ Reply to This | # ]
How to Make a Sparse Image
Authored by: noworryz on Feb 17, '03 08:56:35PM

Here's the executive summary in case the link over at TheMacMind goes away.

You can use the unix utility hdiutil to create and examine disk images, with more options than Disk Copy provides.

One such option is to create a disk image (possibly an encrypted disk image) that is sparse; i.e., the image file is only as large as it needs to be. (However, the image file never shrinks in size once it has expanded.)

For example, suppose you are keeping all your work, mail, etc. on an encrypted disk image. You occasionally eject the image volume and burn the image file to CD-R for backup. With a sparse image, the burning may be much faster because empty space in the volume will not be backed up.

To create an encrypted, sparse disk image, open a Terminal window and cd to the directory in which you want to create the image file. For example:

cd ~/Desktop

Then type the command:

hdiutil create -size thesize -encryption -type SPARSE -fs HFS+ thename

Above, thesize is the maximum size that the volume will ever be able to contain, for example, 660m for 660 megabytes or 1g for one gigabyte. Note that if you want the image file to remain below a certain size (such as the size of a CD) you must allow for approximately 10% overhead. Also above, thename is the name of the image file you want to create, not the volume name.

You will be asked for a password or phase to secure your file. At that time, you should probably uncheck "Remember password (add to Keychain)" because your passphrase will be visible in the Keychain to anyone with physical access to your computer.

The file thename.sparseimage is then created. Double click on the file to mount it (after entering the password again) then click on the mounted volume on the Desktop and hit return to change its name from "untitled."

You can also use the hdiutil program to find out information about any disk image, even those created by Disk Copy. From the Terminal type:

hdiutil imageinfo theimage.ext
where theimage.ext is the name of the image file, for example, myimage.dmg or myimage.sparseimage or whatever.

There is a manual page available; type man hdiutil in the Terminal.

[ Reply to This | # ]

How to Make a Sparse Image
Authored by: novalies on May 27, '04 09:47:21AM

>you should probably uncheck "Remember password (add to Keychain)" because your passphrase will be visible in the Keychain to anyone with physical access to your computer.

I have testet this and on my machine you can open the Keychain Util, see all the entrys, but to display the Passwords, you have to enter first the Keychain-password.



[ Reply to This | # ]
How to Make a Sparse Image
Authored by: jago_lebow on Nov 24, '05 11:02:26AM

Ok so I never get prompted for a password. The only way this works for me is to put the passphrase on the command line, not very secure especially when mounting.

Anyone know any other way to get this to work ?



[ Reply to This | # ]
Create an encrypted disk image that grows as required
Authored by: jurg on Mar 04, '03 04:11:25AM

my sparse disk image got corrupted after a kernel panic. I could reproduce this behaviour by making a new one and do a hard reset of my mac (tried that several times). My non-sparse disk survives. In both cases I used encrypted images and journaling on the partition where the image was on.

For the moment I stich to non-sparse disk images...



[ Reply to This | # ]
Corrupt encrypted sparse image
Authored by: mickerf on Apr 20, '03 08:23:50AM

I've run into the same problem - my encrypted sparse image
became corrupt after a hard reset... I've tried everthing I can
think of and searched thoroughly and haven't come up w/
anything yet. Anyone know of any documentation on recovering
corrupt disk image files?



[ Reply to This | # ]
Corrupt encrypted sparse image
Authored by: John Kiniston on Jun 07, '03 02:39:15AM

Have you had any luck in fixing your corrupt image?

I just lost some data to a crash that killed my image and I'd like to get that data back.



[ Reply to This | # ]
HOW-TO: Recover a corrupt encrypted sparse image
Authored by: Krioni on May 22, '08 11:54:13AM
There's a hint here on this site that has a solution on how to recover a corrupt encrypted sparseimage:

http://www.macosxhints.com/article.php?story=20070419082314524&query=corrupt%2Bsparseimage

Make sure to read the whole conversation there, since there are some issues to consider.

---
http://www.danshockley.com

[ Reply to This | # ]

Create an encrypted disk image that grows as required
Authored by: optimusprime on Feb 11, '05 01:08:41PM

This appears to be the same corruption that happens File Vaulted home directories. FileVault uses encrypted sparse images also. My Vaulted home dir got corrupted a couple weeks ago, but luckily I had a recent backup.

I would avoid sparse images until they are more reliable if you care about the data on them.



[ Reply to This | # ]
Create an encrypted disk image that grows as required
Authored by: netguy45 on May 01, '06 12:53:30PM

The corrupted sparse disk image after a hard-reset problem is still present in 10.4.6



[ Reply to This | # ]
Create an encrypted disk image that grows as required
Authored by: elmimmo on Mar 04, '03 05:44:59AM

I do not know how many of you work in an environment where things need to be encrypted. I do not.

What I would consider useful, though, but do not know if would be possible via a similar trick, are writable compressed images that grow as they need. Where I work we use lots of CDs for backing up data. We used to use DiskDoubler to compress data to fit >700MB in a CD, and thus minimize the spreading of a single project among several CDs, however the process of decompressing to HD the data when you only need to look at something is rather uncomfortable.

I'd love to be able to create that sort of image so that when the image file approched 700MB I toasted it in a CD. When the data needed to be used, just loading the CD and mounting the image saved in it would grant you instant access to >700MB transparently, without the need to copy it to the HD first.

However I do not know if there is a way to make a compressed writeable disk image. Making an uncompressed writeable image and converting it to an unwriteable compressed one at some point is not that useful, since you do not know what the compressed size will be around.



[ Reply to This | # ]
Now built-in to Panther's Disk Utility
Authored by: gslobber on Nov 04, '03 02:02:25PM

The ability to create sparse disk images is now available in Panther's Disk Utility (the tool that replaced Disk Copy).



[ Reply to This | # ]
Create an encrypted disk image that grows as required
Authored by: jasontm1 on Jan 19, '07 06:55:04AM

The hdiutil command also now includes the verb 'compact' which will let you shrink the size of a sparse diskimage. If using an encrypted image you can leave the encryption password out of the command and you will get an os x popup asking you for the password, this should keep it from getting stored in your terminal history.



[ Reply to This | # ]
In OS 10.5...
Authored by: mkoistinen on Nov 03, '07 06:28:44AM

... it is directly possible with the Disk Utility to create sparse and encrypted volumes.



[ Reply to This | # ]
Create an encrypted disk image that grows as required
Authored by: nenewsjunkie on Jun 30, '09 08:48:09AM
10.5 has this option directly in disk utility itself. I have a video tutorial available on my blog. Check it out:
-Ken

[link:]http://www.tz42.com/blog/2009/06/30/mac-encryption-using-disk-utility/

[ Reply to This | # ]