侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Linux命令集-fdisk

2023-11-06 星期一 / 0 评论 / 0 点赞 / 43 阅读 / 6672 字

fdisk命令用于观察硬盘实体使用情况,也可对硬盘分区。###语法[root@www ~]# fdisk [-l] 设备名称###参数-b:<分区大小>:指定每个分区的大小。-l:输出后面接的设备所有

fdisk命令用于观察硬盘实体使用情况,也可对硬盘分区。

###语法

[root@www ~]# fdisk [-l] 设备名称

###参数

-b:<分区大小>:指定每个分区的大小。-l:输出后面接的设备所有的分区内容,若仅有fdisk -l时,   则系统将会把整个系统内能够找到的设备的分区均列出来。-s:<分区编号>:将指定的分区大小输出到标准输出上,单位为区块。-u:搭配"-l"参数列表,会用分区数目取代柱面数目,来表示每个分区的起始地址。-v:显示版本信息。

###实例

首先选择要进行操作的磁盘:

[root@www ~]#fdisk /dev/sdb

输入m列出可以执行的命令

command (m for help) mCommand action   a   toggle a bootable flag   b   edit bsd disklabel   c   toggle the dos compatibility flag   d   delete a partition                      <==删除一个分区   l   list known partition types   m   print this menu   n   add a new partition                   <==新增一个分区   o   create a new empty DOS partition table   p   print the partition table              <==在屏幕上显示分区表   q   quit without saving changes       <==不存储,离开fdisk程度   s   create a new empty Sun disklabel   t   change a partition's system    u   change display/entry units   v   verify the partition table   w  table to disk and                        <==将刚才的操作写入分区表   x   extra functionality (experts only)

输入p列出磁盘目前的分区情况:

下半部的分区表信息主要列出每个分区的信息项目。每个项目的意思为:

  • Device: 设备文件名,依据不同的磁盘接口/分区位置而变。
  • Boot:表示是否为开机引导模块,通常Windows系统的C盘需要这模块。
  • Start,End:表示这个分区在哪个柱面号码之间,可以决定此分区的带下。
  • Blocks:就是以1k为单位的容量。
  • ID,System:代表这个分区内的文件系统应该是啥。不过这个项目只是一个提示而已,不见得真的代表此分区的文件系统。
Command (m for help): pDisk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1           1        8001   8e  Linux LVM/dev/sdb2               2          26      200812+  83  Linux

输入d然后选择分区,删除现有分区:

Command (m for help): pDisk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes   Device Boot      Start         End      Blocks   Id  SystemCommand (m for help):

输入n建立新的磁盘分区,首先建立两个主磁盘分区:

Command (m for help): nCommand action   e   extended   p   primary partition (1-4) //建立主分区pPartition number (1-4): 1First cylinder (1-391, default 1):   //分区的起始位置Using default value 1last  cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100 //分区结束位置,单位为柱面Command (m for help): nCommand action   e   extended   p   primary partition (1-4) pCommand action   e   extended   p   primary partition (1-4) Partition number (1-4): 2First cylinder (1-391, default 1):  Using default value 101Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M //分区结束位置,单位为M

确认分区建立成功:

Command (m for help): p Disk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1         100      803218+  83  Linux/dev/sdb2             101         125      200812+  83  Linux

再建立一个逻辑分区:

Command (m for help): nCommand action   e   extended   p   primary partition (1-4)e //选择扩展分区Partition number (1-4): 3First cylinder (126-391, default 126):Using default value 126Last cylinder or +size or +sizeM or +sizeK (126-391, default 391):Using default value 391

确认扩展分区建立成功:

Command (m for help): pDisk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1         100      803218+  83  Linux/dev/sdb2             101         125      200812+  83  Linux/dev/sdb3             126         391     2136645    5  Extended

在扩展分区上建立两个逻辑分区:

Command (m for help): nCommand action   l   logical (5 or over)   p   primary partition (1-4)l //选择逻辑分区First cylinder (126-391, default 126):Using default value 126Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M    Command (m for help): nCommand action   l   logical (5 or over)   p   primary partition (1-4)lFirst cylinder (176-391, default 176):Using default value 176Last cylinder or +size or +sizeM or +sizeK (176-391, default 391):Using default value 391

确认逻辑分区建立成功:

Command (m for help): pDisk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1         100      803218+  83  Linux/dev/sdb2             101         125      200812+  83  Linux/dev/sdb3             126         391     2136645    5  Extended/dev/sdb5             126         175      401593+  83  Linux/dev/sdb6             176         391     1734988+  83  LinuxCommand (m for help):

从上面的结果我们可以看到,在硬盘sdb我们建立了2个主分区(sdb1,sdb2),1个扩展分区(sdb3),2个逻辑分区(sdb5,sdb6) 注意:主分区和扩展分区的磁盘号位1-4,也就是说最多有4个主分区或者扩展分区,逻辑分区开始的磁盘号为5,因此在这个实验中试没有sdb4的。

最后对分区操作进行保存:

Command (m for help):wThe partition table has been altered!Calling ioctl() to re-read  partition table.Syncing disks.

广告 广告

评论区