Page 1 of 1
How to create the macos BaseSystem.dmg from scratch?
Posted: Tue Jul 02, 2024 8:03 am
by Princekin
Hi:
I learning xnu from the
https://github.com/thenickdude/OSX-KVM and
https://github.com/PureDarwin/PureDarwin, I now write a UEFI boot for the
https://github.com/PureDarwin/PureDarwin project, base the OSX-KVM project, I can run the BaseSystem.dmg which contain the macos system with qemu success, I would like to build BaseSystem.dmg from scratch so that I can understand its principles and subsequent modifications, but I have no idea where to start. Any help is greatly appreciated!
Code: Select all
qemu-system-x86_64 -accel hvf -m 4096 -cpu Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check -machine q35 -usb -device usb-kbd -device usb-tablet -smp 4,cores=2,sockets=1 -device usb-ehci,id=ehci -device nec-usb-xhci,id=xhci -global nec-usb-xhci.msi=off -device isa-applesmc,osk='ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc' -drive if=pflash,format=raw,readonly=on,file=././OVMF_CODE.fd -smbios type=2 -device ich9-intel-hda -device hda-duplex -device ich9-ahci,id=sata -drive file=./OpenCore/OpenCore-master.iso,if=none,id=OpenCoreBoot,format=raw, -device ide-hd,bus=sata.2,drive=OpenCoreBoot -device ide-hd,bus=sata.3,drive=InstallMedia -drive id=InstallMedia,if=none,file=./BaseSystem.img,format=raw -drive id=MacHDD,if=none,file=./mac_hdd_ng.img,format=qcow2 -device ide-hd,bus=sata.4,drive=MacHDD -netdev user,id=net0 -serial stdio -device vmware-svga -debugcon file:debug.log -global isa-debugcon.iobase=0x402
Re: How to create the macos BaseSystem.dmg from scratch?
Posted: Wed Jul 03, 2024 3:57 am
by Princekin
here is the contents of the BaseSystem.dmg:
0.MBR 1.Primary GPT Header 2.Primary GPT Table 3.free 4.hfs 5.free 6.Backup GPT Table 7.Backup GPT Header
How to recreate the macos BaseSystem.dmg from scratch?
Re: How to create the macos BaseSystem.dmg from scratch?
Posted: Wed Jul 03, 2024 5:25 am
by iansjack
This is such a specialised subject that I think you would get more useful answers on one of the dedicated web resources. For example:
https://www.reddit.com/r/PureDarwin/
TBH, I’m not even clear what you are asking. Do you want to build the XNU kernel (instructions on the PureDarwin web site) or are you just asking about the layout of the .dmg image?
Re: How to create the macos BaseSystem.dmg from scratch?
Posted: Wed Jul 03, 2024 8:30 am
by Princekin
I'm very sorry for the misunderstanding.
I use the
https://github.com/thenickdude/OSX-KVM project, which can run macos system using qemu. The operating system is in BaseSystem.dmg, which is downloaded from the apple official website. The command line is
BaseSystem.dmg->BaseSystem.img
Code: Select all
dmg2img -i BaseSystem.dmg BaseSystem.img
run BaseSystem.img on qemu
Code: Select all
qemu-system-x86_64 -accel hvf -m 4096 -cpu Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check -machine q35 -usb -device usb-kbd -device usb-tablet -smp 4,cores=2,sockets=1 -device usb-ehci,id=ehci -device nec-usb-xhci,id=xhci -global nec-usb-xhci.msi=off -device isa-applesmc,osk='ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc' -drive if=pflash,format=raw,readonly=on,file=././OVMF_CODE.fd -smbios type=2 -device ich9-intel-hda -device hda-duplex -device ich9-ahci,id=sata -drive file=./OpenCore/OpenCore-master.iso,if=none,id=OpenCoreBoot,format=raw, -device ide-hd,bus=sata.2,drive=OpenCoreBoot -device ide-hd,bus=sata.3,drive=InstallMedia -drive id=InstallMedia,if=none,file=./BaseSystem.img,format=raw -drive id=MacHDD,if=none,file=./mac_hdd_ng.img,format=qcow2 -device ide-hd,bus=sata.4,drive=MacHDD -netdev user,id=net0 -serial stdio -device vmware-svga -debugcon file:debug.log -global isa-debugcon.iobase=0x402
If I have the necessary files and folders for macos system, such as Applications, etc
, private, Library, sbin, System, tmp, Volumes, usr, bin, var, dev, System/Library/CoreServices/boot.efi, how can I recreate a BaseSystem.dmg myself with the same functions as the one downloaded from the apple official website?
Re: How to create the macos BaseSystem.dmg from scratch?
Posted: Wed Jul 03, 2024 9:05 am
by iansjack
Two points:
1. Why would you want to recreate what you have already downloaded from Apple?
2. I'm not sure of the legality of what you are doing. Apple's .dmg files are only licensed for use on a Macintosh computer. And if you are using a Macintosh, just use the downloaded image as is.
I don't really see your question as being related to OS Development.
Re: How to create the macos BaseSystem.dmg from scratch?
Posted: Wed Jul 03, 2024 4:58 pm
by Princekin
1.for the first point:
I recreated it from scratch to learn how to create a Basesystem.dmg so that I can create a Basesystem.dmg for the puredarwin project kernel, so that I can use qemu and opencore in OSX-KVM to start the Basesystem.dmg, so that I can debug the xnu kernel in the Basesystem.dmg for learning.
Re: How to create the macos BaseSystem.dmg from scratch?
Posted: Wed Jul 03, 2024 4:59 pm
by Princekin
It does not have to be named BaseSystem.dmg, it can be test.dmg. The important thing is that opencore in qemu can effectively recognize it and bootload and start it.
Re: How to create the macos BaseSystem.dmg from scratch?
Posted: Wed Jul 03, 2024 5:07 pm
by Princekin
Below are the partitions of Basesystem.dmg, I don't know how to create these partitions for a new blank dmg so that opencore in qemu can recognize it
Code: Select all
lee@Princekin-MacbookPro:~|⇒ dmg2img -l -v /Users/lee/Desktop/Computer_Systems/Macos/OSX-KVM/BaseSystem.dmg
dmg2img v1.6.7 (c) vu1tur ([email protected])
/Users/lee/Desktop/Computer_Systems/Macos/OSX-KVM/BaseSystem.dmg --> (partition list)
reading property list, 44376 bytes from address 486174238 ...
partition 0: begin=203, size=430, decoded=284
Protective Master Boot Record (MBR : 0)
partition 1: begin=948, size=430, decoded=284
GPT Header (Primary GPT Header : 1)
partition 2: begin=1695, size=430, decoded=284
GPT Partition Data (Primary GPT Table : 2)
partition 3: begin=2424, size=430, decoded=284
(Apple_Free : 3)
partition 4: begin=3137, size=34763, decoded=23404
disk image (Apple_HFS : 4)
partition 5: begin=38183, size=430, decoded=284
(Apple_Free : 5)
partition 6: begin=38911, size=430, decoded=284
GPT Partition Data (Backup GPT Table : 6)
partition 7: begin=39656, size=430, decoded=284
GPT Header (Backup GPT Header : 7)
Re: How to create the macos BaseSystem.dmg from scratch?
Posted: Wed Jul 03, 2024 11:30 pm
by iansjack
You can create and partition .dmg disk images using Disk Utility on an Apple Mac.
Re: How to create the macos BaseSystem.dmg from scratch?
Posted: Thu Jul 04, 2024 3:40 am
by Princekin
Thank you for your reply. Creating and partitioning .dmg disk images using Disk Utility on an Apple Mac is just the first step. There is still a lot to do to create a dmg similar to Basesystem.dmg. I can't find any information. If you can provide relevant information, it will be greatly appreciated.
Re: How to create the macos BaseSystem.dmg from scratch?
Posted: Thu Jul 04, 2024 4:40 am
by iansjack