adding partoff
This commit is contained in:
parent
6994a47211
commit
354abad454
1 changed files with 35 additions and 0 deletions
35
shell/partoff.sh
Executable file
35
shell/partoff.sh
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Calculate the optimal starting partition offset for a block device
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
if [[ $# -ne 1 ]] || [[ ! -d /sys/block/${1} ]]; then
|
||||
_BLKDEVS="["
|
||||
for ii in /sys/block/*; do
|
||||
_BLKDEVS+=" ${ii##*/}"
|
||||
done
|
||||
_BLKDEVS+=" ]"
|
||||
echo "Block devices detected: ${_BLKDEVS}"
|
||||
echo " Usage: $0 <block device>"
|
||||
echo " Example: $0 sda"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OPT=$(cat "/sys/block/${1}/queue/optimal_io_size")
|
||||
OFF=$(cat "/sys/block/${1}/alignment_offset")
|
||||
BLK=$(cat "/sys/block/${1}/queue/physical_block_size")
|
||||
|
||||
# shellcheck disable=SC2004
|
||||
if [[ ${OPT} -eq 0 ]]; then
|
||||
echo "Optimal I/O is zero, use 2048s (sectors)"
|
||||
else
|
||||
_RES=$(( ($OPT+$OFF)/$BLK ))
|
||||
# ensure minimum 2048s offset
|
||||
while [[ ${_RES} -lt 2048 ]]; do
|
||||
_RES=$(( ${_RES}+${_RES} ))
|
||||
done
|
||||
echo "Optimal I/O is set, use ${_RES}s (sectors)"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue