jpskill.com
🛠️ 開発・MCP コミュニティ

routeros-qemu-chr

MikroTik RouterOS CHR (Cloud Hosted Router) with QEMU. Use when: running RouterOS in QEMU, booting CHR images, debugging CHR boot failures, setting up VirtIO devices for RouterOS, choosing between SeaBIOS and UEFI boot, configuring QEMU port forwarding for RouterOS REST API, or selecting QEMU acceleration (KVM/HVF/TCG).

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o routeros-qemu-chr.zip https://jpskill.com/download/20957.zip && unzip -o routeros-qemu-chr.zip && rm routeros-qemu-chr.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/20957.zip -OutFile "$d\routeros-qemu-chr.zip"; Expand-Archive "$d\routeros-qemu-chr.zip" -DestinationPath $d -Force; ri "$d\routeros-qemu-chr.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して routeros-qemu-chr.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → routeros-qemu-chr フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
5

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

QEMU を使用した RouterOS CHR

CHR とは

Cloud Hosted Router (CHR) は、仮想マシン向けに設計された MikroTik の x86_64 および aarch64 版 RouterOS イメージです。無料ライセンスでは、1 Mbps の速度制限付きで無制限に使用できます。これは、開発、テスト、API 作業、パケットスニファのデバッグに十分です。無料の 60 日間トライアルでは、速度制限が完全に解除されます(無料の mikrotik.com アカウントが必要です)。ライセンスティア、トライアルのアクティベーション、有効期限の動作に関する詳細は、CHR ライセンスリファレンスをご覧ください。

イメージのバリアント

イメージ アーキテクチャ 起動方法 ソース
chr-<ver>.img x86_64 SeaBIOS (MBR チェーンロード) download.mikrotik.com
chr-<ver>-arm64.img aarch64 UEFI (EDK2 pflash) download.mikrotik.com
chr-efi.img (fat-chr) x86_64 UEFI (OVMF) tikoci/fat-chr GitHub

標準の x86 イメージには独自のブートパーティションがあります — GPT では EFI システムパーティションのように見えますが、FAT ではありません。UEFI ファームウェア (OVMF) はこれを読み取ることができません。SeaBIOS のみが MBR チェーンロードを介して起動できます。

fat-chr で再パッケージ化されたイメージは、これを標準の FAT16 と EFI/BOOT/BOOTX64.EFI に変換し、UEFI ブートを可能にします。X86 macOS 上の Apple Virtualization.framework には必須ですが、それ以外の場所ではオプションです。

ディスクレイアウト (128 MiB、両アーキテクチャ): ハイブリッド GPT+MBR、パーティション 1 = ブート (~33 MiB)、パーティション 2 = ext4 ルート (~94 MiB)。

CHR イメージのダウンロード

// Resolve current version
const channel = "stable"; // or: long-term, testing, development
const version = await fetch(
  `https://upgrade.mikrotik.com/routeros/NEWESTa7.${channel}`
).then(r => r.text()).then(s => s.trim());

// Download x86_64 image
const url = `https://download.mikrotik.com/routeros/${version}/chr-${version}.img.zip`;
// Download aarch64 image
const armUrl = `https://download.mikrotik.com/routeros/${version}/chr-${version}-arm64.img.zip`;

イメージは .img.zip として配布されます — 解凍すると生の .img ディスクファイルが得られます。

パターンの選択: QEMU 呼び出し

QEMU で CHR を起動するには、いくつかの有効なアプローチがあります。それぞれにトレードオフがあります。

パターン A: インライン引数 (最もシンプル、スクリプトに適しています)

すべてをコマンドラインで指定します。LLM が構築およびデバッグしやすく、すべての状態が一箇所で確認できます。

qemu-system-x86_64 -M q35 -m 256 -smp 1 \
  -drive file=chr.img,format=raw,if=virtio \
  -netdev user,id=net0,hostfwd=tcp::9180-:80 \
  -device virtio-net-pci,netdev=net0 \
  -display none -serial stdio

