发布时间:2025-12-10 19:13:49 浏览次数:8
Linux命令之sfdisk命令「建议收藏」Linuxsfdisk命令是硬盘分区工具程序。sfdisk有四种(主要)用途:列出分区的大小,列出设备上的分区,检查设备上的分区,以及-非常危险-重新分区设备。sfdisk不理解GUID分区表(GPT)格式,它不是为大分区设计的。在这些情况下,请使用更高级的GNUparted。_sfdisk
Linux sfdisk命令是硬盘分区工具程序。sfdisk有四种(主要)用途:列出分区的大小,列出设备上的分区,检查设备上的分区,以及-非常危险-重新分区设备。sfdisk不理解GUID分区表(GPT)格式,它不是为大分区设计的。在这些情况下,请使用更高级的GNU parted。parted使用见Linux命令之parted命令。
[root@s151 ~]# sfdisk –help
[root@s151 ~]# sfdisk –version
sfdisk,来自 util-linux 2.23.2
sfdisk会列出四个主分区,如果分区数量少于4个,会显示分区号,信息为空
[root@s151 ~]# sfdisk -lDisk /dev/sda: 61440 cylinders, 64 heads, 32 sectors/track
Units: cylinders of 1048576 bytes, blocks of 1024 bytes, counting from 0Device Boot Start End #cyls #blocks Id System
/dev/sda1 * 1 1024 1024 1048576 83 Linux
sfdisk: start: (c,h,s) expected (1,0,1) found (0,32,33)sfdisk: end: (c,h,s) expected (1023,63,32) found (130,170,40)
/dev/sda2 1025 61439 60415 61864960 8e Linux LVM
sfdisk: start: (c,h,s) expected (1023,63,32) found (130,170,41)sfdisk: end: (c,h,s) expected (1023,63,32) found (1023,254,63)
/dev/sda3 0 – 0 0 0 空
/dev/sda4 0 – 0 0 0 空
…
[root@s151 ~]# sfdisk -s /dev/sdb
20971520
[root@s151 ~]# sfdisk -V /dev/sdb
Warning: no primary partition is marked bootable (active)
This does not matter for LILO, but the DOS MBR will not boot this disk.
/dev/sdb:OK
#如果检查试验fdisk命令分区的磁盘,提示如下
[root@s151 ~]# sfdisk -V /dev/sda2
Warning: start=2099200 – this looks like a partition rather than
the entire disk. Using fdisk on it is probably meaningless.
[Use the –force option if you really want this]
[root@s151 ~]# sfdisk -T
Id Name0 空
1 FAT12
2 XENIX root
3 XENIX usr
4 FAT16 <32M
5 扩展
6 FAT16
7 HPFS/NTFS/exFAT
8 AIX
…
fe LANstep
ff BBT
[root@s151 ~]# sfdisk -T |wc -l
100
[root@s151 ~]# sfdisk -g
/dev/sda: 61440 cylinders, 64 heads, 32 sectors/track
/dev/sdb: 20480 cylinders, 64 heads, 32 sectors/track
[root@s151 ~]# sfdisk -d
# partition table of /dev/sda
unit: sectors/dev/sda1 : start= 2048, size= 2097152, Id=83, bootable
/dev/sda2 : start= 2099200, size=123729920, Id=8e
/dev/sda3 : start= 0, size= 0, Id= 0
/dev/sda4 : start= 0, size= 0, Id= 0
# partition table of /dev/sdb
unit: sectors/dev/sdb1 : start= 0, size= 0, Id= 0
/dev/sdb2 : start= 0, size= 0, Id= 0
/dev/sdb3 : start= 0, size= 0, Id= 0
/dev/sdb4 : start= 0, size= 0, Id= 0
[root@s151 ~]# sfdisk /dev/sdb <<EOF
1,1520,L
1521,L
EOF
Checking that no-one is using this disk right now …
OKDisk /dev/sdb: 20480 cylinders, 64 heads, 32 sectors/track
Old situation:
Units: cylinders of 1048576 bytes, blocks of 1024 bytes, counting from 0Device Boot Start End #cyls #blocks Id System
/dev/sdb1 0 – 0 0 0 空
/dev/sdb2 0 – 0 0 0 空
/dev/sdb3 0 – 0 0 0 空
/dev/sdb4 0 – 0 0 0 空
New situation:
Units: cylinders of 1048576 bytes, blocks of 1024 bytes, counting from 0Device Boot Start End #cyls #blocks Id System
/dev/sdb1 1 1520 1520 1556480 83 Linux
/dev/sdb2 1521 20479 18959 19414016 83 Linux
/dev/sdb3 0 – 0 0 0 空
/dev/sdb4 0 – 0 0 0 空
Warning: no primary partition is marked bootable (active)
This does not matter for LILO, but the DOS MBR will not boot this disk.
Successfully wrote the new partition tableRe-reading the partition table …
If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
#磁盘分区时起始值为柱面值,可以通过如上截图查看磁盘的总共柱面数,一个柱面大小为1M。
#sfdisk [选项] <设备> […]
| 参数选项 | 参数说明 |
|---|---|
| -s, –show-size | 列出每个分区的大小 |
| -c, –id | 更改或打印分区 Id |
| –change-id | 更改 Id |
| –print-id | 打印 Id |
| -l, –list | 列出每个设备的分区 |
| -d, –dump | 同上,但以适合稍后输入的格式列出 |
| -i, –increment | 给柱面等计数时从 1 而非从 0 开始 |
| -u, –unit <字母> | 要使用的单位;<字母> 可以是以下之一,S (扇区),C (柱面),B (块) 或 M (MB) |
| -1, –one-only | 预留选项,目前没有作用 |
| -T, –list-types | 列出已知的分区类型 |
| -D, –DOS | 与 DOS 兼容;会浪费一点空间 |
| -E, –DOS-extended | 与 DOS 扩展分区兼容 |
| -R, –re-read | 让内核重新读取分区表 |
| -N <数字> | 只更改分区号为 <数字> 的分区 |
| -n | 并不真的写入磁盘 |
| -O <文件> | 将要覆盖的分区保存到 <文件> 中 |
| -I <文件> | 从 <文件> 恢复扇区 |
| -V, –verify | 检查列出扇区的有效性 |
| -v, –version | 显示版本信息并退出 |
| -h, –help | 显示此帮助并退出 |
| -f, –force | 禁止所有一致性检查 |
| –no-reread | 不检查分区是否正在使用 |
| -q, –quiet | 抑制警告消息输出 |
| -L, –Linux | 不报告与 Linux 无关的事情 |
| -g, –show-geometry | 打印内核检测到的几何属性 |
| -G, –show-pt-geometry | 打印从分区表推测出的几何属性 |
| -A, –activate[=<设备>] | 激活 可启动 标志 |
| -U, –unhide[=<设备>] | 取消分区隐藏 |
| -x, –show-extended | 输出时也列出扩展分区,或输入时请求提供它们的描述符 |
| –leave-last | 不分配最后一个柱面 |
| –IBM | 同 –leave-last |
| –in-order | 分区按顺序 |
| –not-in-order | 分区不按顺序 |
| –inside-outer | 所有逻辑分区位于最外的扩展分区内 |
| –not-inside-outer | 不要求所有逻辑分区位于最外的扩展分区内 |
| –nested | 每个分区与所有其他分区不相交 |
| –chained | 与 nested 相似,但扩展分区可以超界 |
| –onesector | 各分区互不相交 |
| -C, –cylinders <数字> | 设置要使用的柱面数 |
| -H, –heads <数字> | 设置要使用的磁头数 |
| -S, –sectors <数字> | 设置要使用的扇区数n |