Perhaps that’s a case of buggy package purge in older version of the package. I think there was such a bug at some point, snap-mgmt --purge would remove stuff under /var/lib/snapd/ but state.json was left behind. That was a bunch of releases back though.
Would manually clearing device-serial in state.json unblock it?
I just had this error in an Ubuntu lxc container which I launched and then immediately tried to snap install something in, via a script. I could insert an artificial delay between the container starting and me doing snap install but that feels rather kludgey. Shouldn’t snap install wait until the system is ready for snaps to be installed, rather than error out when the system isn’t quite ready? I thought the idea of a dependency based init system was that these kinds of issues didn’t happen?
The dependency based init doesn’t capture the fact that snapd is up but not really responding to most requests yet. It’s a particular design decision that snapd.service is the same thing that sets up the system for being operational.
What we’ve recommended to folks in similar situations is to use snap wait system seed.loaded as the first thing in all your scripts that try to use snap install, etc. Although that was always on core, but I imagine it should still be applicable to classic too