sfdisk:Linux命令之sfdisk命令 2024-05-02 15:21:24 0 0 一、命令简介 Linux sfdisk命令是硬盘分区工具程序。sfdisk有四种(主要)用途:列出分区的大小,列出设备上的分区,检查设备上的分区,以及-非常危险-重新分区设备。sfdisk不理解GUID分区表(GPT)格式,它不是为大分区设计的。在这些情况下,请使用更高级的GNU parted。parted使用见Linux命令之parted命令。 二、使用示例 1、获取命令帮助 [root@s151 ~]# sfdisk --help 2、查看命令版本 [root@s151 ~]# sfdisk --version sfdisk,来自 util-linux 2.23.2 3、查看所有分区信息 sfdisk会列出四个主分区,如果分区数量少于4个,会显示分区号,信息为空 [root@s151 ~]# sfdisk -l Disk /dev/sda: 61440 cylinders, 64 heads, 32 sectors/track Units: cylinders of 1048576 bytes, blocks of 1024 bytes, counting from 0 Device 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 空 … 4、查看指定分区大小 [root@s151 ~]# sfdisk -s /dev/sdb 20971520 5、验证磁盘分区 [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] 6、列出已知的分区类型 [root@s151 ~]# sfdisk -T Id Name 0 空 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 7、查看磁盘的CHS参数 [root@s151 ~]# sfdisk -g /dev/sda: 61440 cylinders, 64 heads, 32 sectors/track /dev/sdb: 20480 cylinders, 64 heads, 32 sectors/track 8、以便于分区输入方式显示硬盘分区的设置 [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 9、磁盘分区 [root@s151 ~]# sfdisk /dev/sdb <<EOF 1,1520,L 1521,L EOF Checking that no-one is using this disk right now … OK Disk /dev/sdb: 20480 cylinders, 64 heads, 32 sectors/track Old situation: Units: cylinders of 1048576 bytes, blocks of 1024 bytes, counting from 0 Device 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 0 Device 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 table Re-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。 三、使用语法及参数说明 1、使用语法 #sfdisk [选项] <设备> […] 2、参数说明参数选项参数说明-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 收藏(0)