#Bash 的 blkzone 命令
blkzone CMD [OPTION]... DEVICE
功能
管理和查看分区式(zoned)块设备的 zone 信息。
这种设备常见于:
- SMR 硬盘(Shingled Magnetic Recording)
- ZNS SSD(Zoned Namespace SSD)
普通硬盘 _______ _______ _______ __/_______\____/_______\____/_______\__ 叠瓦盘 _______ _______ _______ __/_______\____/_______\____/_______\__ _______ _______ _______ __/_______\____/_______\____/_______\__在这类设备上,随机写会覆相邻的磁道,磁盘被划分为多个 zone(区域),写入必须按顺序进行,因此需要专门工具管理。
类型
可执行文件(/usr/sbin/blkzone),属于 util-linux。
参数
OPTIONS选项:-o,--offset sector- 起始扇区-l,--length sectors- 长度(以扇区为单位)-c,--count count- 命令可操作的最大区域数-f,--force- 强制执行更改系统所用块设备上的区域状态的命令-v,--verbose- 显示报告中返回的区域数量或重置扇区范围--version- 显示版本-h,--help- 显示帮助-V,--version- 显示版本
DEVICE- 要操作的设备
#区域命令
| 命令 | 说明 |
|---|---|
report | 报告 zone 信息 |
capacity | 报告容量信息 |
reset | 将 zone 的写指针恢复到起始位置 |
open | 打开 zone,使其可以写入 |
close | 关闭 zone |
finish | 标记 zone 写入完成,写指针移动到末尾 |
#字段说明
| 字段 | 说明 |
|---|---|
start | zone 的起始扇区 |
len | zone 的大小 |
cap | zone 的容量 |
wptr | 写指针 |
reset | 建议重置写指针 |
non-seq | 非顺序写入资源处于活动状态 |
cond | zone 的状态 |
type | zone 的类型 |
#zone 的状态
| 状态 | 说明 |
|---|---|
cl | 关闭 |
nw | 未写入指针 |
em | 空 |
fu | 满 |
oe | 明确打开 |
oi | 隐式打开 |
ol | 离线 |
ro | 只读 |
x? | 保留状态 (不应报告) |
#示例
查看 zone 状态
$ sudo blkzone report /dev/sdb
zone 0
start: 0
size : 256MB
write pointer: 128MB
- 写指针在 128MB 处,只能在写指针之后写入
写入 zone
$ sudo blkzone open -o 0 -l 256M /dev/sdb # 打开一块区域(可能包含多个 zone)进行顺序写入
$ sudo dd if=data.bin of=/dev/sdb bs=4K # 写入数据
$ sudo blkzone finish -o 0 -l 256M /dev/sdb # 标记完成
#推荐阅读
#手册
BLKZONE(8) System Administration BLKZONE(8)
NAME
blkzone - run zone command on a device
SYNOPSIS
blkzone command [options] device
DESCRIPTION
blkzone is used to run zone command on device that support the Zoned
Block Commands (ZBC) or Zoned-device ATA Commands (ZAC). The zones to
operate on can be specified using the offset, count and length options.
The device argument is the pathname of the block device.
COMMANDS
report
The command blkzone report is used to report device zone information.
By default, the command will report all zones from the start of the
block device. Options may be used to modify this behavior, changing the
starting zone or the size of the report, as explained below.
Report output:
┌─────────┬────────────────────────────┐
| | |
| start | Zone start sector |
├─────────┼────────────────────────────┤
| | |
| len | Zone length in number of |
| | sectors |
├─────────┼────────────────────────────┤
| | |
| cap | Zone capacity in number of |
| | sectors |
├─────────┼────────────────────────────┤
| | |
| wptr | Zone write pointer |
| | position |
├─────────┼────────────────────────────┤
| | |
| reset | Reset write pointer |
| | recommended |
├─────────┼────────────────────────────┤
| | |
| non-seq | Non-sequential write |
| | resources active |
├─────────┼────────────────────────────┤
| | |
| cond | Zone condition |
├─────────┼────────────────────────────┤
| | |
| type | Zone type |
└─────────┴────────────────────────────┘
Zone conditions:
┌────┬──────────────────────────┐
| | |
| cl | Closed |
├────┼──────────────────────────┤
| | |
| nw | Not write pointer |
├────┼──────────────────────────┤
| | |
| em | Empty |
├────┼──────────────────────────┤
| | |
| fu | Full |
├────┼──────────────────────────┤
| | |
| oe | Explicitly opened |
├────┼──────────────────────────┤
| | |
| oi | Implicitly opened |
├────┼──────────────────────────┤
| | |
| ol | Offline |
├────┼──────────────────────────┤
| | |
| ro | Read only |
├────┼──────────────────────────┤
| | |
| x? | Reserved conditions |
| | (should not be reported) |
└────┴──────────────────────────┘
capacity
The command blkzone capacity is used to report device capacity
information.
By default, the command will report the sum, in number of sectors, of
all zone capacities on the device. Options may be used to modify this
behavior, changing the starting zone or the size of the report, as
explained below.
reset
The command blkzone reset is used to reset one or more zones. Unlike
sg_reset_wp(8), this command operates from the block layer and can
reset a range of zones.
open
The command blkzone open is used to explicitly open one or more zones.
Unlike sg_zone(8), open action, this command operates from the block
layer and can open a range of zones.
close
The command blkzone close is used to close one or more zones. Unlike
sg_zone(8), close action, this command operates from the block layer
and can close a range of zones.
finish
The command blkzone finish is used to finish (transition to full
condition) one or more zones. Unlike sg_zone(8), finish action, this
command operates from the block layer and can finish a range of zones.
By default, the reset, open, close and finish commands will operate
from the zone at device sector 0 and operate on all zones. Options may
be used to modify this behavior as explained below.
OPTIONS
The offset and length option arguments may be followed by the
multiplicative suffixes KiB (=1024), MiB (=1024*1024), and so on for
GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is optional, e.g., "K" has
the same meaning as "KiB") or the suffixes KB (=1000), MB (=1000*1000),
and so on for GB, TB, PB, EB, ZB and YB. Additionally, the 0x prefix
can be used to specify offset and length in hex.
-o, --offset sector
The starting zone specified as a sector offset. The provided offset
in sector units (512 bytes) should match the start of a zone. The
default value is zero.
-l, --length sectors
The maximum number of sectors the command should operate on. The
default value is the number of sectors remaining after offset. This
option cannot be used together with the option --count.
-c, --count count
The maximum number of zones the command should operate on. The
default value is the number of zones starting from offset. This
option cannot be used together with the option --length.
-f, --force
Enforce commands to change zone status on block devices used by the
system.
-v, --verbose
Display the number of zones returned in the report or the range of
sectors reset.
-h, --help
Display help text and exit.
-V, --version
Print version and exit.
AUTHORS
Shaun Tancheff <[email protected]>, Karel Zak <[email protected]>
SEE ALSO
sg_rep_zones(8)
REPORTING BUGS
For bug reports, use the issue tracker at
https://github.com/util-linux/util-linux/issues.
AVAILABILITY
The blkzone command is part of the util-linux package which can be
downloaded from Linux Kernel Archive
<https://www.kernel.org/pub/linux/utils/util-linux/>.
util-linux 2.39.3 2023-10-23 BLKZONE(8)