0

I have a macOS dmg file.. BaseSystem.dmg. It is compressed and contains various hfs partitions..

# file BaseSystem.dmg 
BaseSystem.dmg: zlib compressed data

What I want to do
I want to extract just the 4.hfs partition file. But I cannot.
This is possible on Windows using the Boot Disk Utility tool as demonstrated here.

Here is what I tried
If I use dmg2img like this...

flex@flex-ubuntu:~/Documents/MacOS$ dmg2img BaseSystem.dmg 

dmg2img v1.6.7 (c) vu1tur (to@vu1tur.eu.org)

BaseSystem.dmg --> BaseSystem.img


decompressing:
opening partition 0 ...             100.00%  ok
opening partition 1 ...             100.00%  ok
opening partition 2 ...             100.00%  ok
opening partition 3 ...             100.00%  ok
opening partition 4 ...             100.00%  ok
opening partition 5 ...             100.00%  ok
opening partition 6 ...             100.00%  ok
opening partition 7 ...             100.00%  ok

Archive successfully decompressed as BaseSystem.img

If I now try to mount BaseSystem.img..

$ sudo mount -o loop -t hfsplus BaseSystem.img /mnt/macimage
mount: /mnt/macimage: wrong fs type, bad option, bad superblock on /dev/loop7, missing codepage or helper program, or other error.

So that command does not mount it. This commands returns a single loopback device:
# sudo losetup -P -f --show BaseSystem.img
Which I CAN mount like this:
# sudo mount /dev/loop8p1 /mnt/macimage/

But what I want is to just extract the 4.hfs partition file?!

If I look at the properties of BaseSystem.img...

# file BaseSystem.img
BaseSystem.img: DOS/MBR boot sector; partition 1 : ID=0xee, start-CHS (0x3ff,254,63), end-CHS (0x3ff,254,63), startsector 1, 4176871 sectors, extended partition table (last)

From Ubuntu Terminal: # 7z l BaseSystem.dmg I get...

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_GB.UTF-8,Utf16=on,HugeFiles=on,64 bits,8 CPUs Intel(R) Core(TM)

Scanning the drive for archives:
1 file, 498625205 bytes (476 MiB)

Listing archive: BaseSystem.dmg

--
Path = BaseSystem.dmg
Type = Dmg
Physical Size = 498625205
Method = Copy Zero2 ZLIB CRC
Blocks = 594
----
Path = 4.hfs
Size = 2004299776
Packed Size = 498579443
Comment = disk image (Apple_HFS : 4)
Method = Copy Zero2 ZLIB CRC
--
Path = 4.hfs
Type = HFS
Physical Size = 2004299776
Method = HFS+
Cluster Size = 4096
Free Space = 678445056
Created = 2020-10-30 08:13:26
Modified = 2020-10-30 16:31:38

How can I extract just the file 4.hfs?

When I run this command: # 7z x BaseSystem.dmg it extracts the entire dmg file to give a directory tree of all the files in the dmg file. But I only want to extract a single file out of the dmg file: 4.hfs.

If I run this command: 7z x BaseSystem.dmg 4.hfs I get...

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_GB.UTF-8,Utf16=on,HugeFiles=on,64 bits,8 CPUs Intel(R) Core(TM)

Scanning the drive for archives:
1 file, 498625205 bytes (476 MiB)

Extracting archive: BaseSystem.dmg
--            
Path = BaseSystem.dmg
Type = Dmg
Physical Size = 498625205
Method = Copy Zero2 ZLIB CRC
Blocks = 594
----
Path = 4.hfs
Size = 2004299776
Packed Size = 498579443
Comment = disk image (Apple_HFS : 4)
Method = Copy Zero2 ZLIB CRC
--
Path = 4.hfs
Type = HFS
Physical Size = 2004299776
Method = HFS+
Cluster Size = 4096
Free Space = 678445056
Created = 2020-10-30 08:13:26
Modified = 2020-10-30 16:31:38


No files to process
Everything is Ok

Files: 0
Size:       0
Compressed: 498625205

But then nothing is output in the folder where I would expect 4.hfs to appear.

What am I doing wrong? Is it maybe not possible on Linux?

0

I found that dmg2img and 7z can both extract just a partition from a dmg file.

Using dmg2img we can see the contents of the dmg file:

# dmg2img -l BaseSystem.dmg 

dmg2img v1.6.7 (c) vu1tur (to@vu1tur.eu.org)

BaseSystem.dmg --> (partition list)

partition 0: Protective Master Boot Record (MBR : 0)
partition 1: GPT Header (Primary GPT Header : 1)
partition 2: GPT Partition Data (Primary GPT Table : 2)
partition 3:  (Apple_Free : 3)
partition 4: disk image (Apple_HFS : 4)
partition 5:  (Apple_Free : 5)
partition 6: GPT Partition Data (Backup GPT Table : 6)
partition 7: GPT Header (Backup GPT Header : 7)

Using dmg2img v1.6.7

This command extracts the 4.hfs partition:

# dmg2img -p 4 -i BaseSystem.dmg -o 4.hfs

Using 7z

In 7-Zip [64] 9.20 you can use this command:

7z e BaseSystem.dmg 4.hfs

In 7-Zip [64] 16.02 you need to use this command:

7z e -t* BaseSystem.dmg 4.hfs

The -t* is needed or else in this version of 7z it will not extract to just one level deep but instead it will extract everything down to files and folders.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.