hdiutil and creation of more then one partition in a dmg and sparse image?

Hello,

My main question,
after reading the man page and googling, I can't find any way to create a DMG file with more then one partition. Is this even possible?


-
My finaly goal is to attach those with -mountRandom and - nobrowse from inside a cocoa.app.
I need the return value to get the random path to those partitions.


hdiutil attach test.dmg -mountrandom /Users/dev/Desktop/testdmg
/dev/disk7 GUIDpartitionscheme
/dev/disk7s1 Apple_HFS /Users/dev/Desktop/testdmg/dmg.A43MrA


But I see that when I use a mutli partition dmg ( here simulated ) I will have to look for one or more random paths, something like this.

hdiutil attach test.dmg -mountrandom /Users/dev/Desktop/testdmg
/dev/disk7 Applepartitionscheme
/dev/disk7s1 Applepartitionmap
/dev/disk7s2 Apple_HFS /Users/dev/Desktop/testdmg/dmg.A43MrA
/dev/disk7s3 Apple_HFS /Users/dev/Desktop/testdmg/dmg.7IaUpK


What is the best way?

to grep a line wich contains '/dmg./ and then awk print $3 ?

path=/Users/dev/Desktop
hdiutil attach $path/test.dmg -mountrandom $path/testdmg | grep '/dmg.' | awk '{ print $3 }'


but what when I attach f.e a sparse image not using the -mountRandom, then I have no '/dmg.' just volumes?

Is that doable in one universal piece of code?

Posted on Jul 20, 2010 5:53 AM

Reply
15 replies

Jul 21, 2010 10:16 AM in response to Obj-D

I can only answer your question re:multi partition on a .dmg with:
doug-penningtons-power-mac-g4:Desktop dougp$ diskutil list
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: Apple partitionscheme *57.3 Gi disk0
1: Apple partitionmap 31.5 Ki disk0s1
2: Apple_Driver43 28.0 Ki disk0s2
3: Apple_Driver43 28.0 Ki disk0s3
4: Apple DriverATA 28.0 Ki disk0s4
5: Apple DriverATA 28.0 Ki disk0s5
6: Apple_FWDriver 256.0 Ki disk0s6
7: Apple DriverIOKit 256.0 Ki disk0s7
8: Apple_Patches 256.0 Ki disk0s8
9: Apple_HFS Joe 57.1 Gi disk0s10
/dev/disk1
#: TYPE NAME SIZE IDENTIFIER
0: Apple partitionscheme *10.0 Mi disk1
1: Apple partitionmap 31.5 Ki disk1s1
2: Apple_HFS me 10.0 Mi disk1s2
doug-penningtons-power-mac-g4:Desktop dougp$ diskutil partitionDisk disk1 2 HFS+ leroy 5M HFS+ madge 5M
Started partitioning on disk disk1
Creating partition map
Formatting disk1s2 as Mac OS Extended with name leroy
Formatting disk1s3 as Mac OS Extended with name madge
[ + 0%..10%..20%..30%..40%..50%..60%..70%..80%..90%..100% ]
Finished partitioning on disk disk1
/dev/disk1
#: TYPE NAME SIZE IDENTIFIER
0: Apple partitionscheme *10.0 Mi disk1
1: Apple partitionmap 31.5 Ki disk1s1
2: Apple_HFS leroy 5.0 Mi disk1s2
3: Apple_HFS madge 5.0 Mi disk1s3

Message was edited by: doug pennington

Jul 21, 2010 12:58 PM in response to doug pennington

Hi Doug,

thank you very much.

this works, but I did hope of a better way.

Now, take for example this as scenario.

App create a diskImage, put some secure data on it from other sources ( web, keyboard and third party tool ). And will be used every time the app restarts.

With the information I do have now, it needs to do the following steps.

App starts
If not exists - Create a dmg file with no partitions but with encryption 128bit and passw.
Attach that dmg.
Use diskutil to format that dmg in partitions with diff filesystems.
unmount that dmg
Open dmg with hdiutil attach
If empty, fill it with data and use it.

diskutil is not asking for a password, so everybody can format that dmg when they found it in the system. It should be read/writable

Is there a better way to protect the dmg and keep it out of sight?

Thanks again

Jul 22, 2010 11:00 AM in response to Obj-D

Ok. Here's what I got. The best thing, I believe is for you to try this script(in Script Editor & save as an application) and see what you think. There seems to me, to be a stop issue for adding files. Just see what you think. It's got encryption(.dmg).

