@stgraber I have imported a HUGE raw image into an incus VM with incus-migrate. Problem is that incus-agent is not loaded on the image and it is not getting an IP. Is there any workaround to being able to connect to it?
Imagine that it’s not a virtual server but a real machine standing on your desk. You are having a look and don’t see any VGA/HDMI slot, the only plugs are Ethernet cable and power. What would you do to fix that PC?
My first step would be switching off power, dismounting a HDD and connecting it into an other machine under my control and careful inspection of the reasons why IP configuration does not work as expected.
Yes: serial console and VGA console. Once logged in, then you can configure IP manually, and fetch whatever else you want to fetch.
To install incus-agent in a VM which doesn’t have it, I made the following script (I don’t know if there’s a more “official” way)
# Based on https://github.com/lxc/distrobuilder/blob/distrobuilder-3.0/generators/incus-agent.go
cp incus-agent.service /lib/systemd/system/incus-agent.service
ln -s /lib/systemd/system/incus-agent.service /etc/systemd/system/multi-user.target.wants/incus-agent.service
cp incus-agent-setup /lib/systemd/incus-agent-setup
cp 99-incus-agent.rules /lib/udev/rules.d/99-incus-agent.rules
where these are the source files being copied:
incus-agent.service
[Unit]
Description=Incus - agent
Documentation=https://linuxcontainers.org/incus/docs/main/
ConditionPathExistsGlob=/dev/virtio-ports/org.linuxcontainers.*
Before=cloud-init.target cloud-init.service cloud-init-local.service
DefaultDependencies=no
[Service]
Type=notify
WorkingDirectory=-/run/incus_agent
ExecStartPre=/lib/systemd/incus-agent-setup
ExecStart=/run/incus_agent/incus-agent
Restart=on-failure
RestartSec=300
StartLimitInterval=60
StartLimitBurst=10
[Install]
WantedBy=multi-user.target
incus-agent-setup
#!/bin/sh
set -eu
PREFIX="/run/incus_agent"
# Functions.
mount_virtiofs() {
mount -t virtiofs config "${PREFIX}/.mnt" >/dev/null 2>&1
}
mount_9p() {
/sbin/modprobe 9pnet_virtio >/dev/null 2>&1 || true
/bin/mount -t 9p config "${PREFIX}/.mnt" -o access=0,trans=virtio,size=1048576 >/dev/null 2>&1
}
fail() {
umount -l "${PREFIX}" >/dev/null 2>&1 || true
rmdir "${PREFIX}" >/dev/null 2>&1 || true
echo "${1}"
exit 1
}
# Setup the mount target.
umount -l "${PREFIX}" >/dev/null 2>&1 || true
mkdir -p "${PREFIX}"
mount -t tmpfs tmpfs "${PREFIX}" -o mode=0700,size=50M
mkdir -p "${PREFIX}/.mnt"
# Try virtiofs first.
mount_virtiofs || mount_9p || fail "Couldn't mount virtiofs or 9p, failing."
# Copy the data.
cp -Ra "${PREFIX}/.mnt/"* "${PREFIX}"
# Unmount the temporary mount.
umount "${PREFIX}/.mnt"
rmdir "${PREFIX}/.mnt"
# Fix up permissions.
chown -R root:root "${PREFIX}"
# Legacy.
if [ ! -e "${PREFIX}/incus-agent" ] && [ -e "${PREFIX}/lxd-agent" ]; then
ln -s lxd-agent "${PREFIX}"/incus-agent
fi
exit 0
99-incus-agent.rules
ACTION=="add", SYMLINK=="virtio-ports/org.linuxcontainers.incus", TAG+="systemd"
SYMLINK=="virtio-ports/org.linuxcontainers.incus", RUN+="/bin/systemctl start incus-agent.service"
# Legacy.
ACTION=="add", SYMLINK=="virtio-ports/org.linuxcontainers.lxd", TAG+="systemd"
SYMLINK=="virtio-ports/org.linuxcontainers.lxd", RUN+="/bin/systemctl start incus-agent.service"
As another option, I believe it is possible to attach the agent as an ISO disk as documented here:
You can generate an
agent
configuration ISO which will contain the agent binary, configuration files and installation scripts. This is required for environments where9p
isn’t supported and where an alternative way to load the agent is required.This source type is applicable only to VMs.
To add such a device, use the following command:
incus config device add <instance_name> <device_name> disk source=agent:config