multibootusb icon indicating copy to clipboard operation
multibootusb copied to clipboard

Error writing to disk - not displayed

Open JakubFojtik opened this issue 6 years ago • 23 comments

After clicking "Write image to USB" Multibootusb instantly reports that image has been written, but it has not. When i run the dd command manually I get "Error opening output file: 32 The process cannot access the file because it is being used by another process".

I think that is just a common Windows error (restarting explorer.exe fixed it), probably not solvable in Multiboot, but it should not say it finished succesfully. See attached multibootusb.log:

00:07:41.655 root INFO Executing ==> C:\Program Files (x86)\multibootusb\data\tools\dd\dd.exe if=D:\moje\antergos-18.2-x86_64.iso of=\\.\E: bs=1M --progress
00:07:41.686 root INFO Error writing to disk...
00:07:41.686 root INFO ISO has been written to USB disk...

JakubFojtik avatar May 09 '18 22:05 JakubFojtik

@JakubFojtik, were you able to boot off of the created usb stick after successfully writing to it? I can't. It seems to me "dd if=\.\k: ..." writes to the partition, not the disk containing the partition.

shinji-s avatar May 12 '18 20:05 shinji-s

@shinji-s I checked now and it does not boot from Multiboot's UI: isolinux.bin missing or corrupt. I believe it is because the \.\PhysicalDriveX path stops working see #372.

You can verify that the USB does boot if qemu-system-x86_64.exe -L . -boot c -hda //./k: is used instead of qemu-system-x86_64.exe -L . -boot c -hda //./PhysicalDriveX

JakubFojtik avatar May 12 '18 21:05 JakubFojtik

Thank you for checking and the tip about how to boot using QEMU. It appears we should dd onto //./PhysicalDriveX (if it exists) but I get 'permission denied error'.

shinji-s avatar May 12 '18 22:05 shinji-s

It turned out that my Windows 10 installation is probably bugged. It exhibits same symptom as described in https://community.spiceworks.com/topic/1899241-diskpart-clean-fails-cannot-zero-sectors-on-disk-all-flash-drives and just running syslinux.exe on an usb flash drive fails though doing the same on a removable hdd works. Need to fix my computer before completing the fix of this issue.

shinji-s avatar May 13 '18 08:05 shinji-s

@shiinji, I too have similar issue. dd was successful but failed to boot. Writing ISO to //./PhysicalDriveX is resulting in Access Denied error. Neither od=G: option which selects whole disk instead of partition appears to work resulting in same access denied error. The only working solution for me is to flash it with of=\\.\G: which of course does not boot and neither it produces boot error.

Does any one have the same issue?

mbusb avatar May 13 '18 11:05 mbusb

I have a thought. The Access Denied error could be related to some process/programs accessing USB silently in background. Similar error message appeared when the explorer.exe was open.

mbusb avatar May 13 '18 12:05 mbusb

When you guys say "does not boot" do you mean only via Multibootusb's GUI? Because other ways work for me at least. Just the Multiboot's "qemu.exe \.\PhysicalDrive1" does not work.

In my multibootusb.log dd uses "of=\.\E:" and the resulting USB is bootable, just not from the GUI. It boots with "qemu.exe \.\E:" when manually run in cmd.exe in qemu dir.

Do you run some antivirus software other than the default Defender? I do not, that may be a factor.

JakubFojtik avatar May 13 '18 13:05 JakubFojtik

@mbusb It seems to me Windows behaviour when writing to the sector zero has drastically changed recently. I wrote previously that I can run syslinux on an external HDD properly, but later I found out that the the partition table was hosed (from which I could recover thanks to testdisk utility). Could it be possible that Windows update released at the end of April has something to do with it?

FYI, rufus seems to have no trouble writing to a physical disk that dd/syslinux have trouble with. It takes more elaborate steps to write to a physical disk than simply opening \.\PhysicalDriveX. https://github.com/pbatard/rufus/blob/c84ff4d121aec42967174270812ff851c3f2b8f9/src/format.c#L1628

