Tag Archives: Emulation

Mac OS on 68k QEMU

Mac OS on 68k QEMU

UPDATE 31st July 2024 – This post has been updated to reflect more recent versions of QEMU m68k as I was notified that the instructions I had followed were out of date. The 68k specific patches have more recently been integrated into the main build and so it is no longer necessary to use the q800.upstream branch I originally used.

UPDATE 1st November 2024 – Last night I was able to build and run 68k QEMU on an 64bit ARM based PineBook Pro running Manjaro Linux. Manjaro uses yum instead of apt, so grabbing software was different, but all I needed to do was update installed software, then I installed the repository’s copy of qemu-system-m68k (a lazy way of getting most dependencies), then I had to install the build environment ninja. After that, everything worked exactly as described below, although compiling took quite a while. I haven’t benchmarked the system, but it feels like it runs pretty well. Mac OS 8 didn’t take too long to install. Given this, I would expect this software to be happy compiling on other ARM based Linux PCs and SBCs, such as the Raspberry Pi.

QEMU m68k Running Mac OS 8.1 on Manjaro-ARM (image)
QEMU m68k Running Mac OS 8.1 on Manjaro-ARM (click to view)

Introduction

I recently installed the 68k version of QEMU on Linux (Pop! OS) and struggled to find detailed step-by-step instructions by googling, so thought I’d upload some notes to help others. I suspect that part of what tripped me up is that previously, it was necessary to build from a branch and not the central source, which led me down the wrong path to to get the m68k variant of QEMU to build, but in truth building the main branch source now gets you to a working emulator (although not the copy in the Debian software repository). This is slightly muddied by the out of date threads that are returned as the primary results when you search for instructions on building QEMU for 68k on Linux.

Building m68k QEMU

My primary source for building qemu-system-m68k for Linux was here but ultimately I needed some guidance from a contributor to the project who saw my post and got in touch to point me in the right direction. I’m very appreciative of the time they took to help me on my way. This assumes you plan to run Classic Mac OS (between 7.1 and 8.1), and not AUX or anything more exotic.

Navigate to your home folder

> sudo apt update
> sudo apt-get build-dep qemu-system-misc ninja
> git clone https://gitlab.com/qemu-project/qemu.git
> cd qemu
> ./configure --target-list=m68k-softmmu --enable-gtk --enable-sdl --enable-slirp
> make -j4

I then copied the executables qemu-system-m68k and qemu-img from the build folder, into the folder I wanted to run them from.

Creating / Getting the Required Files

To run, you will need to generate two disk images, and a copy of the Quadra 800 ROM. Place the ROM in the same folder as the executables, and name it Quadra800.rom. I next used some of the instructions from here to work out how to generate the needed image files as follows. Run these two commands in the location you placed qemu-system-m68k and qemu-img previously.

> qemu-img create -f raw -o size=1G mainDisk.img 
> qemu-img create -f raw pram-macos.img 256b

On the first line, change “1G” to other values to change the image size from this example of 1 gigabyte.

Launching the Emulator for the First Time

The emulator “captures” the mouse (and keyboard) once you click in the window. To free the mouse, press Ctrl+Alt+g.

