WARNING!!
This post is LONG (sorry for that)
Here, I describe everything I did to test safe-dd, in great detail. Since I use Garuda Linux here, so I also included the information gathered about my desktop computer by garuda-inxi at the end, so here it all is:
Here is the script itself:
#!/bin/bash
# This script invokes the dd command to copy a file. It first checks to make sure
# the target file (of) is not mounted.
# Warning, this may not work with device names containing a space.
if [ $# -lt 2 ]
then
echo "Please provide an input file and an output file."
exit 1
fi
start=$(echo $@ | sed 's/of=/\^/')
end=$(echo $start | cut -f 2 -d '^')
target=$(echo $end | cut -f 1 -d ' ')
echo "Checking $target"
df | grep $target
if [ $? -eq 0 ]
then
echo "Output file $target is mounted. Refusing to continue."
exit 2
fi
echo "Executing nice dd $@ status=progress"
nice /usr/bin/dd $@ status=progress
sync
echo "Finished writing and sync."
Creared ~/Scripts directory.
copied safe-dd to my desktop PC.
Made it executable.
Ran lsblk without, then with the USB stick connected:
â•â”€ernie@Curiosity4 in ~ took 4ms
╰─λ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 1.8T 0 disk
├─sda1 8:1 0 500G 0 part
├─sda2 8:2 0 681.5G 0 part
└─sda3 8:3 0 681.5G 0 part
zram0 254:0 0 31.3G 0 disk [SWAP]
nvme0n1 259:0 0 931.5G 0 disk
├─nvme0n1p1 259:1 0 2G 0 part /boot/efi
├─nvme0n1p2 259:2 0 16M 0 part
├─nvme0n1p3 259:3 0 464.2G 0 part
└─nvme0n1p4 259:4 0 465.3G 0 part /home
/root
/var/cache
/var/tmp
/var/log
/srv
/
â•â”€ernie@Curiosity4 in ~ took 13ms
╰─λ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 1.8T 0 disk
├─sda1 8:1 0 500G 0 part
├─sda2 8:2 0 681.5G 0 part
└─sda3 8:3 0 681.5G 0 part
sdb 8:16 1 14.6G 0 disk
└─sdb1 8:17 1 14.6G 0 part
zram0 254:0 0 31.3G 0 disk [SWAP]
nvme0n1 259:0 0 931.5G 0 disk
├─nvme0n1p1 259:1 0 2G 0 part /boot/efi
├─nvme0n1p2 259:2 0 16M 0 part
├─nvme0n1p3 259:3 0 464.2G 0 part
└─nvme0n1p4 259:4 0 465.3G 0 part /home
/root
/var/cache
/var/tmp
/var/log
/srv
/
The USB stick is /dev/sdb.
I saved a copy of the post “A Safer Way to Use dd” to a text file.
I copied/pasted the text of the safe-dd script from my copy of the post to my safe-dd script to ensure I have an accurate copy here, and removed the line indents in the script file.
Downloaded the rescuezilla-2.4.2-64bit.jammy.iso file to the Downloads directory.
Using the following command to test safe-dd:
/home/ernie/Scripts/safe-dd if=/home/ernie/Downloads/rescuezilla-2.4.2-64bit.jammy.iso of-/dev/sdb
After running the command, I get the following output (same as what I get on my laptop PC):
â•â”€ernie@Curiosity4 in ~ as 🧙
╰─λ /home/ernie/Scripts/safe-dd if=/home/ernie/Downloads/rescuezilla-2.4.2-64bit.jammy.iso of-/dev/sdb
bash: /home/ernie/Scripts/safe-dd: cannot execute: required file not found
Output of garuda-inxi:
â•â”€ernie@Curiosity4 in ~ as 🧙 took 2s
[🔍] × garuda-inxi
System:
Kernel: 6.10.1-zen1-1-zen arch: x86_64 bits: 64 compiler: gcc
v: 14.1.1 clocksource: tsc avail: hpet,acpi_pm
parameters: root=UUID=ebf2e0f9-da67-44d2-b975-a1528f5be8c1 rw
rootflags=subvol=@ quiet loglevel=3 ibt=off iommu=pt
initrd=@\boot\initramfs-linux-zen.img
Desktop: KDE Plasma v: 6.1.3 tk: Qt v: N/A info: frameworks
v: 6.4.0 wm: kwin_wayland vt: 1 dm: SDDM Distro: Garuda
base: Arch Linux
Machine:
Type: Desktop System: ASUS product: N/A v: N/A
serial: <superuser required>
Mobo: ASUSTeK model: TUF GAMING A520M-PLUS WIFI v: Rev X.0x
serial: <superuser required> part-nu: SKU uuid: <superuser required>
UEFI: American Megatrends v: 3405 date: 12/13/2023
CPU:
Info: model: AMD Ryzen 5 5600X bits: 64 type: MT MCP arch: Zen 3+
gen: 4 level: v3 note: check built: 2022 process: TSMC n6 (7nm)
family: 0x19 (25) model-id: 0x21 (33) stepping: 2
microcode: 0xA20120E
Topology: cpus: 1x cores: 6 tpc: 2 threads: 12 smt: enabled cache:
L1: 384 KiB desc: d-6x32 KiB; i-6x32 KiB L2: 3 MiB desc: 6x512 KiB
L3: 32 MiB desc: 1x32 MiB
Speed (MHz): avg: 3655 high: 3718 min/max: 2200/4650
boost: enabled scaling: driver: acpi-cpufreq governor: performance
cores: 1: 3693 2: 3385 3: 3700 4: 3700 5: 3700 6: 3700 7: 3700
8: 3700 9: 3700 10: 3718 11: 3592 12: 3581 bogomips: 88642
Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a
ssse3 svm
Vulnerabilities: <filter>
Graphics:
Device-1: NVIDIA GP108 [GeForce GT 1030] vendor: Gigabyte
driver: nvidia v: 555.58.02 alternate: nouveau,nvidia_drm
non-free: 545.xx+ status: current (as of 2024-06; EOL~2026-12-xx)
arch: Pascal code: GP10x process: TSMC 16nm built: 2016-2021 pcie:
gen: 3 speed: 8 GT/s lanes: 4 ports: active: none off: HDMI-A-1
empty: DVI-D-1 bus-ID: 08:00.0 chip-ID: 10de:1d01 class-ID: 0300
Device-2: ARC Camera driver: snd-usb-audio,uvcvideo type: USB
rev: 2.0 speed: 480 Mb/s lanes: 1 mode: 2.0 bus-ID: 3-2:3
chip-ID: 05a3:9331 class-ID: 0102 serial: <filter>
Display: wayland server: X.org v: 1.21.1.13 with: Xwayland
v: 24.1.1 compositor: kwin_wayland driver: X: loaded: nvidia
unloaded: modesetting,nouveau alternate: fbdev,nv,vesa
gpu: nvidia,nvidia-nvswitch display-ID: 0
Monitor-1: HDMI-A-1 model: Samsung LC24RG50 serial: <filter>
built: 2021 res: 1920x1080 dpi: 92 gamma: 1.2
size: 532x304mm (20.94x11.97") diag: 613mm (24.1") ratio: 16:9
modes: max: 1920x1080 min: 640x480
API: Vulkan v: 1.3.279 layers: 4 device: 0 type: discrete-gpu
name: NVIDIA GeForce GT 1030 driver: nvidia v: 555.58.02
device-ID: 10de:1d01 surfaces: xcb,xlib,wayland device: 1
type: cpu name: llvmpipe (LLVM 18.1.8 256 bits)
driver: mesa llvmpipe v: 24.1.4-arch1.2 (LLVM 18.1.8)
device-ID: 10005:0000 surfaces: xcb,xlib,wayland
API: EGL Message: EGL data requires eglinfo. Check --recommends.
Audio:
Device-1: NVIDIA GP108 High Definition Audio vendor: Gigabyte
driver: snd_hda_intel v: kernel pcie: gen: 3 speed: 8 GT/s lanes: 4
bus-ID: 08:00.1 chip-ID: 10de:0fb8 class-ID: 0403
Device-2: AMD Starship/Matisse HD Audio vendor: ASUSTeK
driver: snd_hda_intel v: kernel pcie: gen: 4 speed: 16 GT/s
lanes: 16 bus-ID: 0a:00.4 chip-ID: 1022:1487 class-ID: 0403
Device-3: ARC Camera driver: snd-usb-audio,uvcvideo type: USB
rev: 2.0 speed: 480 Mb/s lanes: 1 mode: 2.0 bus-ID: 3-2:3
chip-ID: 05a3:9331 class-ID: 0102 serial: <filter>
API: ALSA v: k6.10.1-zen1-1-zen status: kernel-api tools: N/A
Server-1: PipeWire v: 1.2.1 status: active with: 1: pipewire-pulse
status: active 2: wireplumber status: active 3: pipewire-alsa
type: plugin 4: pw-jack type: plugin
tools: pactl,pw-cat,pw-cli,wpctl
Network:
Device-1: Realtek RTL8821CE 802.11ac PCIe Wireless Network Adapter
vendor: AzureWave driver: rtw_8821ce v: N/A modules: rtw88_8821ce
pcie: gen: 1 speed: 2.5 GT/s lanes: 1 port: e000 bus-ID: 06:00.0
chip-ID: 10ec:c821 class-ID: 0280
IF: wlp6s0 state: up mac: <filter>
Device-2: Realtek RTL8111/8168/8211/8411 PCI Express Gigabit
Ethernet vendor: ASUSTeK RTL8111H driver: r8169 v: kernel pcie:
gen: 1 speed: 2.5 GT/s lanes: 1 port: d000 bus-ID: 07:00.0
chip-ID: 10ec:8168 class-ID: 0200
IF: enp7s0 state: down mac: <filter>
Device-3: Realtek 802.11ax WLAN Adapter driver: rtl8852bu
type: USB rev: 3.0 speed: 5 Gb/s lanes: 1 mode: 3.2 gen-1x1
bus-ID: 4-3:3 chip-ID: 0bda:b832 class-ID: 0000 serial: <filter>
IF: wlp10s0f3u3 state: up mac: <filter>
Info: services: NetworkManager, smbd, systemd-timesyncd,
wpa_supplicant
Bluetooth:
Device-1: IMC Networks Bluetooth Radio driver: btusb v: 0.8
type: USB rev: 1.1 speed: 12 Mb/s lanes: 1 mode: 1.1 bus-ID: 1-5:3
chip-ID: 13d3:3556 class-ID: e001 serial: <filter>
Report: rfkill ID: hci0 rfk-id: 1 state: down
bt-service: not found rfk-block: hardware: no software: no
address: see --recommends
Drives:
Local Storage: total: 2.74 TiB used: 16.72 GiB (0.6%)
SMART Message: Required tool smartctl not installed. Check
--recommends
ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Samsung
model: SSD 970 EVO Plus 1TB size: 931.51 GiB block-size:
physical: 512 B logical: 512 B speed: 31.6 Gb/s lanes: 4 tech: SSD
serial: <filter> fw-rev: 2B2QEXM7 temp: 39.9 C scheme: GPT
ID-2: /dev/sda maj-min: 8:0 vendor: Seagate
model: ST2000DM008-2FR102 size: 1.82 TiB block-size:
physical: 4096 B logical: 512 B speed: 6.0 Gb/s tech: HDD
rpm: 7200 serial: <filter> fw-rev: 0001 scheme: GPT
ID-3: /dev/sdb maj-min: 8:16 vendor: ASolid model: USB
size: 14.65 GiB block-size: physical: 512 B logical: 512 B type: USB
rev: 3.2 spd: 5 Gb/s lanes: 1 mode: 3.2 gen-1x1 tech: N/A
serial: <filter> scheme: MBR
Partition:
ID-1: / raw-size: 465.26 GiB size: 465.26 GiB (100.00%)
used: 16.68 GiB (3.6%) fs: btrfs dev: /dev/nvme0n1p4 maj-min: 259:4
ID-2: /boot/efi raw-size: 2 GiB size: 2 GiB (99.95%)
used: 34.6 MiB (1.7%) fs: vfat dev: /dev/nvme0n1p1 maj-min: 259:1
ID-3: /home raw-size: 465.26 GiB size: 465.26 GiB (100.00%)
used: 16.68 GiB (3.6%) fs: btrfs dev: /dev/nvme0n1p4 maj-min: 259:4
ID-4: /var/log raw-size: 465.26 GiB size: 465.26 GiB (100.00%)
used: 16.68 GiB (3.6%) fs: btrfs dev: /dev/nvme0n1p4 maj-min: 259:4
ID-5: /var/tmp raw-size: 465.26 GiB size: 465.26 GiB (100.00%)
used: 16.68 GiB (3.6%) fs: btrfs dev: /dev/nvme0n1p4 maj-min: 259:4
Swap:
Kernel: swappiness: 10 (default 60) cache-pressure: 100 (default)
zswap: no
ID-1: swap-1 type: zram size: 31.26 GiB used: 0 KiB (0.0%)
priority: 100 comp: zstd avail: lzo,lzo-rle,lz4,lz4hc,842
max-streams: 12 dev: /dev/zram0
Sensors:
System Temperatures: cpu: 41.2 C mobo: N/A
Fan Speeds (rpm): N/A
Info:
Memory: total: 32 GiB available: 31.26 GiB used: 2.68 GiB (8.6%)
Processes: 318 Power: uptime: 34m states: freeze,mem,disk
suspend: deep avail: s2idle wakeups: 0 hibernate: platform
avail: shutdown, reboot, suspend, test_resume image: 12.46 GiB
services: org_kde_powerdevil,upowerd Init: systemd v: 256
default: graphical tool: systemctl
Packages: pm: pacman pkgs: 1451 libs: 430 tools: pamac,yay
Compilers: gcc: 14.1.1 Shell: garuda-inxi default: Bash v: 5.2.26
running-in: konsole inxi: 3.3.35
Garuda (2.6.26-1):
System install date: 2024-07-04
Last full system update: 2024-07-28 ↻
Is partially upgraded: No
Relevant software: snapper NetworkManager dracut nvidia-dkms
Windows dual boot: Probably (Run as root to verify)
Failed units:
I hope something I’ve posted here helps others help me with this issue,
UPDATE!
I found the solution for my issue. When I tried to run the safe-dd script, bash reported a “required file not found” error. Someone on another forum directed me to a stack overflow Linux forum post about the same issue I had. The solution presented there was to install and run the dos2unix package on the script file. That solution worked for me too, so I intend to add “Solved” to the title of this post.
By way of explanation, at some point, I must have opened/saved the script using Microsoft’s Notepad text editor (I dual-boot Garuda Linux with Microsoft Windows 11), thusly introducing carriage return/line feeds in place of the line feeds used in GNU/Linux/Unix. By running dos2unix on the script file, carriage return/line feeds were restored to line feeds, fixing the script.
Ernie