Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virter vm commit error: "cannot open /etc/machine-id for writing: Permission denied" #29

Closed
mmguero opened this issue Oct 25, 2024 · 5 comments

Comments

@mmguero
Copy link
Contributor

mmguero commented Oct 25, 2024

Apologies if I'm missing something, I can't really find any examples or documentation on this.

I have a virter VM provisioned and running that I'd like to commit to an image. According to the virter vm commit --help the syntax should be:

  virter vm commit vm-name image-name

However, when I attempt this:

$ virter vm commit malcolm-191 malcolm-ready
INFO[0000] malcolm-191 err: truncate: cannot open '/etc/machine-id' for writing: Permission denied 
FATA[0000] Process exited with status 1                 

This is a debian-12 based image.

@mmguero
Copy link
Contributor Author

mmguero commented Oct 25, 2024

Hmmm... I wonder if the issue might be that when I ran virter vm run I used --user debian. Is there a way to override the user that was selected during the run stage when I try to do the commit?

@mmguero
Copy link
Contributor Author

mmguero commented Oct 25, 2024

What do you think about this: if this line fails, retry with sudo before giving up? Something like:

		// Starting the VM creates a machine ID.
		// We want these IDs to be unique, so reset to empty.
		err = v.VMExecShell(
			ctx, []string{vmName},
			&ProvisionShellStep{Script: "truncate -c -s 0 /etc/machine-id"})
		if err != nil {
			err = v.VMExecShell(
				ctx, []string{vmName},
				&ProvisionShellStep{Script: "sudo truncate -c -s 0 /etc/machine-id"})
			if err != nil {
				return err
			}
		}

@JoelColledge
Copy link
Member

Hmmm... I wonder if the issue might be that when I ran virter vm run I used --user debian. Is there a way to override the user that was selected during the run stage when I try to do the commit?

Sounds like a plausible explanation. The --user flag was introduced to allow the user to be set to "Administrator" for Windows VMs. It seems your usage of the flag hasn't been covered yet.

The simplest solution is just to create the VM without the --user flag and do everything in the VM as root.

You could also do the truncate -c -s 0 /etc/machine-id step yourself, e.g. using sudo, and then run virter vm commit --reset-machine-id=false ....

retry with sudo before giving up?

That's a change we could consider, yes.

mmguero added a commit to mmguero-dev/virter that referenced this issue Oct 28, 2024
…iving up (LINBIT#29). Also, fix a spelling error in the help messages.
@mmguero
Copy link
Contributor Author

mmguero commented Oct 28, 2024

Thanks for the explanation. I'll prepare a PR for my suggested change.

JoelColledge pushed a commit that referenced this issue Oct 30, 2024
… 'sudo' before giving up

If 'truncate' fails for /etc/machine-id, attempt with 'sudo' before giving up (#29). Also, fix a spelling error in the help messages.
@JoelColledge
Copy link
Member

Fixed by #31.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants