[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: writing iso file to usb stick with dd - garbled files - usb eject error?



On 8/2/25 18:33, Titus Newswanger wrote:
I recall reading somewhere how to send cached writes to disk using a shell command before unplugging a usb flash drive but now I'm failing to find it. Below follows why I think I need that:


Today I installed trixie, everything worked great except for a problem I ran into preparing the installer media. I usually run:

default@debian:~$ sudo dd if=/home/default/debian-trixie-DI-rc2-amd64- netinst.iso of=/dev/sdf status=progress bs=1M
[sudo] password for default:
778+0 records in
778+0 records out
815792128 bytes (816 MB, 778 MiB) copied, 242.327 s, 3.4 MB/s
default@debian:~$ cat /etc/debian_version
12.11
default@debian:~$ dd --version
dd (coreutils) 9.1

Strangely, it did not display status updates like it used to until after it completed. The disk did not even show up in thunar until after I unplugged then plugged it back into the usb port. Next strange thing was when I mounted the finished boot media, the directory contents looked normal, but the text files - readme, changelog, etc contents were garbled.

Attempted boot, grub came up with the usual options, I selected graphical install (the default) then kernel panic, with something like "initrd contained junk"

SHA512SUM on debian-trixie-DI-rc2-amd64-netinst.iso matched so the problem lies somewhere in my writing the media

retried with:

sudo dd if=/home/default/debian-trixie-DI-rc2-amd64-netinst.iso of=/dev/ sdf status=progress bs=1M conv=sync

same result


Next I performed some tests on my brand new very cheap usb 8GB flash drive = all ok.

Finally, I wrote my iso file to this flash drive using "Disk Image Writer" and everything worked like a charm. So now I wonder, what am I doing wrong with dd? I recall having a similar failure maybe two years ago. The rest of the time it just worked.


uh-oh here I found a clue... so I think this makes it seem like something wasn't finished writing when I pulled it from the usb.

sudo dmesg
[ snip ]
[40798.311928] usb 2-1.2: new high-speed USB device number 27 using xhci_hcd [40798.416473] usb 2-1.2: New USB device found, idVendor=abcd, idProduct=1234, bcdDevice= 1.00 [40798.416491] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[40798.416500] usb 2-1.2: Product: UDisk
[40798.416508] usb 2-1.2: Manufacturer: General
[40798.416515] usb 2-1.2: SerialNumber: 2312182347284409360901
[40798.417989] usb-storage 2-1.2:1.0: USB Mass Storage device detected
[40798.418491] scsi host7: usb-storage 2-1.2:1.0
[40799.444551] scsi 7:0:0:0: Direct-Access     General UDisk 5.00 PQ: 0 ANSI: 2
[40799.444763] sd 7:0:0:0: Attached scsi generic sg5 type 0
[40799.445225] sd 7:0:0:0: [sdf] 15728640 512-byte logical blocks: (8.05 GB/7.50 GiB)
[40799.445333] sd 7:0:0:0: [sdf] Write Protect is off
[40799.445335] sd 7:0:0:0: [sdf] Mode Sense: 0b 00 00 08
[40799.445453] sd 7:0:0:0: [sdf] No Caching mode page found
[40799.445455] sd 7:0:0:0: [sdf] Assuming drive cache: write through
[40799.446941]  sdf: sdf1 sdf2
[40799.447110] sd 7:0:0:0: [sdf] Attached SCSI removable disk
[41167.136643] usb 2-1.2: reset high-speed USB device number 27 using xhci_hcd
[41167.236475] usb 2-1.2: device firmware changed
[41167.236574] usb 2-1.2: USB disconnect, device number 27
[41167.252396] blk_print_req_error: 1324 callbacks suppressed
[41167.252405] device offline error, dev sdf, sector 1384200 op 0x1: (WRITE) flags 0x800 phys_seg 1 prio class 2
[41167.252423] buffer_io_error: 36796 callbacks suppressed
[41167.252426] Buffer I/O error on dev sdf, logical block 173025, lost async page write [41167.252625] device offline error, dev sdf, sector 1384216 op 0x1: (WRITE) flags 0x104000 phys_seg 30 prio class 2 [41167.252635] Buffer I/O error on dev sdf, logical block 173027, lost async page write
  [ deleted 7 similar lines ]
[41167.252669] Buffer I/O error on dev sdf, logical block 173035, lost async page write [41167.252707] device offline error, dev sdf, sector 1384456 op 0x1: (WRITE) flags 0x100000 phys_seg 1 prio class 2
  [ deleted 6 similar lines ]
[41167.253272] device offline error, dev sdf, sector 1385296 op 0x1: (WRITE) flags 0x100000 phys_seg 19 prio class 2
[41167.348915] ldm_validate_partition_table(): Disk read failed.
[41167.348941] Dev sdf: unable to read RDB block 0
[41167.348961]  sdf: unable to read partition table
[41167.536322] usb 2-1.2: new high-speed USB device number 28 using xhci_hcd
[41172.740486] usb 2-1.2: device descriptor read/64, error -110
[41172.948721] usb 2-1.2: New USB device found, idVendor=1e3d, idProduct=198a, bcdDevice= 1.00 [41172.948739] usb 2-1.2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[41172.950112] usb-storage 2-1.2:1.0: USB Mass Storage device detected
[41172.950452] scsi host7: usb-storage 2-1.2:1.0
[41194.784951] usb 2-1.2: reset high-speed USB device number 28 using xhci_hcd
[41480.585883] usb 2-1.2: USB disconnect, device number 28


Thank you for posting your console session.  Accurate information helps.


Assuming your ISO is correct and that you have downloaded the corresponding SHA512SUMS file, here is a console session from when I burned a Debian 11.3.0 amd64 ISO to a USB flash drive:

1.  Find the size of the ISO file in bytes -- size is 396361728 bytes:

2022-04-29 22:38:53 root@tinkywinky ~/hardware/adata/usb-flash-drive/***REDACTED*** # ll /home/dpchrist/samba/dpchrist/iso/debian/11.3.0/debian-11.3.0-amd64-netinst.iso -rwxr-xr-x 1 dpchrist dpchrist 396361728 2022-04-28 21:05:05 /home/dpchrist/samba/dpchrist/iso/debian/11.3.0/debian-11.3.0-amd64-netinst.iso

2. Convert size into a convenient block size and count for use with dd(1) -- block size is 1M (2**20 bytes) and count is 378 blocks:

2022-04-29 22:39:14 root@tinkywinky ~/hardware/adata/usb-flash-drive/***REDACTED***
# perl -e 'print 396361728/512/2048, "\n"'
378

3. Burn ISO to USB flash drive -- note bs, iflag, and oflag options. Today, I do not believe the oflag "noatime" option is needed:

2022-04-29 22:39:25 root@tinkywinky ~/hardware/adata/usb-flash-drive/***REDACTED*** # time dd if=/home/dpchrist/samba/dpchrist/iso/debian/11.3.0/debian-11.3.0-amd64-netinst.iso of=/dev/disk/by-id/usb-ADATA_USB_Flash_Drive_***REDACTED***-0\:0 bs=1M iflag=fullblock oflag=sync,noatime status=progress
394264576 bytes (394 MB, 376 MiB) copied, 76.1204 s, 5.2 MB/s
378+0 records in
378+0 records out
396361728 bytes (396 MB, 378 MiB) copied, 76.5701 s, 5.2 MB/s

real    1m16.582s
user    0m0.012s
sys     0m0.584s

4. Compute the SHA512 checksum of the blocks burned to the USB flash drive -- note bs, count, and iflag options:

2022-04-29 22:43:56 root@tinkywinky ~/hardware/adata/usb-flash-drive/***REDACTED*** # time dd if=/dev/disk/by-id/usb-ADATA_USB_Flash_Drive_***REDACTED***-0\:0 bs=1M count=378 iflag=fullblock | sha512sum
378+0 records in
378+0 records out
396361728 bytes (396 MB, 378 MiB) copied, 25.0641 s, 15.8 MB/s
2810f894afab9ac2631ddd097599761c1481b85e629d6a3197fe1488713af048d37241eb85def681ba86e62b406dd9b891ee1ae7915416335b6bb000d57c1e53 -

real    0m25.068s
user    0m3.468s
sys     0m0.720s

5. Verify the computed SHA256 checksum appears in the downloaded SHA512SUMS file:

2022-04-29 22:44:58 root@tinkywinky ~/hardware/adata/usb-flash-drive/***REDACTED*** # grep 2810f894afab9ac2631ddd097599761c1481b85e629d6a3197fe1488713af048d37241eb85def681ba86e62b406dd9b891ee1ae7915416335b6bb000d57c1e53 /home/dpchrist/samba/dpchrist/iso/debian/11.3.0/SHA512SUMS 2810f894afab9ac2631ddd097599761c1481b85e629d6a3197fe1488713af048d37241eb85def681ba86e62b406dd9b891ee1ae7915416335b6bb000d57c1e53 debian-11.3.0-amd64-netinst.iso


HTH,

David


Reply to: