sudo icon indicating copy to clipboard operation
sudo copied to clipboard

DISM does not work properly when run with sudo

Open Stanzilla opened this issue 1 year ago • 16 comments

Sudo for Windows version

1.0.0

Windows build number

10.0.26100.0

Other Software

Note that it does work if you don't use sudo and just run DISM in an elevated shell.

Steps to reproduce

sudo dism /Online /Cleanup-Image /RestoreHealth

sudo is set to inline mode

Expected Behavior

DISM works

Actual Behavior

❯ sudo dism /Online /Cleanup-Image /RestoreHealth

Deployment Image Servicing and Management tool Version: 10.0.26100.1

Error: 31

An error occurred while creating the log file. Ensure that the path to the log file exists and that you have Read/Write permissions on the folder where the log files will be created.

Stanzilla avatar May 24 '24 23:05 Stanzilla

Huh. I can't seem to repro this locally. That's weird. Were you using sudo to run the command as another user/?

zadjii-msft avatar May 29 '24 19:05 zadjii-msft

Huh. I can't seem to repro this locally. That's weird. Were you using sudo to run the command as another user/?

Nope just as normal.

image

Disclaimer: I used a backported version from Canary on my beta branch OS before, then "updated" to 24H2 via downgrading my Insider membership to Release Preview.

Here is the properties of my sudo.exe

image

(no idea why the signature date is in German, just Windows things)

Stanzilla avatar May 29 '24 21:05 Stanzilla

Well, it's real promising that there's literally no other documentation on why this might happen

image

:shrug:

Like, absolute dumb sanity check - does dism work from an elevated console window?

did you drop that sudo.exe into system32? or into some other path/?

zadjii-msft avatar May 29 '24 21:05 zadjii-msft

Well, it's real promising that there's literally no other documentation on why this might happen

image

🤷

Like, absolute dumb sanity check - does dism work from an elevated console window?

did you drop that sudo.exe into system32? or into some other path/?

Yeah it works from an elevated console window just fine and I did the same google search before filing the issue haha

image image

Here's what that sudo points to, is that the correct version? I'm pretty sure I just dropped it in there yeah.

Stanzilla avatar May 29 '24 21:05 Stanzilla

Huh. I can't seem to repro this locally. That's weird. Were you using sudo to run the command as another user/?

Nope just as normal.

image

Disclaimer: I used a backported version from Canary on my beta branch OS before, then "updated" to 24H2 via downgrading my Insider membership to Release Preview.

Here is the properties of my sudo.exe

image

(no idea why the signature date is in German, just Windows things)

About the timestamp, in my case, it uses my local language. Which is English. Do you have other languages installed on your system?

image

AvogatoWizardWhisker avatar May 30 '24 09:05 AvogatoWizardWhisker

But yeah, I also have one user on my computer, I received the same error code (31). I tested all configuration sudo offers.

AvogatoWizardWhisker avatar May 30 '24 09:05 AvogatoWizardWhisker

GandalfThisfoeGIF

I'm gonna reach out to the owners of dism.exe. See if they can't help me track down why this might be.

zadjii-msft avatar May 30 '24 14:05 zadjii-msft

Wait what the heck image

In a VM: works like a charm on my real dev box? no dice.

zadjii-msft avatar May 30 '24 15:05 zadjii-msft

Okay we may be onto a lead: on my dev box, sudo cmd, then dism /Online /Cleanup-Image /RestoreHealth from in the CMD that's now running elevated? That works.

zadjii-msft avatar May 30 '24 16:05 zadjii-msft

as a workaround, running the command like this sudo pwsh {dism /Online /Cleanup-Image /RestoreHealth} works normally... Is this how sudo was designed to be with pwsh?

AvogatoWizardWhisker avatar May 30 '24 17:05 AvogatoWizardWhisker

I'm not an expert at Windows programming, but from what I understand DISM calls CreateFileW to create dism.log. I can't reproduce this, though I have an unorthodox setup where I manually inserted the necessary registry keys to get sudo to work on a non-Insider build of Windows

I'm not sure why it would return error 31. I suspect that if the permissions of a directory are set to something like SYSTEM then sudo could be unable to perform actions inside of that directory, though I created a C file with CreateFileW and it worked fine inside of a directory owned by SYSTEM. could you provide the permissions on C:/Windows/Logs/DISM and anything that might be relevant in Event Viewer?

elijah-wright avatar Jun 09 '24 04:06 elijah-wright

I was looking around the dism.log after i run sudo and i noticed there are a lot of providers don't support does not support CreateDismImage on C:\ - CGenericImagingManager::CreateDismImage. I'll share the log when I'm free.

Edit: I can finally share the logs from dism. Each logs have specific sudo configuration. dismForceNewWindow.log dismInline.log dismDisableInput.log

Although they don't provide enough details on why dism failed

AvogatoWizardWhisker avatar Jun 09 '24 21:06 AvogatoWizardWhisker

Okay this is MSFT:51791454 internally

zadjii-msft avatar Jun 13 '24 19:06 zadjii-msft

Okay we may be onto a lead: on my dev box, sudo cmd, then dism /Online /Cleanup-Image /RestoreHealth from in the CMD that's now running elevated? That works.

For some reason it doesn't work for me with this method image

AvogatoWizardWhisker avatar Jun 14 '24 16:06 AvogatoWizardWhisker

I've also encountered this on 24H2 (release channel). Workaround for me right now is sudo cmd then run dism commands from the new shell

MolotovCherry avatar Oct 26 '24 21:10 MolotovCherry

Encountered this as well on 24H2, I have to run an elevated command prompt to run it.

UltimatePlayer97 avatar Jun 15 '25 06:06 UltimatePlayer97