長所: 単一コマンド、読みやすい、変更しやすい。 短所: 長いコマンドライン、バージョン管理が難しい、永続性がない。

パターン B: ラッパースクリプト (再利用に適しています)

アクセラレーションを検出し、ファームウェアパスを処理し、PID ファイルを管理するシェルスクリプトです。

#!/bin/sh
# detect acceleration
if [ "$(uname -s)" = "Linux" ] && [ -w /dev/kvm ]; then
  ACCEL="-accel kvm"
elif [ "$(uname -s)" = "Darwin" ] && [ "$(sysctl -n kern.hv_support 2>/dev/null)" = "1" ]; then
  ACCEL="-accel hvf"
else
  ACCEL="-accel tcg"
fi

qemu-system-x86_64 -M q35 -m 256 -smp 1 \
  $ACCEL \
  -drive file=chr.img,format=raw,if=virtio \
  -netdev user,id=net0,hostfwd=tcp::${PORT:-9180}-:80 \
  -device virtio-net-pci,netdev=net0 \
  -display none -serial stdio

長所: ポータブル、プラットフォームの違いを処理、パラメータ化可能。 短所: シェルスクリプトの制限、TypeScript からの構成が難しい。

パターン C: Bun/TypeScript からのプログラムによる起動 (統合テストに適しています)

QEMU を子プロセスとして起動し、完全に制御します。

import { $ } from "bun";

const port = 9180;
const accel = await detectAccel();
const proc = Bun.spawn([
  "qemu-system-x86_64", "-M", "q35", "-m", "256",
  "-accel", accel,
  "-drive", `file=chr.img,format=raw,if=virtio`,
  "-netdev", `user,id=net0,hostfwd=tcp::${port}-:80`,
  "-device", "virtio-net-pci,netdev=net0",
  "-display", "none",
  "-chardev", `socket,id=serial0,path=/tmp/chr-serial.sock,server=on,wait=off`,
  "-serial", "chardev:serial0",
  "-monitor", `unix:/tmp/chr-monitor.sock,server,nowait`,
], { stdio: ["ignore", "pipe", "pipe"] });

// Wait for boot
await waitForBoot(`http://127.0.0.1:${port}/`);

長所: 完全なライフサイクル制御、並列インスタンス管理、TypeScript ネイティブ。 短所: コード量が多い、QEMU 引数が依然として正しい必要があります。

パターン D: 設定ファイル (--readconfig) (宣言的、mikropkl で使用)

QEMU の --readconfig は、デバイス/マシン設定用の INI 形式ファイルを読み込みます。mikropkl プロジェクトは、宣言的な VM パッケージングにこれを使用しています。

トレードオフ: 懸念事項を分離します(設定と起動)が、INI 形式は不明瞭であり、すべての QEMU オプションを表現できるわけではありません(pflash、-accel-netdev user,hostfwd はすべてコマンドライン引数を必要とします)。プログラムで設定を生成するプロジェクトに最適です。

起動方法

SeaBIOS を使用した x86_64 (デフォルト、最速)

ファームウェアのセットアップは不要です — QEMU の組み込み SeaBIOS が MikroTik の独自のブートセクタを処理します。

qemu-system-x86_64 -M q35 -m 256 \
  -drive file=chr-7.22.img,format=raw,if=virtio \
  -netdev user,id=net0,hostfwd=tcp::9180-:80 \
  -device virtio-net-pci,netdev=net0 \
  -display none -serial stdio

-M pc (i440fx、レガシー PCI) も CHR で動作します。CHR は、q35 が追加する機能のほとんど(最新の PCIe トポロジ、ACPI ベースのホットプラグなど)を使用しません。RouterOS カーネルは起動後に BIOS/ACPI スタックをバイパスするためです — 実際に使用するのは VirtIO PCI デバイスであり、両方のマシンタイプでこれらは同じように公開されます。このカーネル設定の証拠については、tikoci/mikrotik-gpl (v7.2 カーネル設定アーカイブ) を参照してください。

