Tag Archives: dmg

MacOSX command line tricks

Here's a list of MacOSX commands I had to search for all over the internet because I needed to use them lately and I'm sure I'm going to forget since I'm not a big OSX user. So here they are for when I'll need them again ... 🙂

In linux when you want to know which ports are opened and what applications listen on those ports you use netstat -lnp
In MacOSX you get the listening ports with this:

  1. lsof -i |grep LISTEN

Want to see what system call am application is making use strace, for MacOSX thats:

  1. dtruss

Here's how to install an application that comes packaged in a .dmg:

  1. hdiutil attach App.dmg
  2. installer -package /Volumes/App/App.pkg -target /Volumes/MainDisk
  3.  

uninstall a package

  1.  
  2. lsbom -fls /private/var/db/receipts/package.name.bom|tr '\n' '\0' |xargs -0 rm
  3. rm /private/var/db/receipts/package.name.*
  4.  

pidof required by some mysql scripts

  1.  
  2. #!/bin/sh
  3. ps axc|awk "{if (\$5==\"$1\") print \$1}";
  4.  

remount with noatime

  1. mount -u -o noatime /dev/disk0s2 /Volumes/HD2

More to come ...

How to create a dmg image

In a previous post I showed you how to mount a .dmg image from the command line.

Have you ever wondered how you can create such an image? Continue reading if you want to know.

Let's assume you want to create an image with a size of 10Mb that is formatted with a case sensitive HFS+ filesystem, with a Volume name Test stored in a file with the name Test.dmg.
Here is the command line you have to type in the shell:

  1. hdiutil create -size 10m -fs "Case-sensitive HFS+" -volname Test Test.dmg

If you want to put files on it you have to attach it first:

  1. hdiutil attach Test.dmg

Or you could just add -attach to the list of parameters of the hdiutil command and it will also attach it after it creates it:

  1. hdiutil create -size 10m -fs "Case-sensitive HFS+" -volname Test -attach Test.dmg

Now you can copy your files to /Volumes/Test and when you're done you can detach the image in case you want to transfer/copy/move it:

  1. hdiutil detach /Volumes/Test

If you want a quick way to create an image from the contents of a folder you can use something like this:

  1. hdiutil create -fs "Case-sensitive HFS+" -volname Test -srcfolder /path/to/source/folder Test.dmg

With that you can also specify a format for the image like compressed or read-only images.
Note that in this case I have not used that -size specifier anymore because the image will be as large as the contents of the source folder.

hdutil create --help for more details about image formats encryption and other goodies 🙂

Mount .dmg images from command line

DMG images are the way that a lot of MacOSX binary packages are distributed.  They are somehow like virtual hard disk images or .iso images that you can just mount with a simple double click if you have access to the gui.

But how do you do that from the command line?

quick answer:

  1. hdiutil attach  image.dmg

and the image should now be mounted somewhere in /Volumes

The hdiutil is a tool used to manipulate such disk images. It can do a lot more then just mount the images. It can even burn  them to an optical media, convert them to an iso  and some other formats , even compress them using gzip or bzip2 .