do shell script "hdiutil create -encryption -layout SPUD -size 10m -fs HFS+ -agentpass -volname you you.dmg"
do shell script "hdiutil attach you.dmg"
do shell script " diskutil partitionDisk disk1 2 HFS+ gordy 5M HFS+ helen 5M"
do shell script "hdiutil unmount /Volumes/gordy"
do shell script "hdiutil unmount /Volumes/helen"
do shell script "hdiutil attach you.dmg"

User uploaded file

Message was edited by: doug pennington

Jul 23, 2010 1:09 AM in response to doug pennington

Hi Doug,

again thank you.

I dont use applecript but bash script kickstarted with NSTask because I have to transfer info from one line to another.
Using your lines as an example I use some output parsing from one line to the next line for input.
We can't assume that the disk will be disk1.

I want that my app is the only one that can write to that image, I use a generated password and do,


passw="passw_generated"
echo $passw | hdiutil create -encryption -layout SPUD -size 10m -fs HFS+ -volname you2 you2.dmg

but as the man page reads again, I should use -plist to use info from one party to the other, its more complex for me right now.
I notice that keys are not always available.

Is there a command that do parsing for this kind of situations, or should I stay with things like

hdiutil code | grep '/dmg.' | awk '{ print $3 }'


for now users can do what they want, guess that I should go using a cert and a different created owner and put that in charge as dmg owner. BTW, the app will have a uninstall option.

Jul 24, 2010 1:02 PM in response to doug pennington

Using the - after xmllint works so far like


echo "<?xml version='1.0' encoding='UTF-8'?>
<insertion>
<mytag>123</mytag>
</insertion>" | xmllint -

but I want to use the --shell argument in xmllint
So can I use something like
echo cat /begin mytag/endmytag | xmllint -shell - {code}

and still add info to stdin of xmllint?

any idea how to do that?

Jul 25, 2010 7:27 AM in response to Obj-D

I tried the shell arg. w/xmllint but it doesn't do anything different than with no shell arg.. this is just a startup lagent posted. A test.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.dougp.ohmy</string>
<key>ProgramArguments</key>
<array>
<string>xmllint --shell --/Users/dougp/Desktop/aquiz</string>
<string>open</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

aquiz is an executable containing the code as in the AppleScript above. But the code is bash. Running the code outside the executable container is a failure.
And this is what I get with any echo and cat:
cat com.dougp.ohmy.plist | xmllint --noout --valid - echo $?
I/O error : failed to load external entity "echo"
I/O error : failed to load external entity "0"
and
cat com.dougp.ohmy.plist | xmllint --shell --/Users/dougp/Desktop/aquiz /Users/dougp/Desktop/righthere.txt
Unknown option --/Users/dougp/Desktop/aquiz
Not sure if any of this even helps you.

Jul 26, 2010 10:59 AM in response to Obj-D

While I haven't tried this, you can run an applescript script like any other unix script. Place the following code in a text document and chmod. See link for details.

#!/usr/bin/osascript

(*
Also starting in Mac OX X v10.5, AppleScript allows use of the # symbol as a comment-to-end-of-line token (the traditional double hyphen (--) is also still supported). This means that you can make a plain AppleScript script into a Unix executable by beginning it with the following line and giving it execute permission.

#!/usr/bin/osascript

http://developer.apple.com/mac/library/documentation/AppleScript/Conceptual/Appl eScriptX/Concepts/work_with_as.html
*)

do shell script "hdiutil create -encryption -layout SPUD -size 10m -fs HFS+ -agentpass -volname you you.dmg"
do shell script "hdiutil attach you.dmg"
do shell script " diskutil partitionDisk disk1 2 HFS+ gordy 5M HFS+ helen 5M"
do shell script "hdiutil unmount /Volumes/gordy"
do shell script "hdiutil unmount /Volumes/helen"
do shell script "hdiutil attach you.dmg"

Jul 26, 2010 3:33 PM in response to rccharles

Thank you for your reply.

But what you give me is not what I need.

What I need now is how to communicate between the lines and parse that information.

E.g
hdiutil attach -plist you.dmg
gives a plist back with the disk number like disk5
that disk5 I do need that in the next line
diskutil partitionDisk disk5 2 HFS+ gordy 5M HFS+ helen 5M.

I want to use xmllint for that parsing
.

xmllint accepts xml from memory using the - option in xmllint
xmllint -

However to get the right key I can use in shell mode
echo cat /head/key | xmllint --shell

But how can I use the -shel option at the same time as the - option?

If I use applescript or bash script with NSTask ( cocoa ) I have to transfer the 'in between values' from bash to applescript and back to applescript or in the other case between NSTask to bash and back to NSTask etc.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

hdiutil and creation of more then one partition in a dmg and sparse image?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.