diff --git a/README.md b/README.md index 55b20e0dc..6f224d69d 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ main SkiffOS repository: | VirtualBox | [virt/virtualbox] | N/A | ✔ 6.8.4 | | [Docker Img] | [virt/docker] | N/A | N/A | | [Qemu] | [virt/qemu] | N/A | ✔ 6.8.4 | +| [UTM] on MacOS | [apple/arm] + [virt/qemu] | N/A | ✔ 6.8.4 | | [V86] on WebAssembly | [browser/v86] | [V86] | ✔ 6.8.4 | | [WSL] on Windows | [virt/wsl] | N/A | N/A | |-----------------------|---------------------------|------------------|-----------------| @@ -169,6 +170,7 @@ main SkiffOS repository: [VisionFive2]: https://ameridroid.com/products/visionfive-2 [Steam Deck]: https://store.steampowered.com/steamdeck [USBArmory Mk2]: https://github.com/f-secure-foundry/usbarmory +[UTM]: https://getutm.app/ [V86]: https://copy.sh/v86/?profile=copy/skiffos [Wandboard]: https://elinux.org/Wandboard [WSL]: https://docs.microsoft.com/en-us/windows/wsl/ @@ -345,6 +347,32 @@ $ ./scripts/push_image.bash root@my-ip-address The SkiffOS upgrade (or downgrade) will take effect on next reboot. +### Compile on MacOS + +Building directly on MacOS is not yet possible, particularly due to the +case-insensitivity of the MacOS file system. You can use Lima to build the OS: + +[Install Lima](https://github.com/lima-vm/lima?tab=readme-ov-file#getting-started), then: + +```bash +limactl start --name=skiffos-build https://raw.githubusercontent.com/skiffos/SkiffOS/master/build/lima/lima.yaml +limactl shell skiffos-build +``` + +Then in the lima shell: + +```bash +cd +git clone https://github.com/skiffos/skiffos +cd skiffos +``` + +Proceed with usual build sequence. + +See the [apple/arm] docs for building a VM to run on MacOS. + +[apple/arm]: ./configs/apple/arm + ### Podman Use the `apps/podman` configuration package to enable Podman support. diff --git a/build/lima/lima.yaml b/build/lima/lima.yaml new file mode 100644 index 000000000..3c96a5b48 --- /dev/null +++ b/build/lima/lima.yaml @@ -0,0 +1,53 @@ +images: + - location: >- + https://cloud.debian.org/images/cloud/sid/daily/latest/debian-sid-genericcloud-arm64-daily.qcow2 + arch: aarch64 + +provision: + # Automatically installing the dependencies for a successful ARM build (taken from https://github.com/skiffos/SkiffOS/?tab=readme-ov-file#getting-started) + - mode: boot + script: | + #!/bin/bash + apt-get update + set -eux -o pipefail + export DEBIAN_FRONTEND=noninteractive + apt-get install -y \ + bash \ + bc \ + binutils \ + build-essential \ + bzip2 \ + cpio \ + diffutils \ + file \ + findutils \ + git \ + golang \ + gzip \ + libarchive-tools \ + libncurses-dev \ + make \ + patch \ + perl \ + rsync \ + sed \ + tar \ + unzip \ + wget \ + zsh + +mounts: + - location: "/tmp/lima" + writable: true + - location: ~/skiffos-build + mountPoint: /opt/skiffos-build + writable: true + +mountType: virtiofs +disk: 75GB +cpus: 8 + +# NOTE: This uses a "raw" disk format (unlike qemu). +# This is faster but uses disk space equal to the disk: option above! +# Not using this option will use less disk space. +# vmType: vz diff --git a/configs/apple/arm/README.md b/configs/apple/arm/README.md index ddac30d18..5d3767ee7 100644 --- a/configs/apple/arm/README.md +++ b/configs/apple/arm/README.md @@ -1,32 +1,36 @@ -# Apple Macbook (ARM) +# Apple Silicon (ARM64) -This package supports the ARM64 Macbook Pros. +This package supports the ARM64 Macs. -Direct hardware support through [Asahi Linux] will be supported, but has not -been implemented yet. In the meantime, we support running with [UTM] on MacOS. +Support for booting SkiffOS natively with [Asahi Linux] has not been implemented yet. [Asahi Linux]: https://asahilinux.org/ + +In the meantime, we support running with [UTM] on MacOS. + [UTM]: https://github.com/utmapp/UTM -## Setup +## Compiling -Install UTM on your Mac. +For compiling on MacOS, see [Compile on MacOS]. -Compile SkiffOS on a Linux host: +[Compile on MacOS]: https://github.com/skiffos/SkiffOS?tab=readme-ov-file#compile-on-macos -``` -export SKIFF_CONFIG=apple/arm,skiff/core +```bash +export SKIFF_CONFIG=apple/arm,skiff/core,virt/qemu make configure compile +make cmd/virt/qemu/buildutm ``` -Instructions on how to run using UTM will be added here soon (TODO). +Copy `workspaces/default/images/skiffos.utm` to your Mac, on Lima: -## Compiling on MacOS +```bash +cp workspaces/default/images/skiffos.utm /opt/skiffos-build +``` -Compiling SkiffOS on MacOS is not yet supported. +## Running in UTM -You can compile it in any Linux environment or VM. +[Install UTM](https://getutm.app) on your MacOS machine. -Instructions on how to build using [lima] will be added here soon. +Run `open ~/skiffos-build` and double-click the skiffos.utm file to start the VM! -[lima]: https://github.com/lima-vm/lima diff --git a/configs/apple/arm/buildroot/arch b/configs/apple/arm/buildroot/arch index c9222d8c5..fe2edbc26 100644 --- a/configs/apple/arm/buildroot/arch +++ b/configs/apple/arm/buildroot/arch @@ -2,4 +2,5 @@ BR2_aarch64=y # The M1, M2, and M3 support armv8.5-a. # Closest option we have: saphira => armv8.4a +# With qemu this requires -cpu max BR2_saphira=y diff --git a/configs/apple/arm/root_overlay/opt/skiff/scripts/mount-all.pre.d/00mounts.sh b/configs/apple/arm/root_overlay/opt/skiff/scripts/mount-all.pre.d/00mounts.sh deleted file mode 100755 index feaaddf07..000000000 --- a/configs/apple/arm/root_overlay/opt/skiff/scripts/mount-all.pre.d/00mounts.sh +++ /dev/null @@ -1,5 +0,0 @@ -export PERSIST_DEVICE="LABEL=SKIFFOS" -export ROOTFS_DEVICE="/mnt/persist/rootfs" -export ROOTFS_MNT_FLAGS="--rbind" -export BOOT_DEVICE="/mnt/persist/boot" -export BOOT_MNT_FLAGS="--rbind" diff --git a/configs/virt/qemu/README.md b/configs/virt/qemu/README.md index 7d0489c5a..9d4da9db8 100644 --- a/configs/virt/qemu/README.md +++ b/configs/virt/qemu/README.md @@ -19,3 +19,25 @@ Log in as "root" for the default Skiff setup. The `intel/x64` portion of `SKIFF_CONFIG` can be replaced with any of the SkiffOS targets, including the arm and riscv64 systems. + +## Using UTM on MacOS + +For compiling on MacOS, see [Compile on MacOS]. + +[Compile on MacOS]: https://github.com/skiffos/SkiffOS?tab=readme-ov-file#compile-on-macos + +```bash +export SKIFF_CONFIG=apple/arm,skiff/core,virt/qemu +make configure compile +make cmd/virt/utm/buildutm +``` + +Copy `workspaces/default/images/skiffos.utm` to your Mac, on Lima: + +``` +cp workspaces/default/images/skiffos.utm /opt/skiffos-build +``` + +[Install UTM](https://getutm.app) on your MacOS machine. + +Run `open ~/skiffos-build` and double-click the skiffos.utm file to start the VM! diff --git a/configs/virt/qemu/buildroot/tools b/configs/virt/qemu/buildroot/tools index bc9724156..a3008a4fa 100644 --- a/configs/virt/qemu/buildroot/tools +++ b/configs/virt/qemu/buildroot/tools @@ -1,5 +1,3 @@ BR2_PACKAGE_HOST_QEMU=y BR2_PACKAGE_HOST_QEMU_SYSTEM_MODE=y BR2_PACKAGE_HOST_QEMU_VIRTFS=y -BR2_PACKAGE_HOST_E2FSPROGS=y -BR2_PACKAGE_HOST_GENEXT2FS=y diff --git a/configs/virt/qemu/extensions/Makefile b/configs/virt/qemu/extensions/Makefile index 91f7af604..39e598859 100644 --- a/configs/virt/qemu/extensions/Makefile +++ b/configs/virt/qemu/extensions/Makefile @@ -1,2 +1,5 @@ run: @$(SKIFF_CURRENT_CONF_DIR)/scripts/execute_qemu.sh + +buildutm: + @$(SKIFF_CURRENT_CONF_DIR)/scripts/buildutm.sh diff --git a/configs/virt/qemu/resources/utm-config.plist b/configs/virt/qemu/resources/utm-config.plist new file mode 100644 index 000000000..4e9107359 --- /dev/null +++ b/configs/virt/qemu/resources/utm-config.plist @@ -0,0 +1,191 @@ + + + + + Backend + QEMU + ConfigurationVersion + 4 + Display + + + DownscalingFilter + Linear + DynamicResolution + + Hardware + virtio-gpu-pci + NativeResolution + + UpscalingFilter + Nearest + + + Drive + + + Identifier + 1a69bb72-4f95-4525-95b6-a228ceb8ee74 + ImageName + Image + ImageType + LinuxKernel + Interface + None + InterfaceVersion + 1 + ReadOnly + + + + Identifier + de859e3e-ea2d-4c5b-beb1-0693160e884e + ImageName + rootfs.cpio.lz4 + ImageType + LinuxInitrd + Interface + None + InterfaceVersion + 1 + ReadOnly + + + + Identifier + 81204ce1-bebe-458a-be45-f19b6eebe4c5 + ImageName + persist.qcow2 + ImageType + Disk + Interface + VirtIO + InterfaceVersion + 1 + ReadOnly + + + + Information + + Icon + skiff-icon.png + IconCustom + + Name + SkiffOS + UUID + 20c05852-ae8c-49e8-bc99-7f7db953aed0 + + Input + + MaximumUsbShare + 3 + UsbBusSupport + 3.0 + UsbSharing + + + Network + + + Hardware + virtio-net-pci + IsolateFromHost + + MacAddress + REPLACEME_MAC_ADDRESS + Mode + Shared + PortForward + + + + QEMU + + AdditionalArguments + + -append + "root=/dev/ram0 ro net.ifnames=0" + + BalloonDevice + + DebugLog + + Hypervisor + + PS2Controller + + RNGDevice + + RTCLocalTime + + TPMDevice + + TSO + + UEFIBoot + + + Serial + + + Mode + Terminal + Target + Auto + Terminal + + BackgroundColor + #000000 + CursorBlink + + Font + Menlo + FontSize + 12 + ForegroundColor + #ffffff + + + + Sharing + + ClipboardSharing + + DirectoryShareMode + VirtFS + DirectoryShareReadOnly + + + Sound + + + Hardware + intel-hda + + + System + + Architecture + aarch64 + CPU + default + CPUCount + 0 + CPUFlagsAdd + + CPUFlagsRemove + + ForceMulticore + + JITCacheSize + 0 + MemorySize + 4096 + Target + virt + + + + diff --git a/configs/virt/qemu/scripts/buildutm.sh b/configs/virt/qemu/scripts/buildutm.sh new file mode 100755 index 000000000..f8d1c7328 --- /dev/null +++ b/configs/virt/qemu/scripts/buildutm.sh @@ -0,0 +1,45 @@ +#!/bin/bash +set -eo pipefail + +# Directories and file setup +IMAGES_DIR="${BUILDROOT_DIR}/images" +UTM_DIR="${IMAGES_DIR}/skiffos.utm" +ROOTFS_FILE="${UTM_DIR}/Data/persist.qcow2" + +# Set default root filesystem size if not provided +: "${ROOTFS_MAX_SIZE:=32G}" + +# Ensure necessary directories exist +mkdir -p "${UTM_DIR}/Data" + +# Copy necessary resources +cp "${ROOT_DIR}/resources/images/skiff-icon.png" "${UTM_DIR}/Data/skiff-icon.png" +cp "${IMAGES_DIR}/Image" "${UTM_DIR}/Data/Image" +cp "${IMAGES_DIR}/rootfs.cpio.lz4" "${UTM_DIR}/Data/rootfs.cpio.lz4" + +# Create a sparse image if it does not exist +if [ ! -f "${ROOTFS_FILE}" ]; then + qemu-img create -f qcow2 "${ROOTFS_FILE}" "${ROOTFS_MAX_SIZE}" +fi + +# Function to generate a MAC address +# https://github.com/utmapp/UTM/blob/13664282a2a9fb239f62c5777cb45cabcce29fae/Configuration/UTMConfiguration%2BNetworking.m#L75-L85 +generate_mac_address() { + local mac="" + for i in {1..6}; do + local byte=$((RANDOM % 256)) + if [[ $i -eq 1 ]]; then + byte=$((byte & 0xFC | 0x2)) # Ensure locally administered and unicast + fi + mac+=$(printf "%02X" $byte) + [ $i -lt 6 ] && mac+=":" + done + echo "$mac" +} + +# Configure UTM plist with a dynamic MAC address +cp "${SKIFF_CURRENT_CONF_DIR}/resources/utm-config.plist" "${UTM_DIR}/config.plist" +sed -i -e "s/REPLACEME_MAC_ADDRESS/$(generate_mac_address)/g" "${UTM_DIR}/config.plist" + +# Echo completion status +echo "UTM environment setup complete." diff --git a/resources/images/skiff-icon.png b/resources/images/skiff-icon.png new file mode 100644 index 000000000..5a70a097f Binary files /dev/null and b/resources/images/skiff-icon.png differ