shinji-s avatar May 14 '18 07:05 shinji-s

Sorry, my assumption that writing to //./K: changes partition, not entire disk may be wrong. I'll follow up with more info once I have some evidence to confirm or deny.

shinji-s avatar May 14 '18 09:05 shinji-s

As I initially suspected, \.\K: refers to a partition, not the disk. Below is a test I run to confirm.

Sector content after formatting a USB flash disk.

* dd if=/dev/sdd bs=512 count=1 ... (On Linux)
C:\Users\shinj\Documents\src\multibootusb.adhoc>file after_format_mbr.bs
after_format_mbr.bs: DOS/MBR boot sector MS-MBR Windows 7 english at offset 0x163 "Invalid partition table" at offset 0x17b "Error loading operating system" at offset 0x19a "Missing operating system", disk signature 0x86b8be15; partition 1 : ID=0xc, start-CHS (0x0,2,3), end-CHS (0x1f0,254,63), startsector 128, 7986944 sectors

* dd if=/dev/sdd1 bs=512 count=1 ... (On Linux)
C:\Users\shinj\Documents\src\multibootusb.adhoc>file after_format_p1.bs
after_format_p1.bs: DOS/MBR boot sector, code offset 0x58+2, OEM-ID "MSDOS5.0", sectors/cluster 8, reserved sectors 816, Media descriptor 0xf8, sectors/track 63, heads 255, hidden sectors 128, sectors 7986944 (volumes > 32 MB) , FAT (32 bit), sectors/FAT 7784, reserved 0x1, serial number 0xdc67e9d7, unlabeled

* dd if=\\.\K: bs=512 count=1 ... (On Windows)
C:\Users\shinj\Documents\src\multibootusb.adhoc>file after_format_k.bs
after_format_k.bs: DOS/MBR boot sector, code offset 0x58+2, OEM-ID "MSDOS5.0", sectors/cluster 8, reserved sectors 816, Media descriptor 0xf8, sectors/track 63, heads 255, hidden sectors 128, sectors 7986944 (volumes > 32 MB) , FAT (32 bit), sectors/FAT 7784, serial number 0xdc67e9d7, unlabeled

So if=/dev/sdd1 and if=\.\k: seems to read the same sector.

Sector content after writing a iso image to \.\k

* dd if=/dev/sdd bs=512 count=1 ... (On Linux)
C:\Users\shinj\Documents\src\multibootusb.adhoc>file after_dd_mbr.bs
after_dd_mbr.bs: DOS/MBR boot sector MS-MBR Windows 7 english at offset 0x163 "Invalid partition table" at offset 0x17b "Error loading operating system" at offset 0x19a "Missing operating system", disk signature 0x86b8be15; partition 1 : ID=0xc, start-CHS (0x0,2,3), end-CHS (0x1f0,254,63), startsector 128, 7986944 sectors

* dd if=/dev/sdd1 bs=512 count=1 ... (On Linux)
C:\Users\shinj\Documents\src\multibootusb.adhoc>file after_dd_p1.bs
after_dd_p1.bs: DOS/MBR boot sector; partition 2 : ID=0xef, start-CHS (0x3ff,254,63), end-CHS (0x3ff,254,63), startsector 328, 6688 sectors

* dd if=\\.\K: bs=512 count=1 ... (On Windows)
C:\Users\shinj\Documents\src\multibootusb.adhoc>file after_dd_k.bs
after_dd_k.bs: DOS/MBR boot sector; partition 2 : ID=0xef, start-CHS (0x3ff,254,63), end-CHS (0x3ff,254,63), startsector 328, 6688 sectors

So MBR remains unchanged and the first sector of the partition get updated. if=/dev/sdd1 and if=\.\K: still generates same content.

After dding iso image to /dev/sdd using mbusb on LInux

* dd if=/dev/sdd bs=512 count=1 ... (On Linux)
C:\Users\shinj\Documents\src\multibootusb.adhoc>file after_dd_sdc_mbr.bs
after_dd_sdc_mbr.bs: DOS/MBR boot sector; partition 2 : ID=0xef, start-CHS (0x3ff,254,63), end-CHS (0x3ff,254,63), startsector 328, 6688 sectors

