The command you've shared is used to write a specific amount of data to a drive at a controlled rate, simulating a data transfer process. Here's a breakdown of what it does:
pv is a command-line tool that is a terminal-based UI for monitoring the progress of data through a pipeline.
--rate-limit 100M limits the transfer rate to 100 MB/s.
-s {size_gb}G specifies the total size of the data to be transferred, in this case, {size_gb} gigabytes.
< /dev/zero provides a source of infinite zero-filled data.
dd of={drive_path} bs=1M status=none conv=fsync writes the data to the specified {drive_path} with a block size of 1 megabyte, and conv=fsync ensures that the data is written to disk.
If you're looking for alternatives to this command for similar purposes (e.g., throttling data transfer, writing to a drive), here are a few options:
Using dd with fallocate
If your goal is simply to create a file of a certain size on the target drive, you might use fallocate, which is much faster and doesn't require transferring data:
fallocate -l {size_gb}G {drive_path}
Alternative with dd and pv for Throttling
If you specifically need to throttle the write speed and monitor progress, you could stick with pv and dd, but explore other dd options:
pv --rate-limit 100M -s {size_gb}G < /dev/zero | dd of={drive_path} bs=1M oflag=sync status=none
Note the use of oflag=sync instead of conv=fsync, which can offer better performance in some cases.
Using fio
For more complex I/O operations, including throttling and detailed control over the I/O patterns, you might use fio:
fio --name=fill-device --readwrite=write --size={size_gb}G --blocksize=1M --iodepth=1 --runtime={runtime} --rate_iops=0 --rate_bps=100M --filename={drive_path} --output=fio.log
You'll need to calculate {runtime} based on your desired transfer rate and size. This example is more complex and allows for a lot of customization regarding I/O patterns.
Using dd with sleep for Simple Throttling
For a very simple, though less efficient or accurate, throttling:
dd if=/dev/zero of={drive_path} bs=1M count={size_gb} &
pid=$!
while kill -USR1 $pid 2>/dev/null; do
sleep 1
pkill -USR1 -P $pid
done
However, accurately controlling the write rate with this method can be difficult.
Conclusion
The best alternative depends on your specific requirements, such as the need for throttling, monitoring, and the type of data to be written. If you need a straightforward, high-speed fill of a device, fallocate might be best. For throttled writes with monitoring, sticking with or optimizing the pv and dd command might be most suitable.