起動時間: 約 5 秒 (KVM)、約 30 秒 (TCG)。TCG の場合、-accel tcg,tb-size=256 は変換ブロックキャッシュを拡大し、繰り返し実行時の起動時間を著しく短縮します。

UEFI (EDK2) を使用した aarch64

UEFI pflash ファームウェアファイルが必要です。両方の pflash ユニットは同じサイズである必要があります (通常 64 MiB)。

# Copy vars file (writable) — never modify the original
cp /path/to/edk2-arm-vars.fd /tmp/my-vars.fd

qemu-system-aarch64 -M vi

(原文がここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

RouterOS CHR with QEMU

What Is CHR

Cloud Hosted Router (CHR) is MikroTik's x86_64 and aarch64 RouterOS image designed for virtual machines. Free license allows unlimited use with 1 Mbps speed limit — sufficient for development, testing, API work, and packet sniffer debugging. A free 60-day trial removes the speed limit entirely (requires a free mikrotik.com account). See CHR licensing reference for full details on license tiers, trial activation, and expiry behavior.

Image Variants

Image Architecture Boot method Source
chr-<ver>.img x86_64 SeaBIOS (MBR chain-load) download.mikrotik.com
chr-<ver>-arm64.img aarch64 UEFI (EDK2 pflash) download.mikrotik.com
chr-efi.img (fat-chr) x86_64 UEFI (OVMF) tikoci/fat-chr GitHub

Standard x86 image has a proprietary boot partition — it looks like an EFI System Partition in GPT but is NOT FAT. UEFI firmware (OVMF) cannot read it. Only SeaBIOS can boot it via MBR chain-load.

The fat-chr repackaged image converts this to standard FAT16 with EFI/BOOT/BOOTX64.EFI, enabling UEFI boot. Required for Apple Virtualization.framework on X86 macOS, optional everywhere else.

Disk layout (128 MiB, both architectures): Hybrid GPT+MBR, partition 1 = boot (~33 MiB), partition 2 = ext4 root (~94 MiB).

Downloading CHR Images

// Resolve current version
const channel = "stable"; // or: long-term, testing, development
const version = await fetch(
  `https://upgrade.mikrotik.com/routeros/NEWESTa7.${channel}`
).then(r => r.text()).then(s => s.trim());

// Download x86_64 image
const url = `https://download.mikrotik.com/routeros/${version}/chr-${version}.img.zip`;
// Download aarch64 image
const armUrl = `https://download.mikrotik.com/routeros/${version}/chr-${version}-arm64.img.zip`;

Images are distributed as .img.zip — unzip to get the raw .img disk file.

Pattern Choices: QEMU Invocation

There are several valid approaches to launching CHR under QEMU. Each has tradeoffs:

Pattern A: Inline arguments (simplest, good for scripts)

Everything on the command line. Easy for an LLM to construct and debug — all state is visible in one place.

qemu-system-x86_64 -M q35 -m 256 -smp 1 \
  -drive file=chr.img,format=raw,if=virtio \
  -netdev user,id=net0,hostfwd=tcp::9180-:80 \
  -device virtio-net-pci,netdev=net0 \
  -display none -serial stdio

Pros: Single command, easy to read, easy to modify. Cons: Long command lines, hard to version-control, no persistence.

Pattern B: Wrapper script (good for reuse)

A shell script that detects acceleration, handles firmware paths, manages PID files.

#!/bin/sh
# detect acceleration
if [ "$(uname -s)" = "Linux" ] && [ -w /dev/kvm ]; then
  ACCEL="-accel kvm"
elif [ "$(uname -s)" = "Darwin" ] && [ "$(sysctl -n kern.hv_support 2>/dev/null)" = "1" ]; then
  ACCEL="-accel hvf"
else
  ACCEL="-accel tcg"
fi

qemu-system-x86_64 -M q35 -m 256 -smp 1 \
  $ACCEL \
  -drive file=chr.img,format=raw,if=virtio \
  -netdev user,id=net0,hostfwd=tcp::${PORT:-9180}-:80 \
  -device virtio-net-pci,netdev=net0 \
  -display none -serial stdio

Pros: Portable, handles platform differences, parameterizable. Cons: Shell scripting limitations, harder to compose from TypeScript.

Pattern C: Programmatic launch from Bun/TypeScript (good for integration tests)

Launch QEMU as a child process with full control:

import { $ } from "bun";

const port = 9180;
const accel = await detectAccel();
const proc = Bun.spawn([
  "qemu-system-x86_64", "-M", "q35", "-m", "256",
  "-accel", accel,
  "-drive", `file=chr.img,format=raw,if=virtio`,
  "-netdev", `user,id=net0,hostfwd=tcp::${port}-:80`,
  "-device", "virtio-net-pci,netdev=net0",
  "-display", "none",
  "-chardev", `socket,id=serial0,path=/tmp/chr-serial.sock,server=on,wait=off`,
  "-serial", "chardev:serial0",
  "-monitor", `unix:/tmp/chr-monitor.sock,server,nowait`,
], { stdio: ["ignore", "pipe", "pipe"] });

// Wait for boot
await waitForBoot(`http://127.0.0.1:${port}/`);

Pros: Full lifecycle control, parallel instance management, TypeScript-native. Cons: More code, QEMU args still need to be correct.

Pattern D: Config file (--readconfig) (declarative, used by mikropkl)

QEMU's --readconfig loads an INI-format file for device/machine config. The mikropkl project uses this for its declarative VM packaging.

Tradeoffs: Separates concerns (config vs launch), but the INI format is obscure and not all QEMU options can be expressed in it (pflash, -accel, -netdev user,hostfwd all require command-line args). Best suited for projects that generate configs programmatically.

Boot Tracks

x86_64 with SeaBIOS (default, fastest)

No firmware setup needed — QEMU's built-in SeaBIOS handles MikroTik's proprietary boot sector:

qemu-system-x86_64 -M q35 -m 256 \
  -drive file=chr-7.22.img,format=raw,if=virtio \
  -netdev user,id=net0,hostfwd=tcp::9180-:80 \
  -device virtio-net-pci,netdev=net0 \
  -display none -serial stdio

-M pc (i440fx, legacy PCI) also works for CHR. CHR doesn't exercise most of what q35 adds (modern PCIe topology, ACPI-based hotplug, etc.) because the RouterOS kernel bypasses the BIOS/ACPI stack after boot — the VirtIO PCI devices are what it actually uses, and both machine types expose those identically. For the kernel-config evidence behind this, see tikoci/mikrotik-gpl (v7.2 kernel config archive).

Boot time: ~5s (KVM), ~30s (TCG). For TCG, -accel tcg,tb-size=256 enlarges the translation block cache and reduces boot time noticeably on repeated runs.

aarch64 with UEFI (EDK2)

Requires UEFI pflash firmware files. Both pflash units must be identical size (typically 64 MiB):

# Copy vars file (writable) — never modify the original
cp /path/to/edk2-arm-vars.fd /tmp/my-vars.fd

qemu-system-aarch64 -M virt -cpu cortex-a710 -m 256 \
  -drive if=pflash,format=raw,readonly=on,unit=0,file=/path/to/edk2-aarch64-code.fd \
  -drive if=pflash,format=raw,unit=1,file=/tmp/my-vars.fd \
  -drive file=chr-arm64.img,format=raw,if=none,id=drive0 \
  -device virtio-blk-pci,drive=drive0 \
  -netdev user,id=net0,hostfwd=tcp::9180-:80 \
  -device virtio-net-pci,netdev=net0 \
  -display none -serial stdio

Boot time: ~10s (KVM), ~20s (TCG native), ~20s (TCG cross-arch on x86 host).

UEFI Firmware Locations

Platform Code ROM Vars File
macOS Homebrew (Apple Silicon) /opt/homebrew/share/qemu/edk2-aarch64-code.fd edk2-arm-vars.fd
macOS Homebrew (Intel) /usr/local/share/qemu/edk2-aarch64-code.fd edk2-arm-vars.fd
Ubuntu/Debian /usr/share/AAVMF/AAVMF_CODE.fd AAVMF_VARS.fd
x86 OVMF (Homebrew) edk2-x86_64-code.fd edk2-i386-vars.fd
x86 OVMF (Linux) /usr/share/OVMF/OVMF_CODE.fd OVMF_VARS.fd

VirtIO — Critical Details

See the VirtIO driver matrix for the full table.

The one rule: RouterOS has virtio_pci but NOT virtio_mmio. This matters on aarch64.

The if=virtio Trap (aarch64)

                         x86_64 (q35)              aarch64 (virt)
if=virtio shorthand →    virtio-blk-pci (PCI) ✅    virtio-blk-device (MMIO) ❌
-device virtio-blk-pci → virtio-blk-pci (PCI) ✅    virtio-blk-pci (PCI) ✅

On x86_64 q35, if=virtio resolves to PCI — works fine. On aarch64 virt, it resolves to MMIO — RouterOS kernel stalls silently. Always use explicit -device virtio-blk-pci on aarch64:

# WRONG on aarch64 — silent boot failure
-drive file=chr.img,format=raw,if=virtio

# CORRECT on aarch64 — explicit PCI device
-drive file=chr.img,format=raw,if=none,id=drive0
-device virtio-blk-pci,drive=drive0

On x86_64, both work. The explicit form is always safe on both architectures.

Network — Universal

All architectures: virtio-net-pci. No exceptions:

-netdev user,id=net0,hostfwd=tcp::9180-:80
-device virtio-net-pci,netdev=net0

Acceleration Detection

import { $ } from "bun";

async function detectAccel(guestArch: string): Promise<string> {
  const hostOs = process.platform;  // "darwin" | "linux"
  const hostArch = process.arch;    // "x64" | "arm64"

  if (hostOs === "linux") {
    // KVM requires host/guest architecture match
    const kvm = await Bun.file("/dev/kvm").exists();
    const archMatch = (guestArch === "x86_64" && hostArch === "x64")
      || (guestArch === "aarch64" && hostArch === "arm64");
    if (kvm && archMatch) return "kvm";
  }

  if (hostOs === "darwin") {
    // HVF may not be available (e.g., GitHub Actions VMs)
    const hvOk = await $`sysctl -n kern.hv_support`.text().then(s => s.trim() === "1").catch(() => false);
    const archMatch = (guestArch === "aarch64" && hostArch === "arm64")
      || (guestArch === "x86_64" && hostArch === "x64");
    if (hvOk && archMatch) return "hvf";
  }

  return "tcg";  // Software emulation — always available
}

Key rule: KVM and HVF both require host/guest architecture match. Cross-arch always falls back to TCG. Don't check just for /dev/kvm — verify the architecture matches too.

HVF + CPU Model Gotcha (macOS)

With -accel hvf, QEMU exposes the host CPU directly. Specifying a CPU model like cortex-a710 (ARMv9, requires SVE2) on Apple Silicon (ARMv8.5) crashes QEMU before the VM starts. Use -cpu host with HVF:

# TCG/KVM — specify exact model
CPU_FLAGS="-cpu cortex-a710"

# HVF — passthrough host CPU
if [ "$ACCEL" = "hvf" ]; then
  CPU_FLAGS="-cpu host"
fi

Health Check and Boot Wait

RouterOS WebFig responds with HTTP 200 on port 80 without authentication — this works as a minimal health check:

async function waitForBoot(url: string, timeoutMs = 60_000): Promise<boolean> {
  const deadline = Date.now() + timeoutMs;
  while (Date.now() < deadline) {
    try {
      const r = await fetch(url, { signal: AbortSignal.timeout(2000) });
      if (r.ok) return true;
    } catch { /* not ready yet */ }
    await Bun.sleep(2000);
  }
  return false;
}

Startup race — pitfall if you then call the REST API immediately

RouterOS boot is staged from the client's perspective:

  1. Connection refused — QEMU still booting
  2. ECONNRESET — HTTP server up but REST subsystem not accepting
  3. 401 from /rest/* — auth middleware up; REST handler may still be initializing
  4. 200 but wrong body — REST initialized before routing tables settled; /system/resource can briefly return an array (e.g., a /user list) before it returns the expected singleton object
  5. 200 with correct body — fully operational

A health check on the root / reaches stage 2 but gives no signal about 3–5. For code that will immediately call the REST API, probe /rest/system/resource with auth and require two consecutive successful probes with the expected body shape (singleton object containing board-name). On auth-only checks (unprovisioned admin), accept 401/403 as "REST layer responded." The / + HTTP 200 check is fine for "is it up?" monitoring but not for "can I start calling REST now?"

Port Forwarding

QEMU user-mode networking (-netdev user,hostfwd=...) for typical RouterOS services:

Service Guest Port Example Host Port hostfwd
WebFig/REST API 80 9180 tcp::9180-:80
SSH (RouterOS CLI) 22 9122 tcp::9122-:22
API protocol 8728 9728 tcp::9728-:8728
API-SSL 8729 9729 tcp::9729-:8729
WinBox 8291 9291 tcp::9291-:8291

Multiple forwards in one netdev:

-netdev user,id=net0,hostfwd=tcp::9180-:80,hostfwd=tcp::9122-:22,hostfwd=tcp::9728-:8728

Use unique host ports per instance when running multiple CHRs (9180, 9181, 9182...).

Known Limitations

  • QGA (Guest Agent) requires KVM — RouterOS CHR's QGA daemon only starts when it detects a KVM hypervisor via CPUID. Under HVF (macOS) or TCG (software emulation), CPUID 0x40000000 returns no KVM vendor string and 0x40000001 returns no KVM features, so the daemon never starts. QEMU correctly provides the virtio-serial port and sends PORT_OPEN (event 6) — the guest simply never opens it (query-chardev shows frontend-open=false). This is NOT a QEMU bug. MikroTik documents QGA exclusively under the "KVM" section. QGA testing requires Linux + KVM (e.g., mikropkl lab).
  • check-installation fails on aarch64 in all QEMU environments — this is an unresolvable firmware/DTB issue (see known issues)
  • Direct -kernel boot does not work for either architecture — RouterOS needs its full firmware boot path
  • Cross-arch TCG: x86_64 on aarch64 host is not viable — x86 I/O port emulation is too slow (~300s+ timeouts). The reverse (aarch64 on x86_64) works fine (~20s)
  • No virtio_mmio driver — always use explicit -device virtio-blk-pci, never rely on if=virtio on aarch64

Additional Resources

  • VirtIO driver matrix — full driver support table
  • Known issues — boot failures, cross-arch limitations
  • GitHub Actions CI patterns — running CHR on GitHub-hosted runners
  • CHR licensing — free tier (1 Mbps), 60-day trial, paid tiers, expiry behavior
  • For RouterOS CLI/REST once booted: see the routeros-fundamentals skill
  • For packet capture and TZSP streaming from CHR: see the routeros-sniffer skill
  • For /app YAML container format (requires CHR with container package): see the routeros-app-yaml skill

同梱ファイル

※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。