Now MBR gets update and seems to match the first sector of the partition before dding onto /dev/sdd.

shinji-s avatar May 14 '18 15:05 shinji-s

@JakubFojtik My stick after dding onto \.\K: does not boot even under a bare metal. (The same image/stick boots if I dd onto /dev/sdd on LInux). Possibly your stick boots because the MBR on your stick chain boots to the partition boot sector or you dded EFI bootable OS image and you are using an EFI machine. You may get different result if you wipe off the MBR before dding or use a BIOS machine.

I don't have any AV software running other than Microsoft provided one.

shinji-s avatar May 14 '18 16:05 shinji-s

@mbusb I wrote previously:

It turned out that my Windows 10 installation is probably bugged. It exhibits same symptom as described in https://community.spiceworks.com/topic/1899241-diskpart-clean-fails-cannot-zero-sectors-on-disk-all-flash-drives and just running syslinux.exe on an usb flash drive fails though doing the same on a removable hdd works. Need to fix my computer before completing the fix of this issue.

It seems to me Windows behaviour when writing to the sector zero has drastically changed recently. I wrote previously that I can run syslinux on an external HDD properly, but later I found out that the the partition table was hosed (from which I could recover thanks to testdisk utility).

Sorry, that was a false alarm. I forgot that I had eanbled this part of the code in my workspace. https://github.com/mbusb/multibootusb/blob/master/scripts/syslinux.py#L178 And quite likely that have lead to the strange Windows behavior and corruption of partition table.

Now what we should find is a way to write onto \\.\PhysicalDriveX.

shinji-s avatar May 14 '18 17:05 shinji-s

@shinji-s I can confirm that writing ISO to \\.\PhysicalDriveX works fine. Before hand, we have to get rid of the Access denied error. I did the following to do that:-

diskpart.exe select disk 1 clean exit

I could not find any api for doing it through python.

mbusb avatar May 15 '18 14:05 mbusb

@mbusb Thank you for the info. It appears that operation effectively unmounts the relevant volume(s). Rufus explicitly unmounts volumes (and deletes mount points) before formatting a drive. Here is an informative tip of theirs, https://github.com/pbatard/rufus/issues/759

shinji-s avatar May 16 '18 11:05 shinji-s

This commit should fix writing iso to entire disk under windows https://github.com/mbusb/multibootusb/commit/696b1ff8f003e99ae72e6a3be2f4de174f4b690f.

mbusb avatar May 17 '18 08:05 mbusb

Is the change brought by the past few commits an introduction of dd_win_clean_usb() and config.imager_return? I'm planning to move os dependent code back to osdriver.Widnows class.

shinji-s avatar May 17 '18 09:05 shinji-s

@shinji-s , Yes. Those were the changes. Make a pull request for merge.

mbusb avatar May 17 '18 10:05 mbusb

I've brought my devel branch in sync with mbusb/devel and tried writing an iso file. In the first attempt, dd exited immediately and the usb did not boot. The log is shown below. (diskpart cleaned the disk successfully.)

Physical Device Number is 2

Microsoft DiskPart バージョン 10.0.16299.15

Copyright (C) Microsoft Corporation. コンピューター: ESPRIMO-K553F

ディスク 2 が選択されました。(*1)

DiskPart はディスクを正常にクリーンな状態にしました。(*2)

DiskPart を終了しています... (*3) Executing ==> "C:\Users\shinj\Documents\src\multibootusb\data\tools\dd\dd.exe" if=C:\Users\shinj\Downloads\debian-9.4.0-amd64-netinst.iso of=\.\PhysicalDrive2 bs=1M --progress No USB disk found... No USB device found... No USB device found...

In the 2nd attempt, where I placed a sleep of 5 seconds after diskpart/clean, dd was successful and the usb booted fine but it became impossible to diskpart/clean again until I get the disk reinitialized using rufus. It seems more testing and investigation is needed.

