我正在尝试创建一个进度条或某种加载图标来显示正在创建哈希,而不是没有任何反应的空白屏幕......这是我目前所拥有的:
if [[ $hashing != "y" && $hashing != "Y" ]]; then
echo -e "\n"
sudo dd if=dev/"$source" | md5sum
read -r compareresult
i=1
sp="/-\|"
echo -n ' '
while true
do
printf "\b${sp:i++%${#sp}:1}"
done
exit
fi ;;
这使用旋转轮来表示加载图标。使用上面的方法确实有效。但目前不行?不确定顺序是否不正确,或者我是否遗漏了什么。任何帮助都将不胜感激
#!/bin/bash
#Clone_Command
while true
do
sudo -s
echo "==========================="
echo " Clone Command "
echo "==========================="
echo -e "\n"
echo -e "\n"
echo "Enter 1 for source device"
echo "Enter 'a' to hash source device"
echo "Enter 2 for destination device"
echo "Enter 3 to list all available disks"
echo "Enter 4 to execute dd command"
echo "Enter 5 to compare MD5 hashes"
echo "Enter q to exit"
echo -e "\n"
echo "PLEASE NOTE LISTING ALL DISKS WILL REQUIRE YOU TO RELOAD THE SCRIPT"
echo -e "\n"
echo -e "Enter your choice \c"
read -r choice
case "$choice" in
q) exit;;
1) echo -e "Enter source device '/dev/---'
Enter the last 3 letters of the device eg - sdf or sdb etc"
read -r source ;;
a) echo -e "Hashing this device may take a while depending on size"
echo -e "\n"
echo -e "Press enter if you wish to hash this device"
read -r hashing
if [[ $hashing != "y" && $hashing != "Y" ]]; then
echo -e "\n"
sudo dd if=dev/"$source" | md5sum
read -r compareresult
i=1
sp="/-\|"
echo -n ' '
while true
do
printf "\b${sp:i++%${#sp}:1}"
done
exit
fi ;;
2) echo -e "Enter destination device '/dev/---'
Enter the last 3 letters of the device eg - sdf or sdb etc"
read -r destination ;;
3) echo -e "Press enter to list all available disks \c"
read -r answ
if [[ $answ != "y" && $answ != "Y" ]]; then
clear
sudo lshw -class disk
exit
fi ;;
4) echo -e "This will format $destination. If you wish to continue press enter \c"
read -r ans
if [[ $ans != "y" && $ans != "Y" ]]; then
echo -e "\n"
sudo dd if=/dev/"$source" of=/dev/"$destination" bs=4096 status=progress
exit
fi ;;
5) echo -e "If you wish to compare MD5 Hash of both USBs then press 'Enter'\c"
read -r compare
if [[ $compare != "y" && $compare != "Y" ]]; then
echo -e "\n"
echo -e "Please note this is not a quick process"
echo -e "n"
md5sum -c <<<"$compareresult /dev/$destination"
fi ;;
esac
done
答案1
进度视图pv
您的概念存在一个普遍问题,因为即使标称尺寸相同,USB 驱动器的尺寸也会略有不同,这会影响整个设备的 md5sum。
- 如果你检查每个分区的 md5sum,即可检查原件和克隆件是否相同。
- 另一种方法是存储图像文件并使用 md5sum 和图像的大小应用于棍棒上(使用 dd 检查与图像文件中的字节数完全相同)。
pv
例如,您可以使用进度视图来代替微调器
$ sudo pv /dev/sdc | md5sum
29,8GiB 0:13:46 [37,0MiB/s] [================================================>] 100%
2372da0e77d754a912078af8e47b36c9 -
$
最好只检查相关分区,
$ lsblk -f /dev/sdc
NAME FSTYPE LABEL UUID MOUNTPOINT
sdc
├─sdc1
├─sdc2 vfat 34D9-D113
├─sdc3 ext4 3c66d05d-bc02-4a1e-baca-e227a161e345
└─sdc4 crypto_LUKS 371f0cbc-3f6f-49dd-9fc4-4cdf91cb15c9
在本例中为分区 #4,
$ sudo pv /dev/sdc4 | md5sum
1,66GiB 0:00:46 [36,2MiB/s] [================================================>] 100%
35d33ae006c90b47b2e7b9aacb7f9bd7 -
请记住卸载检查 md5sum 之前,检查 USB 记忆棒上的分区。
克隆驱动器并保证安全
您可以使用以下方法将一个 USB 设备克隆到另一个 USB 设备(或卡或 SSD,任何大容量存储设备)穆库斯布-杜斯还使用pv
是否已安装和watch-flush
监控克隆操作的进度。假设源驱动器是sdx
,运行
dus /dev/sdx
它将帮助您识别正确的目标驱动器(帮助您避免覆盖错误的驱动器),因此您不必在命令行上指定目标。