Install lxd-agent manually on custom OS?

Hi, I am using VyOS on LXD, which is based on Debian11. but their system image doesn’t have LXD-agent, so I am losing many functions, is there are a proper way to install lxd-agent?

You can install below two serivces to install lxd-agent:

  1. lxd-agent-9p
    cat > /lib/systemd/system/lxd-agent-9p.service << EOF
    [Unit]
    Description=LXD - agent - 9p mount
    Documentation=https://linuxcontainers.org/lxd
    ConditionPathExists=/dev/virtio-ports/org.linuxcontainers.lxd
    After=local-fs.target
    DefaultDependencies=no
    
    [Service]
    Type=oneshot
    RemainAfterExit=yes
    ExecStartPre=-/sbin/modprobe 9pnet_virtio
    ExecStartPre=/bin/mkdir -p /run/lxd_config/9p
    ExecStartPre=/bin/chmod 0700 /run/lxd_config/
    ExecStart=/bin/mount -t 9p config /run/lxd_config/9p -o access=0,trans=virtio
    
    [Install]
    WantedBy=multi-user.target
    EOF
    
  2. lxd-agent
    cat > /lib/systemd/system/lxd-agent.service << EOF
    [Unit]
    Description=LXD - agent
    Documentation=https://linuxcontainers.org/lxd
    ConditionPathExists=/dev/virtio-ports/org.linuxcontainers.lxd
    Requires=lxd-agent-9p.service
    After=lxd-agent-9p.service
    Before=cloud-init.target cloud-init.service cloud-init-local.service
    DefaultDependencies=no
    
    [Service]
    Type=simple
    WorkingDirectory=/run/lxd_config/9p
    ExecStart=/run/lxd_config/9p/lxd-agent
    Restart=on-failure
    RestartSec=5s
    StartLimitInterval=60
    StartLimitBurst=10
    
    [Install]
    WantedBy=multi-user.target
    EOF
    
  3. Enable lxd-agent-9p and lxd-agent
    systemctl enable lxd-agent-9p.service
    systemctl enable lxd-agent.service
    

You can losetup your rootfs image, chroot and do above steps.

Thank you for your help first, but it seems that this is the way to do in custom LXC container, but not KVM VM?

------------------ Original ------------------

it’s for vm image. BTW, you need to make sure your guest kernel has 9p module support.