0

我正在尝试编写一个 dd.sh,它只支持这两种情况:

1: clone a device to an img file, with compression (gzip)
2: clone a an img file to a device, with de-compression (gunzip)

我更喜欢对话 UI 以获得更好的进度状态。
我主要在 Ubuntu/Linux 中使用它,所以,不需要与 macos 兼容。

下面是我的 dd.sh:

#!/bin/zsh

input="$1"
output="$2"

if [[ "$input" = *'.img' ]] && [[ "$output" = *'/dev/'* ]]
then
    (pv -n "$input" | gunzip -c | dd of="$output" bs=128M conv=notrunc,noerror) 2>&1 | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0
elif [[ "$output" = *'.img' ]] && [[ "$input" = *'/dev/'* ]] 
then
    (pv -n "$input" | gzip -c | dd of="$output" bs=128M conv=notrunc,noerror) 2>&1 | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0
fi

我测试了它

./dd.sh /media/psf/Home/software/tinypilot-voyager-2.3.2-2022-01-10T1531Z.img /dev/sdc

但什么也没发生,它很快就结束了,没有写入 /dev/sdc

img 文件有点大,所以它不应该立即结束。

du -sh /media/psf/Home/software/tinypilot-voyager-2.3.2-2022-01-10T1531Z.img
2.3G    /media/psf/Home/software/tinypilot-voyager-2.3.2-2022-01-10T1531Z.img

更新:我对 dd.sh 做了一个小改动

#!/bin/zsh

input="$1"
output="$2"

if [[ "$input" = *'.img' ]] && [[ "$output" = *'/dev/'* ]]
then
    (pv -n "$input" | dd of="$output" bs=128M conv=notrunc,noerror) 2>&1 | gunzip -c | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0
elif [[ "$output" = *'.img' ]] && [[ "$input" = *'/dev/'* ]] 
then
    (pv -n "$input" | dd of="$output" bs=128M conv=notrunc,noerror) 2>&1 | gzip -c | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0
fi

这一次,它似乎工作了,因为我注意到 /dev/sdc 确实正在编写。但是,需要很长时间才能完成。

4

0 回答 0