0

I have a raw disk file as bellow

$fdisk -l Monterey.img

Disk Monterey.img: 14 GiB, 15032385536 bytes, 29360128 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: B0853EBC-902A-41B6-8BEB-C533A09C0376

Device Start End Sectors Size Type Monterey.img1 40 409639 409600 200M EFI System Monterey.img2 409640 29097943 28688304 13,7G Apple HFS/HFS+

It has 2 partitions, 1st for EFI (200MB), 2nd for MacOS installer data

And I have a SSD disk (GUIID type formatted)

~$ lsblk
sda           8:0    0 447,1G  0 disk 
├─sda1        8:1    0   190M  0 part 
├─sda2        8:2    0 152,6G  0 part /mnt/sda2
├─sda3        8:3    0    96M  0 part 
├─sda4        8:4    0   9,6G  0 part 
├─sda5        8:5    0  15,5G  0 part 
├─sda6        8:6    0  15,5G  0 part 
├─sda7        8:7    0 156,3G  0 part 
└─sda8        8:8    0    97G  0 part /media/minh/M2

I want to clone the 2nd partitions from Monterey.img to sda6 (physical partition of internal SSD),

I have tried with

$sudo dd if=Monterey.img of=/dev/sda6

29360128+0 records in 29360128+0 records out 15032385536 bytes (15 GB, 14 GiB) copied, 253,909 s, 59,2 MB/s

but the result report that unknown type , while other HFS+ partitions are visible and accessible.

Result disk:

Result disk

If the source disk file type is DMG, it can be cloned by DMG2IMG command as below:

$sudo dmg2img -p 2 BaseSystem.dmg /dev/sda6

How can I do that for a raw img type ?

karel
  • 114,770
MinhNV
  • 3

1 Answers1

1

losetup + dd can do it.

1. find first unused loop device

losetup -f

result for example:

/dev/loop0

2. attach Monterey.img to loop0

losetup /dev/loop0 Monterey.img
partprobe /dev/loop0
lsblk

3. clone

dd if=/dev/loop0p2 of=/dev/sda6
bin456789
  • 148
  • Thanks very much, It can clone to the physical partition, it can show the partition label and type , but the content is unreadable, error when mounting: "Error mounting /dev/sda6 at /media/minh/Install macOS Monterey: wrong fs type, bad option, bad super block on /dev/sda6, missing codepage or helper program, or other error (udisks-error-quark, 0) ". Does it need to matter size of destination partition must exact same as in RAW img file (current destination is large than image). – MinhNV Mar 02 '24 at 03:36
  • https://askubuntu.com/questions/332315/how-to-read-and-write-hfs-journaled-external-hdd-in-ubuntu-without-access-to-os – bin456789 Mar 02 '24 at 12:50
  • My machine install hfsprogs already, others HFS+ is readable , only the new one is unable to read. After using dd command to write sda, it shows label and type okay, but unable to boot OSX. – MinhNV Mar 02 '24 at 13:08
  • Try mount /dev/loop0p2. If works, /dev/sda6 should works too – bin456789 Mar 03 '24 at 00:31
  • the loop is work fine, but the sda6 is not, Do I need to update partition table info or something like that, because the size of sda6 is currently larger than the loop – MinhNV Mar 03 '24 at 03:43
  • try mount /dev/sda6 -o sizelimit=14688411648 /mnt – bin456789 Mar 03 '24 at 15:26
  • I changed the destination partition sda3: sudo mount /dev/sda3 -o sizelimit=14688411648 /mnt/sda3 It mount okay, but error during boot macOS from that partition – MinhNV Mar 04 '24 at 16:03
  • maybe the size of destination partition should be same as origin. Or the Partition type GUID should be same. Which is in Partition Table. – bin456789 Mar 05 '24 at 04:06