Creating multi-part DMG using the commandline

There have been times whereby it is necessary to create disk image files such that it can be placed unto smaller drives. Maybe you have a 8GB DMG file that needs to be placed into 2 4GB disk. This can be done over the command-line. The steps are as follows

  1. Create the initial disk image for the file and attach it
    sudo hdiutil create -srcfolder folder_to_image first_file.dmg -attach
  2. Take note of the attached device from the output that might look something like this
    /dev/disk2s2           Apple_HFS                         /Volumes/folder_to_image
  3. Create the multi-part DMG files using the following command line
    sudo hdiutil create -srcdevice /dev/disk2s2 -segmentSize 4g final_file.dmg

The output of this command will be the multiple DMG parts limited to 4GB with the extension of dmgpart. Clicking on the first DMG file will result in all the part files being formed together and mounted as one single volume.