shinji-s avatar May 18 '18 13:05 shinji-s

Got the following error during testing prior to sending a PR. Simultaneously to getting the error, explorer showed warning that the filesystem can't be recognized and asked to insert a media. It seems \.\PhysicalDriveX can go away in the middle of dding.

Physical Device Number is 2

Microsoft DiskPart バージョン 10.0.16299.15

Copyright (C) Microsoft Corporation. コンピューター: ESPRIMO-K553F

ディスク 2 が選択されました。

DiskPart はディスクを正常にクリーンな状態にしました。

DiskPart を終了しています... Executing => ['C:\Users\shinj\Documents\src\multibootusb\data\tools\dd\dd.exe', 'if=C:\Users\shinj\Downloads\openSUSE-Tumbleweed-NET-x86_64-Snapshot20180316-Media.iso', 'of=\\.\physicaldrive2', 'bs=1M', '--progress'] dd: rawwrite dd for windows version 0.6beta3. ] 6% dd: Written by John Newbigin [email protected] dd: This program is covered by terms of the GPL Version 2. dd: 8M Error writing file: 2 指定されたファイルが見つかりません。 dd: 9+0 records in dd: 8+0 records out Error writing iso image...

shinji-s avatar May 19 '18 07:05 shinji-s

I didn't experience such errors in yours and my commit. Tested with 4 different distros and all worked without crash. I think after changing the filesystem, windows doesn't recognize the disk and asking user to format...

On Sat 19 May, 2018, 1:25 PM Shinji Suzuki, [email protected] wrote:

Got the following error during testing prior to sending a PR. Simultaneously to getting the error, explorer showed warning that the filesystem can't be recognized and asked to insert a media. It seems .\PhysicalDriveX can go away in the middle of dding.

Physical Device Number is 2

Microsoft DiskPart バージョン 10.0.16299.15

Copyright (C) Microsoft Corporation. コンピューター: ESPRIMO-K553F

ディスク 2 が選択されました。

DiskPart はディスクを正常にクリーンな状態にしました。

DiskPart を終了しています... Executing => ['C:\Users\shinj\Documents\src\multibootusb\data\tools\dd\dd.exe', 'if=C:\Users\shinj\Downloads\openSUSE-Tumbleweed-NET-x86_64-Snapshot20180316-Media.iso', 'of=\.\physicaldrive2', 'bs=1M', '--progress'] dd: rawwrite dd for windows version 0.6beta3. ] 6% dd: Written by John Newbigin [email protected] dd: This program is covered by terms of the GPL Version 2. dd: 8M Error writing file: 2 指定されたファイルが見つかりません。 dd: 9+0 records in dd: 8+0 records out Error writing iso image...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mbusb/multibootusb/issues/368#issuecomment-390387601, or mute the thread https://github.com/notifications/unsubscribe-auth/AEC34M-ZT-rmmVpmAcJTtsCwv9vmgLVWks5tz8_hgaJpZM4T5Fme .

mbusb avatar May 19 '18 08:05 mbusb

I think after changing the filesystem, windows doesn't recognize the disk and asking user to format..

Yes. Windows asked for both inserting media and formatting the drive. (Each on different paritions?) I got the above error in all three trials using the suse iso though the number of blocks successfully written differ. The error from debian-9.4.0-amd64-netinst.iso is more sporadic with higher success rate.

shinji-s avatar May 19 '18 09:05 shinji-s

dd if=c.img of=\.\E: bs=512 count=1 Error opening output file: 32 The process cannot access the file because it is being used by another process who can save me , I was driven crazy by this error

CretaceousConstructor avatar May 13 '20 17:05 CretaceousConstructor

dd if=c.img of=.\E: bs=512 count=1 Error opening output file: 32 The process cannot access the file because it is being used by another process who can save me , I was driven crazy by this error

I find that newer version of DD has a dd if=c:\my files\boot.bin od=z: bs=512 count=1 command which do the job.

CretaceousConstructor avatar May 14 '20 02:05 CretaceousConstructor