hypriot / flash

Command line script to flash SD card images of any kind
MIT License
1k stars 176 forks source link

pv can't show progress properly #148

Open sonnyhcl opened 5 years ago

sonnyhcl commented 5 years ago

https://github.com/hypriot/flash/blob/0b28b5cb525ad27707d4eb57cb54f98b9e3ccdb5/flash#L632

In my use case, the progress soon gets 100% but the dd command is still working at 10MB/s. It seems the image is preloaded in memory.

clhu@t5 ~/w/f/sample> flash --userdata static.yml -d /dev/sdd ~/Downloads/installer/hypriotos-rpi-v1.10.0.img 

Is /dev/sdd correct? y
Unmounting /dev/sdd ...
Flashing /home/clhu/Downloads/installer/hypriotos-rpi-v1.10.0.img to /dev/sdd ...
1000MiB 0:00:02 [ 400MiB/s] [=========================================================>] 100%
sonnyhcl commented 5 years ago

Actually, dd is now providing a progress flag to tell you the progress.

status=LEVEL
              The LEVEL of information to print to stderr; 'none' suppresses
              everything but error messages, 'noxfer' suppresses the final
              transfer statistics, 'progress' shows periodic transfer
              statistics

https://github.com/hypriot/flash/blob/0b28b5cb525ad27707d4eb57cb54f98b9e3ccdb5/flash#L628-L637 It's time to change this using progress flag

echo "Flashing ${image} to ${rawdisk} ..." 
sudo dd bs=$bs_size status=progress "if=${image}" "of=${rawdisk}" 
shafer commented 4 years ago

I don't think it is pv that is the problem. I think the problem is that dd needs flags to bypass cache(s) so that writes don't appear to finish super fast and you see the real progress. I added oflag=direct iflag=fullblock to my dd options and then the progress looks correct. I don't know if macOS supports those options. If there is interest I'm game to make a PR that adds support to the script so that the progress shown by pv reflects reality.