码迷,mamicode.com
首页 > 系统相关 > 详细

linux命令:fdisk

时间:2016-10-29 02:21:35      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:fdisk 磁盘分区   管理磁盘分区 格式化 删除分区

   fdisk命令简介:

     查看当前系统识别了几块硬盘或者对磁盘进行分区操作。

  VFS:virtual file system 虚拟文件系统

1.命令格式:

 fdisk [options] <disk>     对硬盘进行分区

 fdisk [options] -l <disk>   列出硬盘的分区信息

 fdisk -s <partition>      显示分区的大小

 fdisk -l  查看当前系统中所有的硬盘分区

[root@xuelinux ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0001e9b8

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26        1046     8192000   83  Linux

/dev/sda3            1046        1556     4096000   83  Linux

/dev/sda4            1556        2611     8477696    5  Extended

/dev/sda5            1556        1811     2048000   83  Linux

/dev/sda6            1811        2066     2048000   83  Linux

/dev/sda7            2066        2258     1536000   82  Linux swap / Solaris 

 格式化:mkfs -t ext3 /path 格式化成ext3类型的文件系统

  2.命令功能: 

    查看当前系统识别了几块硬盘或者管理硬盘分区

 管理磁盘分区:

 fdisk /dev/sda

    p:显示当前硬件的分区,包括没保存的改动

    n:创建新分区 

       e:扩展分区

       p:主分区

    d:删除一个分区

    w:保存退出

    q:不保存退出

    t:修改分区类型

       L:在t状态下查看所以支持的类型

    l:显示所支持的所有类型

partprobe 通知内核重读分区表,使新建的分区能被读到。

cat /pro/partitions  查看内核已读到的分区表,只有被内核识别到的分区才能进行格式化,挂载等操作

root@xuelinux ~]# cat /proc/partitions 

major minor  #blocks  name


   8        0   20971520 sda

   8        1     204800 sda1

   8        2    8192000 sda2

   8        3    4096000 sda3

   8        4          1 sda4

   8        5    2048000 sda5

   8        6    2048000 sda6

   8        7    1536000 sda7


3.命令参数:

 -b <size>                扇区大小 (512, 1024, 2048 or 4096)

 -c                        switch off DOS-compatible mode

 -h                        显示帮助

 -u <size>                 显示出扇区中柱面大小

 -v                        print version

 -C <number>               specify the number of cylinders

 -H <number>               specify the number of heads

 -S <number>               specify the number of sect

4.命令实例:

   1、演示新建一个分区,删除一个分区,修改分区类型。 

  fdisk /dev/sda

[root@xuelinux ~]# fdisk /dev/sda

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  新建分区,如果是个新硬盘会提示新建主分区(p)或者是扩展分区(e)

First cylinder (2258-2611, default 2258):   输入起始柱面默认即可

Using default value 2258

Last cylinder, +cylinders or +size{K,M,G} (2258-2611, default 2611): +1G  创建一个1G分区

Command (m for help): t    t修改分区类型

Partition number (1-8): 8

Hex code (type L to list codes): L   L查看系统支持的分区类型


 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        

 1  FAT12           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  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx         

 5  Extended        42  SFS             86  NTFS volume set da  Non-FS data

Hex code (type L to list codes): 82   输入分区类型

Changed system type of partition 8 to 82 (Linux swap / Solaris)


Command (m for help): p  显示已经建立好的分区表


Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0001e9b8


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26        1046     8192000   83  Linux

/dev/sda3            1046        1556     4096000   83  Linux

/dev/sda4            1556        2611     8477696    5  Extended

/dev/sda5            1556        1811     2048000   83  Linux

/dev/sda6            1811        2066     2048000   83  Linux

/dev/sda7            2066        2258     1536000   82  Linux swap / Solaris

/dev/sda8            2258        2389     1059691   82  Linux swap / Solaris

sda8即为刚才新建立的分区

ommand (m for help): w   w保存退出新建分区建立成功

The partition table has been altered!

Calling ioctl() to re-read partition table.

[root@xuelinux ~]# partprobe    partprobe通知内核重读分区表,让内核识别新建的分区

[root@xuelinux ~]# cat /proc/partitions 

major minor  #blocks  name

   8        0   20971520 sda

   8        1     204800 sda1

   8        2    8192000 sda2

   8        3    4096000 sda3

   8        4          1 sda4

   8        5    2048000 sda5

   8        6    2048000 sda6

   8        7    1536000 sda7

   8        8    1024000 sda8   内核已经识别到新建分区,只有识别到了分区才能进行格式化、挂载等操作。


 

本文出自 “学linux历程” 博客,请务必保留此出处http://woyaoxuelinux.blog.51cto.com/5663865/1866987

linux命令:fdisk

标签:fdisk 磁盘分区   管理磁盘分区 格式化 删除分区

原文地址:http://woyaoxuelinux.blog.51cto.com/5663865/1866987

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!