To initially format the disk image, you can use Drive Setup (Mac OS 8.x) or Apple HD SC Setup (7.6.1 and older) while booted from the OS installer CD. It is critical that the CD iso image you use has been properly created and includes the driver partitions and is bootable, otherwise you will just get a flashing question mark on a floppy disk icon. If you do not already have an image, you can grab one from the Macintosh Garden here (which is a direct link to download #6 (at time of writing) on this page), or from my own site here.

Rename the iso image as MacOS81.iso and place it in the same folder as qemu-system-m68k and qemu-img.

If you plan to run another version of Mac OS on the emulated computer, download a bootable iso image of that operating system, for example Mac OS 7.6.1, place it in the same folder and name it, for example, MacOS761.iso. In the following instructions I will assume that you are using a, 8.1 CD image to format the disk and install the operating system. If you plan to install another OS, use that disk image instead.

Boot the emulator from the Mac OS 8.1 CD image using the following command, all on one line :

> ./qemu-system-m68k -boot d -L pc-bios -M q800 -m 64 -bios Quadra800.rom -drive file=pram-macos.img,format=raw,if=mtd -device scsi-hd,scsi-id=0,drive=hd0 -drive file=mainDisk.img,media=disk,format=raw,if=none,id=hd0 -device scsi-cd,scsi-id=3,drive=cd0 -drive file=MacOS81.iso,media=cdrom,if=none,id=cd0

When you press return, you should get a QEMU window, hear your emulated Mac chime and see the boot process. Once the emulated computer reaches the desktop, open the CD, open the Utilities folder and then launch the Drive Setup application. If you are formatting the emulated hard disk using Mac OS 7.6.1 or older, skip to the section titled “Apple HD SC Setup” and then return to the section titled “Here”.

In Drive Setup, select the unformatted hard disk from the list, click the Initialize button, and then in the Initialize dialog box, click the Custom Setup… button, select “1 Partition” from the Partitioning Scheme popup menu, ensure the other popup menu says “Mac OS Standard” and not “Mac OS Extended” (if you plan to use the hard disk image with Mac OS 7.x), click OK, and lastly click Initialize. Once this is done, you can quit out of Drive Setup, and rename the hard disk you just formatted if you haven’t already. “Macintosh HD” is traditional. Once you’re done, you can install your operating system.

Here

To install an OS, navigate to the desktop. If you have just booted you will be there by default, otherwise if you are following these instructions and have just formatted your “hard disk” you may need to quit out of the formatting utility and close some Finder windows. Once you get to the desktop, open the CD and run the main installer application. Follow on-screen instructions to complete the install. If you’re unfamiliar with the process, the default settings should be just fine. Selecting Restart (if offered in a dialog box, or from the Special menu at the desktop) should bring you back up in your installed copy of Mac OS.

You can shutdown the emulated computer by selecting Shutdown from the Special menu while at the desktop.

If you wish to start QEMU again, but from a different CD image, for example a Mac OS 7.6.1 iso image we downloaded and called MacOS761.iso, enter and execute the following command, which is identical to the previous command, except the CD Image filename has been updated.

> ./qemu-system-m68k -boot d -L pc-bios -M q800 -m 64 -bios Quadra800.rom -drive file=pram-macos.img,format=raw,if=mtd -device scsi-hd,scsi-id=0,drive=hd0 -drive file=mainDisk.img,media=disk,format=raw,if=none,id=hd0 -device scsi-cd,scsi-id=3,drive=cd0 -drive file=MacOS761.iso,media=cdrom,if=none,id=cd0

Once you’re done, Shutdown and we’ll set up a simpler (less typing intensive) way of launching the emulator, as well as consider a couple of helpful customisations.

Create and edit a new bash script in the folder with qemu-syetem-m68k…

> touch launch68k.sh
> chmod +x launch68k.sh
> nano launch68k.sh

Paste (right-click, paste) in the following into the file you should have open for editing :

./qemu-system-m68k -boot d -L pc-bios -M q800 -m 64 -g 1152x870x8 \
    -bios Quadra800.rom \
    -drive file=pram-macos.img,format=raw,if=mtd \
    -device scsi-hd,scsi-id=0,drive=hd0 \
    -drive file=sharedharddisk.img,media=disk,format=raw,if=none,id=hd2 \
    -device scsi-cd,scsi-id=3,drive=cd0 \
    -drive file=/dev/cdrom,media=cdrom,if=none,id=cd0

On the first line “-g 1152x870x8″ sets the display to 1152 by 870 pixels (Apple’s 21” monitor resolution) at 256 colours (8bit). If you want to run the display at 640 by 480, or 800 by 600 at 24bit colour, delete the “-g 1152x870x8” text (move the cursor with the cursor keys in nano. The default display mode allows you to switch between 640×480 and 800×600 from the Monitors control panel within the emulated computer.

If your host computer has an optical drive, the last two lines set up the emulator to directly access disks put in that drive. If you do not have an optical drive, you may need to delete these last two lines.

Press Ctrl-x and when prompted, press “y” to exit and save changes.

Now, when you want to launch the emulator, you can run the bash script launch68k.sh, for example by navigating in the terminal to the folder, and then typing ./launch68k.sh.

Apple HD SC Setup

If you format the emulated hard disk using a Mac OS 7.6.1 or older version of System 7, you will need to use the formatting utility Apple HD SC Setup. This is because older versions of Drive Setup were exclusively for PowerPCs and / or formatting IDE hard disks (and we’re emulating a SCSI disk). While the process is pretty simple, an quirk I noticed while setting up my emulator was that Apple HD SC Setup only created a very small data partition on the emulated hard disk. This is simple to fix though.

Step 1

Launch Apple HD SC Setup, likely in the Utilities folder on the top level of the CD you have booted from. Select the SCSI ID of the emulated hard disk you want to format by clicking the Drive button, you most likely want “SCSI Device: 0”. Do not get this wrong or you could erase the data on whatever hard disk image you have mounted in your emulator.

Step 2

Click the Initialize button and wait. This takes quite a while.

Step 3

Click the Partition button, then click on the Customize button if available.

Step 4

If the disk utilisation graphic shows partitions taking up most of the disk, you’re good to quit out of the utility, but if like me, the data partition is only using a small portion of the disk and the remainder is grey half tone, select the partition and click remove.

Click towards the bottom of the grey area. In the dialog box that appears, select the option “Mac Volume” on the left, and then in the text field on the right hand side, enter a value (in K) that is about 1000 less than the maximum value quoted below the text field. Click OK once you’re happy. You should now have a small amount of grey between the disk driver and the data partition. Click Done.

Step 5

Quit Apple HD SC Setup and return to the heading “Hear” above, to install the operating system.

Getting Software onto the Emulator

At this point, if you have an optical drive, you should be able to install any software you own on original CDs. This only gets you so far though. I’ve actually been moving files onto the disk image using another emulator. Basilisk II allows access to the host file system and while QEMU isn’t compatible with my Basilisk II disk images, the QEMU image works fine in Basilisk II. Other emulators might also work in this fashion, such as the Infinite Mac website, SheepShaver and others.

Make sure you don’t accidentally launch both emulators at the same time or you will possibly cause issues and corruption.

Limiting Processor Usage

On my fairly elderly laptop, when I run QEMU it consumes 100% of two cores (from the OSes perspective, as hyperthreading is on this isn’t strictly correct). This is enough to either cause the fan to ramp up to an annoying level, or if I am running from the battery, significantly reduce battery life.

The truth is, I don’t actually offer all of the speed this offers me, so I decided to look into how I might best throttle the performance of m68k QEMU to reduce the CPU time it consumes at the cost of emulator performance. Ultimately, I settled on using the program cputool which I had to install, but was available from the Debian repositories so a simple apt get install cputool sorted that.

This solution isn’t perfect as it makes the emulated graphics redraw stuttery, but it is OK if you’re mainly typing and not playing games or drawing.

After installing cputool, I was able to make a new script to launch QEMU, that just called my existing script. What I ended up with was a bash script containing…

cputool -c 50 -- ./startqemu.sh

Where “startqemu.sh” was my existing start script, “50” is the percent of each core’s total time I’m allowing. QEMU m68k uses two threads, so with this setup, I see the total CPU usage by the emulator halved and visible as 50% usage on two cores.

The above method should probably work with other emulators that consume all of an available core or core’s resources regardless of whether it is needed or not.

Advantages and Disadvantages

I’m pretty pleased with this emulator, with the only slight disadvantages I’ve seen so far (since installing an up to date version) are that it runs slower than some other emulators, it is harder to install and transferring files between the host and emulator isn’t as trivial as in emulators that mount the host file system on the desktop by default. This plays off against much better stability and compatibility when compared to Basilisk II for example, which I have been mainly using lately. One big compatibility improvement is sound. For example, SoundEdit 16 was not usable on Basilisk II due to constant crashes.

The driving factor for me trying QEMU was a bug that manifests in Basilisk II when writing software in REALbasic – if I convert an integer into a string in my REALbasic program, I get an incorrect result. This does not happen on real hardware such as my Centris 650 or my PowerBook G3, and also does not happen in QEMU.

Further Work

At this point, I should probably look into better ways of transferring files into the emulator. I believe that network filesharing, either using netatalk or possibly FTP, would be a fairly simple thing to setup. I’ve not looked into mounting the host system within the emulated Mac, I’m told this is possible, and will add instructions here when I look into it.

Obsolete Comments

This post was originally made with respect to an older, unofficial, build of QEMU with which I had a number of issues. I’ve moved the old list of issues here so that if someone is searching for terms they contain, they will still find this guide.

Issues (some minor) I experienced with the development branch and thread detailing how to build on Linux…

  • Build instructions don’t mention all dependencies.
  • Could not run configure due to permission issues if you try in a location outside your home folder, specifically on a secondary partition in my instance (I haven’t tried this again with the latest source).
  • The emulator is debouncing double clicks on my computer so they only count as a single click. It is not possible to double click in the normal manner. -fixed-
  • Disk image compatibility is very picky and the emulator does not seem to work with existing disk images.
  • After generating a disk image using QEMU’s own tool, it will not format, or even show on the emulated SCSI bus in Mac OS until you format it in Mac OS 8.1. -fixed-
  • The man pages are exclusively about x86 PCs even when called in relation to the m68k executable.
  • Resolution support is limited, more limited than real hardware.
  • The SDL mode does not work on my computer and just results in a blank screen.
  • Installing from the Debian repositories results in a non-working executable.

The most frustrating of these issues have been entirely fixed in the newer version of qemu-system-m68k, although some of the minor issues are still present (and others I haven’t re-checked for at this point). I have marked items I’ve tested and found solved as “-fixed-“.

Creating a Custom Bootable Classic Mac OS CD from Linux

Creating a Custom Bootable Classic Mac OS CD from Linux

and possibly other operating systems, which I don’t have to hand

The following is a description of the process to easily create a HFS formatted disk image and burn it to a CD, suitable for use in a Macintosh computer running Mac OS 9.2.2 or older, assuming it has an operable CD drive. If your CD drive is struggling to read disks, cleaning its lens can help. I have some short instructions on how to do that here.

The instructions on actually generating an appropriately formatted ISO disk image ready to be burnt to a CD are universal, and apply equally to Linux, modern Mac OS and Windows, but these instructions provide Linux specific detail as it is the only OS I have on hand to test.

What You Will Need

Hardware

  • A computer running Linux (or another OS, but most of my guidance wont be directly applicable)
  • An optical drive capable of burning CDs
  • A blank CD-R
  • A vintage Macintosh running a version of the classic Mac OS, with a functional CD drive.

Software

  • A flavour of Linux, this page assumes a Debian family variant, such as Debian, Ubuntu, Mint or Pop!_OS (other operating systems can be used, but detailed instructions are not provided)
  • Basilisk II – a cross-platform Macintosh Emulator, a bootable disk image with required software (provided below)
  • A ROM image for the emulator, taken from a retro Macintosh you own, or at least equivalent to a machine you own.
  • K3b – CD burning software for Linux (other software may work, but detailed instructions are not provided))

Setting Up the Software

Installation

To install Basilisk II, run the command in a terminal…

sudo apt install basilisk2

To install K3b, run the command in a terminal…

sudo apt install k3b

Download this disk image which will be your main boot disk for the Basilisk II emulator, extract the contents from the ZIP and store it in a convenient location.

Obtain the required Macintosh ROM, from a Macintosh II series or Centris / Quadra ideally, but other ROMs are likely to work. I have been using a IIci ROM. Store it in a convenient location.

First Run of Basilisk II

01 Volumes
01 Volumes

After launching Basilisk II, you will be faced with the window shown above, without the two disks listed. To add these, first, click the “Add…” button, navigate to where you stored the disk image “Bernie.dsk” and select it. This already contains an operating system and the retro Mac software we’ll need to create a bootable CD. “WorkingVolume.dsk” is a second, empty, disk image that we will create now and which will be where we will collate and organise the CD we want to build. Click the “Create…” button and enter the following details for Size and the file name. Navigate to a convenient location to save, and then click “OK”. We now have a 650MB empty disk image in addition to our 1GB, bootable, disk image.

02 Creating Working Volume
02 Creating Working Volume

Within the “Graphics/Sound” tab I set the Width and Height to 640 and 480 respectively. These values suit me, but are not critical – for example you could set 1024 and 768 if you wanted a larger emulated display. Sound settings can be left at your installation’s defaults. In the “Memory/Misc” I set MacOS RAM Size to 32MB, Mac Model ID to Mac IIci, CPU Type to 68030 with FPU and selected a IIci ROM file using the “Browse…” button. With my setup, it was required that I selected “68030 with FPU” and not just “68030”, otherwise the emulated computer would not boot from my particular operating system.

Once you are happy, you can click the “Start” button, and you should be greeted with an emulated Macintosh booting very quickly. Once the startup sequence has completed, the first time only, you will be greeted by a dialogue box asking for you to format the empty “WorkingVolume”, 650MB disk image that you created. Name this disk whatever you want your CD to be called when it mounts on the desktop (after this first time, you will need to do this by renaming the volume on the desktop). Keep the format as the default “Macintosh 650 MB”. Click “Initialize”.

05 Format Working Volume
05 Format Working Volume

The new volume, in my instance called “WorkingVolume” will mount on the emulated desktop, along with “Bernie”, our boot volume and “Unix”. Unix is a link into the host computer’s file system which we will be using later to transfer our complete disk image back to the host for burning to a disk. Your window should look similar to the following.

06 Booted Bernie
06 Booted Bernie

Congratulations! You are now ready to start creating your custom bootable CD!

Creating Your Bootable CD

Use the emulator to fetch the various files you want to put on the CD. If you are on a computer that doesn’t natively support resource forks, such as Linux or a Windows PC, it is best to move any files onto the emulator in a protective container format such as a .bin file, later versions of .sit (SIT5) or some disk image formats. Some disk images can be “added” to the emulator as other emulated hard disks in the same way we added the “Bernie” disk above. Care must be taken as classic Mac OS files contain both a data and a resource fork. The resource fork is not usually recognised by other computer platforms and they are prone to “strip” the resource fork from a file. Doing so severely corrupts most Mac OS files, for example, 68k applications have all of their executable code in the resource fork and removing it… removes the application’s ability to do anything at all, irreparably. Assuming the files you are working with were correctly prepared in the first place (this is sadly more frequently an issue than it should be), extracting the archives / encoded files from within classic Mac OS itself is usually the best, although not only, solution.

Personally, I store files I want to transfer to the emulator in a specific folder on my hard disk, then use the “Unix” volume within the emulator to copy them over to the volume “Bernie”. Here, I extract them (the tools provided within “Utilities” should help in many cases) and then copy the files onto “WorkingVolume”, and arrange them as I want. Note that the window arrangement you leave the windows in will be burned forever into the CD, so it is usually good to move windows up to the top left corner to ensure that they are easily accessible even on a computer with a small screen. In the following example, I have copied a number of items from the “Bernie” disk over to “WorkingVolume”. This includes the System Folder, as this will be the bootable operating system on my CD. This System Folder is a good starting point for bootable disks as it is a universal “minimal install for any computer”, although older computers, such as non-32 bit machines like the SE/30, are not compatible with Mac OS 7.6.1 by default.

07 Setting Up a CD
07 Setting Up a CD

Once you are happy with the contents, icon layout, window positioning and have verified that everything you have placed on the disk works as expected, you are ready to start creating a CD disk image. To do this, open the “Toast Deluxe 4.1.3” folder on the Bernie disk. Then launch the application “Toast Deluxe 4.1.3”. You should see a window similar to the one shown in the second image immediately below. Select “Mac Volume” from the drop down menu, and then drag the “WorkingVolume” disk icon (or whatever you have called your working volume) into the area under the drop down menu. The window should update to similar to the provided image, with the name of your volume following the bold text says “Data: “. Note that Toast will use the CD ROM or CD DVD ROM Extension from the booted Operating System as the CD Driver on the CD it writes, so it needs to be made certain that a version is used which is compatible with the computer you plan to boot. In some cases it might be best to create the custom disk image on the actual machine itself if possible.

Click the button “Data…” and verify that the “Bootable” checkbox is checked if you intend to create a bootable disk. If you do not intend your disk to be bootable, you do not need to do this step. Click “OK” to close this dialogue box again.

10 Select Volume
10 Select Volume

As per the following two images, select “Save as Disc Image…” from the “File” menu, and enter a name for your disk image. Note that you will want to finish the file name with “.iso” – this is important for other operating systems, such as windows, but also serves as a reminder when you are managing your files. You can either save the file on “Bernie” if there is 650MB free, or alternatively save directly to the host by navigating to a suitable location on the mounted “Unix” volume.

Congratulations! You now have a disk image, hopefully formatted correctly to boot a classic Macintosh computer!

Burning the Disk Image

01 K3b Screen
01 K3b Screen

On Linux, launch K3b (which you installed at the beginning of these instructions) and select “Burn Image…” from the “Tools” menu. Near the top of the window under the text “Image to Burn”, to the right of the combo box, is a small button with a folder icon. Click this to use a file open dialogue box to select the CD disk image, in my case “WorkingVolume.iso”, which you intend to burn to a CD. When you select the disk image, you will get an error dialogue box as shown below in the second of the three images – Click “Yes”. This dialogue box is generated because the software doesn’t recognise the format of the disk image, because it is a classic Mac OS disk.

At this point, it is probably a good idea to insert a blank CD-R into your optical drive if you haven’t already. Once the computer has finished probing the disk and the window updates, in the “Burn Image – K3b” window, set “Speed” to the lowest speed offered and click “Start”.

A Real Macintosh IIci Booted from the Example CD