我可以用来parted找出图像的偏移量。
sudo parted -s image.img unit B print
Model: (file)
Disk /home/user/image.img: 107374182400B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 2097152B 107374182399B 107372085248B primary ext4
Run Code Online (Sandbox Code Playgroud)
例如,分区从 开始2097152。
2097152我怎样才能用 bash 脚本得到它?
我可能可以解析输出,但也许有更合适的方法?
一种选择是将输出提供给awk
sudo parted -s image.img unit B print |
awk '/^Number/{p=1;next}; p{gsub(/[^[:digit:]]/, "", $2); print $2}'
Run Code Online (Sandbox Code Playgroud)