设为首页 收藏本站
查看: 1204|回复: 0

[经验分享] Linux命令之fdisk

[复制链接]

尚未签到

发表于 2019-2-17 11:09:53 | 显示全部楼层 |阅读模式
  fdisk
  fdisk [选项]   改变分区表
  fdisk [选项] –l   列出所有分区表
  fdisk –s   以分区块为单位,给出指定分区的大小
  这是一个创建和维护分区的命令,兼容DOS类型的分区表、BSD或SUN类型的磁盘列表。
  相关了解:
  磁头数(Heads)表示硬盘有几个磁头,也就是有几面盘片,一个硬盘最多有255个磁头
  柱面数(Cylinders)表示硬盘每面盘片上有几条磁道
  扇区数(Sectors)表示每条磁道上有几个扇区,每条磁道最多有63个扇区
  (1).选项
  -b   指定扇区大小(512,1024,2048或4096 B)
  -c  关闭DOS兼容模式
  -u   以扇区编号取代柱面编号来表示每个分区的起始地址,一般与-l选项联合使用
  -C   指定柱面编号
  -H   指定磁头编号
  -S   指定磁道扇区编号
  (2).菜单操作说明:
  a 设置可引导标记(活动分区/引导分区之间切换)
  b 编辑BSD磁盘标签
  c 设置DOS操作系统兼容标记(兼容/不兼容之间切换)
  d 删除一个分区
  l 显示已知的分区类型,其中82为Linux swap分区,83为Linux分区
  m 显示帮助信息
  n 增加一个新的分区
  o 创建一个新的空白的DOS分区表
  p 显示磁盘当前的分区表
  q 退出fdisk程序,不保存任何修改
  s 创建一个新的空白的Sun磁盘标签
  t 改变一个分区的系统ID,就是改变分区类型(比如把Linux Swap分区改为Linux分区)
  u 改变显示或输入单位
  v 验证磁盘分区表
  w 将分区表写入磁盘并退出(保存并退出)
  x 额外功能(专家级)
  (3).实例
  sda和hda的区别
  sd代表的是SCSI,SATA接口硬盘
  hd代表IDE接口的硬盘
  sda和hda最后面的a都代表的是第一块硬盘
  sda1和hda1则代表的是该硬盘的第一分区
  fdisk -l
  /盘/dev/sda:107.4G,107374182400字节(B),255个磁头,63个扇区,13054柱面(磁道) 1单位=16065柱面(磁道)512=8225280字节(B) 扇区大小(逻辑/物理):512字节(B)/512字节(B)输入/输出大小(最小/最佳):512字节(B)/512字节(B)磁盘标识:0x00079700/Disk /dev/sda: 107.4 GB, 107374182400 bytes
  255 heads, 63 sectors/track, 13054 cylinders
  Units = cylinders of 16065  512 = 8225280 bytes

  Sector>
  I/O>
  Disk>  /设备     启动标识  开始位置 结束位置  分区块的大小  分区ID  系统(分区类型)  /dev/sda1       1     64     512000     83    Linux 分区1不以柱面边界结束 /dev/sda2        64    13055   104344576   8e    Linux LVM/

  Device Boot      Start         End      Blocks  >  /dev/sda1   *           1          64      512000   83  Linux
  Partition 1 does not end on cylinder boundary.
  /dev/sda2              64       13055   104344576   8e  Linux LVM
  Disk /dev/sdb: 21.5 GB, 21474836480 bytes
  255 heads, 63 sectors/track, 2610 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes

  Sector>
  I/O>
  Disk>  Disk /dev/mapper/vg_centos6-lv_root: 53.7 GB, 53687091200 bytes
  255 heads, 63 sectors/track, 6527 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes

  Sector>
  I/O>
  Disk>  Disk /dev/mapper/vg_centos6-lv_swap: 4194 MB, 4194304000 bytes
  255 heads, 63 sectors/track, 509 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes

  Sector>
  I/O>
  Disk>  Disk /dev/mapper/vg_centos6-lv_home: 49.0 GB, 48964304896 bytes
  255 heads, 63 sectors/track, 5952 cylinders
  Units = cylinders of 16065 512 = 8225280 bytes

  Sector>
  I/O>
  Disk>  fdisk -lu
  Disk /dev/sda: 107.4 GB, 107374182400 bytes
  255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors
  Units = sectors of 1  512 = 512 bytes

  Sector>
  I/O>
  Disk>
  Device Boot      Start         End      Blocks  >  /dev/sda1   *        2048     1026047      512000   83  Linux
  Partition 1 does not end on cylinder boundary.
  /dev/sda2         1026048   209715199   104344576   8e  Linux LVM
  Disk /dev/sdb: 21.5 GB, 21474836480 bytes
  255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
  Units = sectors of 1 * 512 = 512 bytes

  Sector>
  I/O>
  Disk>  Disk /dev/mapper/vg_centos6-lv_root: 53.7 GB, 53687091200 bytes
  255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
  Units = sectors of 1 * 512 = 512 bytes

  Sector>
  I/O>
  Disk>  Disk /dev/mapper/vg_centos6-lv_swap: 4194 MB, 4194304000 bytes
  255 heads, 63 sectors/track, 509 cylinders, total 8192000 sectors
  Units = sectors of 1 * 512 = 512 bytes

  Sector>
  I/O>
  Disk>  Disk /dev/mapper/vg_centos6-lv_home: 49.0 GB, 48964304896 bytes
  255 heads, 63 sectors/track, 5952 cylinders, total 95633408 sectors
  Units = sectors of 1 * 512 = 512 bytes

  Sector>
  I/O>
  Disk>  你们也看到了,我的/dev/sdb还没有开始使用,下面就用这个硬盘简单的演示下fdisk主要用到的操作菜单
  创建一个新的分区
  [root@CentOS6 桌面]# fdisk /dev/sdb
  Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

  Building a new DOS disklabel with disk>  Changes will remain in memory only, until you decide to write them.
  After that, of course, the previous content won't be recoverable.
  Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
  WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
  switch off the mode (command 'c') and change display units to
  sectors (command 'u').
  Command (m for help): n
  Command action
  e   extended            //扩展分区,创建扩展分区会占用一个主分区,并且只有创建扩展分区后才能创建逻辑分区
  p   primary partition (1-4)   //主分区,最多创建4个
  e
  Partition number (1-4): 1
  First cylinder (1-2610, default 1):   //起始柱面,默认为1
  Using default value 1
  Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):   //终止柱面,默认为最后一个数
  Using default value 2610
  Command (m for help): n
  Command action
  l   logical (5 or over)    //逻辑分区
  p   primary partition (1-4)  //主分区
  l
  First cylinder (1-2610, default 1): 1
  Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G  //终止柱面不仅可以用柱面数表示,还可以用+[数值][单位]的格式表示
  Command (m for help): n
  Command action
  l   logical (5 or over)
  p   primary partition (1-4)
  l
  First cylinder (1307-2610, default 1307):
  Using default value 1307
  Last cylinder, +cylinders or +size{K,M,G} (1307-2610, default 2610):
  Using default value 2610
  Command (m for help): p
  Disk /dev/sdb: 21.5 GB, 21474836480 bytes
  255 heads, 63 sectors/track, 2610 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes

  Sector>
  I/O>
  Disk>
  Device Boot      Start         End      Blocks  >  /dev/sdb1               1        2610    20964793+   5  Extended
  /dev/sdb5               1        1306    10490382   83  Linux
  /dev/sdb6            1307        2610    10474348+  83  Linux

  Command (m for help):  w      //写入磁盘,保存并退出,否则之前的操作都无效。如果不想写入磁盘就使用qThe partition table has been>  同样在/dev/sdb下操作, 删除一个分区
  [root@CentOS6 桌面]# fdisk /dev/sdb
  WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
  switch off the mode (command 'c') and change display units to
  sectors (command 'u').
  Command (m for help): p
  Disk /dev/sdb: 21.5 GB, 21474836480 bytes
  255 heads, 63 sectors/track, 2610 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes

  Sector>
  I/O>
  Disk>
  Device Boot      Start         End      Blocks  >  /dev/sdb1               1        2610    20964793+   5  Extended
  /dev/sdb5               1        1306    10490382   83  Linux
  /dev/sdb6            1307        2610    10474348+  83  Linux
  Command (m for help): d
  Partition number (1-6): 6  //这里输入的始分区编号,如果删除扩展分区,那扩展分区下的逻辑分区也会被删除
  Command (m for help): p
  Disk /dev/sdb: 21.5 GB, 21474836480 bytes
  255 heads, 63 sectors/track, 2610 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes

  Sector>
  I/O>
  Disk>
  Device Boot      Start         End      Blocks  >  /dev/sdb1               1        2610    20964793+   5  Extended
  /dev/sdb5               1        1306    10490382   83  Linux
  Command (m for help): w

  The partition table has been>  Calling ioctl() to re-read partition table.
  Syncing disks.
  最后展示下修改分区类型
  WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
  switch off the mode (command 'c') and change display units to
  sectors (command 'u').
  Command (m for help): t
  Partition number (1-5): 5  //操作哪一个分区
  Hex code (type L to list codes): L  //这里会提示你使用L查看类型列表
  0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
  1  FA×××2           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
  2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
  3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
  4  FA×××6

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-673515-1-1.html 上篇帖子: linux文件的时间及类型 下篇帖子: LINUX修改文件权限
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表