使用 qemu/incus 启动 home-assistant
使用 qemu 启动 home-assistant
下载 home-assistant 镜像
wget https://github.com/home-assistant/operating-system/releases/download/15.2/haos_ova-15.2.qcow2.xz
# 解压
xz -d haos_ova-15.2.qcow2.xz
扩容镜像大小
qemu-img resize haos_ova-15.2.qcow2 50G
创建 tap 网卡
# 创建 TAP 接口
sudo ip tuntap add dev jvp-ha mode tap
# 激活 TAP 接口
sudo ip link set dev jvp-ha up
# 将 TAP 接口添加到网桥 br0
sudo ip link set dev jvp-ha master br0
qemu 配置
# Machine
[machine]
graphics = "off" # 关闭图形界面
type = "q35" # 使用 Q35 架构
accel = "kvm" # 使用 KVM 加速
usb = "off" # 关闭 USB
[global]
driver = "ICH9-LPC"
property = "disable_s3"
value = "1"
[global]
driver = "ICH9-LPC"
property = "disable_s4"
value = "1"
[boot-opts]
strict = "on" # 严格模式
# Memory
[memory]
size = "2048M" # 内存大小
# CPU
[smp-opts]
cpus = "2" # 核心数
maxcpus = "2" # 最大核心数
[object "mem0"]
qom-type = "memory-backend-memfd" # 内存类型
size = "2048M" # 内存大小
share = "on" # 共享
# Qemu control
[chardev "monitor"]
backend = "socket"
path = "/home/jimyag/jvp/m6-ha/qemu.monitor"
server = "on"
wait = "off"
[mon]
chardev = "monitor"
mode = "control"
# Console
[chardev "console"]
backend = "socket"
path = "/home/jimyag/jvp/m6-ha/qemu.console"
server = "on"
wait = "off"
[device "virtio-serial0"]
driver = "virtio-serial"
[device "console"]
driver = "virtserialport"
chardev = "console"
name = "org.qemu.guest_agent.0"
# Random number generator
[object "qemu_rng"]
qom-type = "rng-random"
filename = "/dev/urandom"
# Drive
[drive "haos_ova-15.2.qcow2"]
file = "/home/jimyag/jvp/m6-ha/haos_ova-15.2.qcow2"
if = "virtio"
format = "qcow2"
启动 qemu
#! /bin/bash
sudo rm -f /home/jimyag/jvp/m6-ha/{qemu.console,qemu.pid,qemu.log,qemu.spice,qemu.vnc}
sudo qemu-system-x86_64 \
-daemonize \
-name "ha" \
-display none \
-uuid 0fecc246-2c34-4f62-ab57-36d4a931d0c2 \
-cpu host,hv_passthrough \
-no-user-config \
-sandbox on,obsolete=deny,elevateprivileges=allow,spawn=allow,resourcecontrol=deny \
-netdev tap,id=net0,ifname=jvp-ha,script=no,downscript=no \
-device virtio-net-pci,netdev=net0 \
-readconfig /home/jimyag/jvp/m6-ha/qemu.conf \
-pidfile /home/jimyag/jvp/m6-ha/qemu.pid \
-D /home/jimyag/jvp/m6-ha/qemu.log \
-spice unix=on,disable-ticketing=on,addr=/home/jimyag/jvp/m6-ha/qemu.spice \
-runas nobody \
-vnc unix:/home/jimyag/jvp/m6-ha/qemu.vnc \
-smbios type=2,manufacturer=JIMYAG,product=JVP \
-drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.fd \
-drive if=pflash,format=raw,file=/usr/share/OVMF/OVMF_VARS_4M.fd
# 不要调整netdev,device 和 readconfig的位置
里面的 /usr/share/OVMF/OVMF_VARS_4M.fd 和 /usr/share/OVMF/OVMF_CODE_4M.fd 不同的 host 系统可能不一样,需要根据实际情况调整。一般安装 ovmf 会自动在 /usr/share/OVMF/ 目录下生成这两个文件。
暴露 vnc 端口
sudo socat TCP-LISTEN:5900,fork UNIX-CONNECT:/home/jimyag/jvp/m6-ha/qemu.vnc
使用 noVNC 或者 其他 VNC 客户端连接
进入 登陆到 home-assistant 的 shell
默认的 shell 用户名是 root 没有密码,按回车进入
执行 ha network info 查看网络信息
浏览器 访问 http://<ip>:8123
进入 home-assistant 的 web 界面
如果要删除网卡,执行
sudo ip link set dev jvp-ha nomaster
sudo ip link set dev jvp-ha down
sudo ip tuntap del dev jvp-ha mode tap
使用 incus 启动 home-assistant
下载 home-assistant 镜像
wget https://github.com/home-assistant/operating-system/releases/download/15.2/haos_ova-15.2.qcow2.xz
# 解压
xz -d haos_ova-15.2.qcow2.xz
扩容镜像大小
qemu-img resize haos_ova-15.2.qcow2 50G
下载 incus-migrate
wget https://github.com/lxc/incus/releases/latest/download/bin.linux.incus-migrate.x86_64
# 赋予执行权限
chmod +x bin.linux.incus-migrate.x86_64
# 移动到 /usr/local/bin/
sudo mv bin.linux.incus-migrate.x86_64 /usr/local/bin/incus-migrate
使用 incus-migrate 迁移镜像
sudo incus-migrate
The local Incus server is the target [default=yes]:
Would you like to create a container (1) or virtual-machine (2)?: 2
Name of the new instance: ipc-ha
Please provide the path to a disk, partition, or qcow2/raw/vmdk image file: haos_ova-15.2.qcow2
Does the VM support UEFI booting? [default=yes]:
Does the VM support UEFI Secure Boot? [default=yes]: no
Instance to be created:
Name: ipc-ha
Project: default
Type: virtual-machine
Source: haos_ova-15.2.qcow2
Source format: qcow2
Config:
security.secureboot: "false"
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 1
Converting image "haos_ova-15.2.qcow2" to raw format before importing
Instance ipc-ha successfully created
启动 incus 容器
incus config set ipc-ha limits.cpu 2
incus config set ipc-ha limits.memory 2GiB
incus start ipc-ha
浏览器 访问 http://<ip>:8123
进入 home-assistant 的 web 界面