Tip to install NetBSD/macppc in qemu-system-ppc reddit / BSD ---------------------------------------------------------------------- Kernigh · 2018-11-27 04:31 This is your invitation to try NetBSD/macppc in an emulator. I was never able to do this until now. You will need qemu-system-ppc and about 3G of disk space. I used QEMU 3.0.0. I am introducing ways to configure devices in QEMU and to install NetBSD's bootloader. NetBSD will run better than Debian. **Step 1:** Visit [https://cdn.netbsd.org/pub/NetBSD/images/](https:// cdn.netbsd.org/pub/NetBSD/images/) and fetch NetBSD-8.0-macppc.iso or the latest version. **Step 2:** Create a virtual hard disk. I allow my qcow2 disk to grow to 50G, but 5G might be big enough. $ qemu-img create -f qcow2 nep.qcow2 50G **Step 3:** Write a shell script to start the emulator. Some of the default devices are bad, so I introduce different ones. The default ADB keyboard can miss my keys; I use `usb-kbd`. The default NE2000 Ethernet is too slow in NetBSD; I use `model=e1000`. I also like to add a `usb-tablet` (so the emulator window doesn't trap the mouse). I am forwarding host port 5428 to guest port 22 (so I can ssh into the guest; I use ports near 5432). I use 1024M = 1G of virtual RAM. The bootloader will be at `hd:,ofwboot.xcf;1`. $ cat boot #!/bin/sh cd "$(dirname "$0")" exec qemu-system-ppc -m 1024 \ -nic user,model=e1000,hostfwd=tcp:127.0.0.1:5428-:22 \ -usb -device usb-kbd -device usb-tablet \ -prom-env 'boot-device=hd:,ofwboot.xcf;1' \ -hda nep.qcow2 "$@" $ chmod +x boot **Step 4:** Start the emulator with the virtual CD. $ ./boot -cdrom NetBSD-8.0-macppc.iso **Step 5:** The emulator fails to boot the hard disk. In the emulator's Open Firmware, type > `boot cd:,ofwboot.xcf` to boot the CD. Wait for it to boot, then start the installer and choose a language (like English), then request a shell with "Utility menu" and "Run /bin/sh". Need the shell to make an Apple partition map for a New World Macintosh (like the iMac). The installer would make a disklabel for an Old World Mac, but that doesn't work in QEMU. **Step 6:** In the shell, run # `pdisk /dev/rwd0` to make the Apple partition map. Use the commands `?` for help and `p` to print the partitions. Need a small "Apple\_HFS" partition for the bootloader; I made a 1M partition. Need some partitions for NetBSD; I made a 2G swap partition "b" and filled the free space with a root partition "a". The partitions may have any names, so I named them "Boot" and "Swap" and "Root". My command sequence was * `i` to initialize a new partition map; * `C` (uppercase) to create HFS boot, first block `2p`, length `1m`, name `Boot`, type `Apple_HFS`; * `c` (lowercase) to create NetBSD swap, first block `3p`, length `2g`, name `Swap`, bzb `b`; * `c` (lowercase) to create NetBSD root, first block `4p`, length `4p`, name `Root`, bzb `a`; * `w` to write the map, confirm `y`; * `q` to quit pdisk. This is my partition map: Partition map (with 512 byte blocks) on '/dev/rwd0' #: type name length base ( size ) 1: Apple_partition_map Apple 63 @ 1 2: Apple_HFS Boot 2048 @ 64 ( 1.0M) 3: Apple_UNIX_SVR2 Swap 4194304 @ 2112 ( 2.0G) S1 SFS k0 (swap) 4: Apple_UNIX_SVR2 Root 100661184 @ 4196416 ( 48.0G) S0 RUFS k0 / **Step 7:** Back in the shell, run # `disklabel wd0` to check the partition letters. There is no disklabel on the disk, so NetBSD turns the Apple partition map into a disklabel. Need the letter of the HFS partition; I have it as letter "d". # size offset fstype [fsize bsize cpg/sgs] a: 100661184 4196416 4.2BSD 2048 16384 0 # (Cyl. 4163*- 104025*) b: 4194304 2112 swap # (Cyl. 2*- 4163*) c: 104857600 0 unused 0 0 # (Cyl. 0 - 104025*) d: 2048 64 HFS # (Cyl. 0*- 2*) **Step 8:** \# `exit` the shell, "Exit" the utility menu, and do "Install NetBSD to hard disk". Must tell the installer to "Use existing partition sizes". (This trick comes from [Sevan Janiyan's NetBSD/macppc quickstart](https://mail-index.netbsd.org/port- macppc/2017/07/07/msg002425.html).) *Must not edit the partitions in the installer, because any edit would destroy the Apple partition map!* "Use existing partition sizes" and install from "CD-ROM". I want a "Full installation", but a "Minimal installation" also works. Wait for the installer to newfs the disk and install the sets. This is the only long wait during the install. **Step 9:** The installer asks you to configure the system. *Don't configure the network, because the installer has no DHCP client!* Also don't set up binary packages or pkgsrc without the network. I chose my timezone, set my root password, enabled sshd, and added a user (in the wheel group). **Step 10:** The disk is still missing the bootloader, but I introduce the trick to install it. Request another shell with "Utility menu" and "Run /bin/sh", then mount the installed system and chroot into it. # mount /dev/wd0a /mnt # chroot /mnt **Step 11:** This is optional, but I did # `vi /etc/rc.conf` to set the hostname and enable the DHCP client. (# `man vi` if you don't know how to vi.) I named my system "nep" (short for NetBSD powerpc). I added 2 lines near my sshd line, so I had hostname=nep dhcpcd=YES sshd=YES **Step 12:** Make an ISO 9660 filesystem containing the bootloader "ofwboot.xcf". The trick to [boot from ISO 9660](https://schmonz.com/2006/06/29/installing-netbsd-on-powerpc-mac- mini/) was known, but I introduce this trick to chroot and makefs. I don't need to copy the .iso from another system, because I make the .iso in the installer's shell. # mkdir /tmp/boot # cp /usr/mdec/ofwboot.xcf /tmp/boot # makefs -t cd9660 /tmp/boot.iso /tmp/boot **Step 13:** Check with # `ls -lh /tmp/boot.iso` that the .iso is smaller than the HFS partition. (In my case, 686K < 1M.) Check with # `disklabel wd0` for the letter of the HFS partition. Then copy the .iso to the HFS partition. This puts the bootloader at `hd:,ofwboot.xcf;1` because the firmware sees the version numbers on .iso files. # dd if=/tmp/boot.iso of=/dev/wd0d **Step 14:** Halt the system: # `halt -p` **Step 15:** Start the emulator without the CD: `$ ./boot` NetBSD/macppc should boot! (If you ever need the Open Firmware prompt, add `-prom-env 'auto-boot?=false'` to QEMU's arguments.) If you enabled dhcpcd and sshd, and forwarded host port 5428 to guest port 22, then `sftp -P 5428 localhost` and `ssh -p 5428 localhost` should work. For me, ssh is a better terminal than QEMU's window. To set up binary packages in NetBSD/macppc, look in [https://cdn.netbs d.org/pub/pkgsrc/packages/NetBSD/macppc](https://cdn.netbsd.org/pub/pk gsrc/packages/NetBSD/macppc) for packages. I found 8.0\_2018Q3 packages and installed pkgin with # pkg_add http://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD\ > /macppc/8.0_2018Q3/All/pkgin-0.11.6.tgz (I had an error with https, so I used http.) I followed the hints to edit my repositories.conf and update my package list. (https worked; https://.../8.0\_2018Q3/All/ is my repository.) Then I installed the binary package of perl. # vi /usr/pkg/etc/pkgin/repositories.conf # pkgin update # pkgin install perl **Why these 15 steps:** NetBSD/macppc is the only BSD that can run on an Old World Mac (before the iMac). The installer makes the partitions and bootloader for an Old World Mac. QEMU can run the Old World bootloader, but then the bootloader can't find a kernel. It is harder to put NetBSD/macppc on a New World Mac. The usual way is to dual-boot Mac OS and NetBSD. You would install Mac OS on an HFS partition and use Mac OS to put "ofwboot.xcf" on the same HFS partition. Then you run [pdisk(8)](http://netbsd.gw.com/cgi-bin/man- cgi?pdisk). The official [INSTALL 8 macppc](https://cdn.netbsd.org/pub /NetBSD/NetBSD-8.0/macppc/INSTALL.html) is obsolete and gives a difficult procedure, >From this shell prompt, you will do some of the steps that the normal install procedure runs automatically.... Run the **newfs** command on the `4.2BSD` partitions... Make an `fstab` file for your new system... It is easier to use [Sevan Janiyan's trick](https://mail- index.netbsd.org/port-macppc/2017/07/07/msg002425.html). You tell the installer to "Use existing partition sizes", so the installer runs newfs and makes the fstab. Open Firmware must run "ofwboot.xcf" but can't read NetBSD filesystems. Open Firmware can read HFS, but NetBSD's installer can't write HFS. The installer can write MS-DOS filesystems, and a real New World Mac's Open Firmware might read DOS, but QEMU's Open Firmware can't read DOS. I use ISO 9660 because the installed NetBSD has [makefs(8)](http://netbsd.gw.com/cgi-bin/man-cgi?makefs) and Open Firmware can read it. The partition type is "Apple\_HFS" because Apple partition maps never had a type for DOS or ISO 9660 filesystems, probably because DOS disks and CDs never had Apple partition maps. QEMU's default ADB keyboard has problems with both NetBSD and Debian. It misses my keystrokes, so I need to type slowly. I can't see my mistyped passwords, so I often fail to log in. `usb-kbd` is better. QEMU's default Ethernet is `model=ne2k_pci` and works well with Debian, but uses too much system cpu in NetBSD, so ssh is too slow. `model=rtl8139` is just as bad, and `model=sungem` freezes NetBSD, but `model=e1000` works with both NetBSD and Debian. **Why NetBSD runs better than Debian:** I have installed both NetBSD/macppc and Debian/powerpc in qemu-system-ppc. Now that I have the tricks to install NetBSD, I know that Debian is more difficult to install. NetBSD's installer has only one long wait (to run newfs and install sets), but Debian's installer has multiple long waits and needs my attention. Debian/powerpc is unofficial, with CD images in [h ttps://cdimage.debian.org/cdimage/ports/](https://cdimage.debian.org/c dimage/ports/) and packages in [https://www.ports.debian.org/](https://www.ports.debian.org/); but the current CD (Debian 10.0) can't find the package repository. The result was an incomplete system with no man(1) command! It wasn't easy to add the repository and install the missing packages. Debian's boot (using initrd and systemd) is slow. When NetBSD is finished booting, Debian is only mounting the root filesystem. Debian has a problem with random numbers: the kernel message `random: crng init done` is slow to appear, and ssh refuses connections (with a confusing error message) before that message appears. (It might help to move the mouse across QEMU's window.) NetBSD's [rnd(4)](http://netbsd.gw.com/cgi-bin/man-cgi?rnd) is better. ---------------------------------------------------------------------- jaypatelani · 2018-11-27 04:40 Also worth noting HAXM-qemu WIP being worked by kamil on NetBSD https://bsd.network/@sehnsucht/101140510655202699 ---------------------------------------------------------------------- E39M5S62 · 2018-11-27 05:39 Thanks for the very detailed writeup on this! There's a lot of great information in this post. ---------------------------------------------------------------------- johnklos · 2018-11-27 05:51 Awesome how-to! What is your performance like? ---------------------------------------------------------------------- Kernigh · 2018-11-27 23:36 The performance inside qemu-system-ppc seems to be worse than my real PowerBook G4; the emulator might be near a 400 MHz G3. I'm run qemu- system-ppc on a fast host, an AMD Phenom II X2 560 at 3315 MHz with OpenBSD/amd64. (This has 2 cores, but qemu-system-ppc seems to use 1 core.) The PowerBook has a (PowerPC G4) MPC7447A at 1333 MHz, but I run it at half speed (666 MHz) in OpenBSD/macppc. The half-speed PowerBook still seems to outrun the emulator. Here are runs of `openssl speed sha256` to compare. OpenBSD/amd64 on the AMD processor (3315 MHz): Doing sha256 for 3s on 16 size blocks: 7379037 sha256's in 3.01s Doing sha256 for 3s on 64 size blocks: 4158502 sha256's in 3.01s Doing sha256 for 3s on 256 size blocks: 1851870 sha256's in 3.01s Doing sha256 for 3s on 1024 size blocks: 494705 sha256's in 2.98s Doing sha256 for 3s on 8192 size blocks: 56884 sha256's in 3.00s ... The 'numbers' are in 1000s of bytes per second processed. type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes sha256 39224.12k 88419.98k 157501.24k 169992.59k 155331.24k OpenBSD/macppc on the real PowerPC G4 (666 MHz): Doing sha256 for 3s on 16 size blocks: 820249 sha256's in 2.99s Doing sha256 for 3s on 64 size blocks: 581444 sha256's in 3.01s Doing sha256 for 3s on 256 size blocks: 319933 sha256's in 3.03s Doing sha256 for 3s on 1024 size blocks: 115082 sha256's in 2.99s Doing sha256 for 3s on 8192 size blocks: 16401 sha256's in 3.03s ... The 'numbers' are in 1000s of bytes per second processed. type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes sha256 4389.29k 12362.93k 27030.64k 39412.70k 44342.24k NetBSD/macppc inside qemu-system-ppc on the AMD (3315 MHz): Doing sha256 for 3s on 16 size blocks: 592513 sha256's in 3.08s Doing sha256 for 3s on 64 size blocks: 389172 sha256's in 3.01s Doing sha256 for 3s on 256 size blocks: 193353 sha256's in 3.00s Doing sha256 for 3s on 1024 size blocks: 63116 sha256's in 3.00s Doing sha256 for 3s on 8192 size blocks: 8659 sha256's in 2.99s ... The 'numbers' are in 1000s of bytes per second processed. type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes sha256 3077.99k 8274.75k 16499.46k 21543.59k 23723.92k ---------------------------------------------------------------------- johnklos · 2018-11-28 10:08 It seems to be the case with many emulations that the fastest processors commonly available today don't quite emulate older hardware as fast as the actual hardware yet. Even a 50 MHz m68060 isn't definitively beat by a 4+ GHz Intel / AMD in all things when MMU emulation is required. Likewise, it's going to be many years before a PowerPC emulation can beat the fastest G4, much less the G5. Alpha CPUs are also many times faster than the fastest emulations. It does make accessibility much easier. A single core of a contemporary eight core AMD is usually easier to find than actual hardware, although PowerPC Mac minis are pretty darned small. I wish there were more options for tiny Alpha hardware... ---------------------------------------------------------------------- ander_bsd · 2018-11-30 18:43 Well, the last mainline Qemu with multithreaded TCG would close things up a but. ---------------------------------------------------------------------- jd723446 · 2018-12-01 06:02 OP, do you have a technical blog? If so, please put this there. ---------------------------------------------------------------------- bplipschitz · 2019-01-08 19:05 Thanks for this detailed write-up! This is so much less painful than when I installed NetBSD (4? 5?) on an old G3 years ago to run a database server. Qemu and this how-to allowed me to re-read some old backup tapes from that old machine that we couldn't read on our current PC hardware (because endianess). ---------------------------------------------------------------------- jack-bender · 2023-12-28 21:25 It's now 5 years later and this thread really helped me get NetBSD/macppc running on QEMU. Thanks a lot for the detailed instructions. Below is what I would add to guide someone wanting to install a newer NetBSD/macppc version like the current 9.3 (at the time of writing). **Step 6:** To have ample room I decided to make the Boot (Apple\_HFS) partition 16MB in size, not that it make a difference in practice because "ofwboot.xcf" still is less than 1MB in NetBSD/macppc 9.3, just to let anyone know it won't hurt. **Step 8:** With recent NetBSD/macppc versions (9.3 in my case), after selecting "Use existing partition sizes" it is necessary to edit the fields of the root partition because default values won't allow for an install and will instead cause errors of the kind "cannot write file \[...\], disk is full". Here are the root partition fields that worked for me: `type : FFSv2` `install : Yes` `newfs : Yes` `mount : Yes` `mount point : /` **Step 15:** Refer to [https://netbsd.org/docs/pkgsrc/using.html](https://netbsd.or g/docs/pkgsrc/using.html) for installation of pkgin and pkgsrc.