Reset Incus VM root Password Without incus-agent
By chimo on (updated on )This is "part 2" of the Virtual Machines with Incus on an Alpine Linux Host blog post saga. In this blog post, we find a way to access the VM when the incus-agent isn't running.
2025-01-06 update: The solution to the incus-agent error was to install the "incus-agent" package on the host. The "incus-vm" package now depends on "incus-agent", so that step isn't necessary anymore. As long as the "incus-vm" package is installed on the host, "incus exec" should work as intended.
Of course, the next thing I did after starting the VM was: The I was greeted with after starting the VM, was:
incus exec alpine-vm -- sh
But then was greeted with:
Error: VM agent isn't currently running
After some sleuthing the web I was reminded of the “incus console” command, so gave that a shot. This was at the bottom of the output:
* Starting incus-agent-setup ... [ ok ]
* Starting incus-agent ... * start-stop-daemon: /run/incus_agent/incus-agent does not exist
* Failed to start incus-agent
[ !! ]
* ERROR: incus-agent failed to startWelcome to Alpine Linux 3.20 Kernel 6.6.68-0-virt on an x86_64 (/dev/console)
localhost login:
I tried to login using the default/common credentials (root:root, alpine:alpine, root:<blank>, root:alpine…) but nothing worked. It appears the root password isn’t set and the alpine user doesn’t exist (anymore?). All good things, but how do you get access to this thing now then?
My first thought was to chroot into the environment, so I navigated to “/var/lib/incus/virtual-machines/alpine-vm”. After listing the directory contents, I noticed there is no “rootfs” folder. Ah yes, this isn’t a container… VMs use images, and there is a “root.img” file that looks interesting.
I knew it’s possible to mount an .img file but the last time I did this was years ago. Back to web searching, I found this excellent forum post, which I’ll summarize in command form:
# Stop the VM
incus stop alpine-vm
# Print the partitions of the .img file
fdisk -l /var/lib/incus/virtual-machines/alpine-vm/root.img
Disk ./root.img: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 438F2735-BBFD-42BF-AB24-E40D80434790
Device Start End Sectors Size Type
./root.img1 2048 206847 204800 100M EFI System
./root.img2 206848 8388574 8181727 3.9G Linux filesystem
# Mount the .img file (offset "105906176" is 512 * 206848)
mount -o loop,offset=105906176 /var/lib/incus/virtual-machines/alpine-vm/root.img /mnt/
# chroot into the mounted VM img
chroot /mnt/
# Change the root password
passwd
Changing password for root
New password:
Retype password:
passwd: password for root changed by root
# Exit the chroot
exit
# Unmount .img
umount /mnt
# Start the VM
incus start alpine-vm
# Attach to console
incus console alpine-vm
# Login with the new password
localhost login: root
Password:
Welcome to Alpine!
...
localhost:~#
# Success!
I haven’t found the actual issue with the incus-agent not running, but now that I have access to the VM, I might be able to troubleshoot that.