首页 > 系统服务 > 详细

Linux系统磁盘分区

时间:2015-10-28 17:28:12      阅读:272      评论:0      收藏:0      [点我收藏+]

 

Linux系统磁盘分区实例

 

   简述:在Linux系统中常见的磁盘分区工具有fdisk和parted,而且在企业工作中也经常使用到,下面先介绍fdisk磁盘分区工具。

 

fdisk

fdisk命令说明:用于查看磁盘使用情况,也可查看新增且未分区的磁盘情况和对磁盘进行分区。

命令语法:

fdisk [参数] [设备]

常用参数

描述

-u

默认是分区表,是由units 换成sectors

-c

关闭DOS兼容模式

-l

列出指定的设备

1.fdisk 分区实例:

[root@CentOS66-15 /]# fdisk /dev/sdb        #fdisk 将/dev/sdb分区

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x2656c6b6.

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‘).

 

提示:

输入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‘).

第一个:建议关闭DOS兼容模式

第二个:如果把units(柱面)改成sectors(扇区)就用-u.

注意:CentOS5.x系列没有这个提示,也就是说CentOS5.x系列是按照柱面的,Centos6.x系列按照扇区划分,所以可以做调整。

 

磁盘分区实例要求:/dev/sdb 创建6个分区,分别为:(1P+1E(5L))

/dev/sdb1,/dev/sdb5, /dev/sdb6, /dev/sdb7, /dev/sdb8, /dev/sdb9

Linux系统命令行操作:

[root@CentOS66-15 /]# fdisk -cu /dev/sdb  #fdisk -cu指定/dev/sdb分区

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x14806a23.

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)

 

Command (m for help): m                     #打印菜单

Command 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             #退出不保存

   s   create a new empty Sun disklabel

   t   change a partition‘s system id          #修改分区类型

   u   change display/entry units

   v   verify the partition table

   w   write table to disk and exit   #保存并退去

   x   extra functionality (experts only)

 

Command (m for help): p     #查看磁盘分区表

 

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 size (logical/physical): 512 bytes / 512 bytes

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

Disk identifier: 0x14806a23

 

   Device Boot      Start         End      Blocks   Id  System 

Command (m for help): n     #新建分区

Command action

   e   extended          #创建扩展分区

   p   primary partition (1-4)#创建主分区

p                    #输入p,创建主分区

Partition number (1-4): 1   #输入主分区编号1

First sector (2048-41943039, default 2048):  #这是为什么就开始就设置扇区是因为-u的原因,(2048-41943039)是范围,default 2048 从2048开始分区

Using default value 2048   #直接回车是默认2048

Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10M          #结束分区,默认回车,是给全部,另外可以使用+sectors or +size{K,M,G}指定分区大小,+10M给10M

Command (m for help): p     #查看分区表,已经创建了一个

 

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 size (logical/physical): 512 bytes / 512 bytes

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

Disk identifier: 0x14806a23

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83  Linux

#设备名            起始的扇区   结束的扇区    Blocks ID  分区类型

 

Command (m for help): n     #再创建分区

Command action

   e   extended

   p   primary partition (1-4)

e                #输入e,创建扩展分区

Partition number (1-4): 2   #扩展分区编号2

First sector (22528-41943039, default 22528): #默认回车从22528开始分区

Using default value 22528

Last sector, +sectors or +size{K,M,G} (22528-41943039, default 41943039):         #默认回车全部剩余空间给扩展分区

Using default value 41943039

Command (m for help): p     #打印分区列表,已创建扩展分区

 

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 size (logical/physical): 512 bytes / 512 bytes

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

Disk identifier: 0x14806a23

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83  Linux

/dev/sdb2           22528    41943039    20960256    5  Extended

 

#以下再创建5个逻辑分区

Command (m for help): n

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l                #输入l创建逻辑分区

First sector (24576-41943039, default 24576):

Using default value 24576

Last sector, +sectors or +size{K,M,G} (24576-41943039, default 41943039): +10M           #分给逻辑分区10M

Command (m for help): p     #查看磁盘分区表,逻辑分区编号从/dev/sdb5开始

 

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 size (logical/physical): 512 bytes / 512 bytes

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

Disk identifier: 0x14806a23

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83  Linux

/dev/sdb2           22528    41943039    20960256    5  Extended

/dev/sdb5           24576       45055       10240   83  Linux

 

#下面再创建4个逻辑分区,步骤一样

Command (m for help): n

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l

First sector (47104-41943039, default 47104):

Using default value 47104

Last sector, +sectors or +size{K,M,G} (47104-41943039, default 41943039): +10M

 

Command (m for help): p

 

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 size (logical/physical): 512 bytes / 512 bytes

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

Disk identifier: 0x14806a23

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83  Linux

/dev/sdb2           22528    41943039    20960256    5  Extended

/dev/sdb5           24576       45055       10240   83  Linux

/dev/sdb6           47104       67583       10240   83  Linux

 

Command (m for help): n

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l

First sector (69632-41943039, default 69632):

Using default value 69632

Last sector, +sectors or +size{K,M,G} (69632-41943039, default 41943039): +10M

 

Command (m for help): p

 

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 size (logical/physical): 512 bytes / 512 bytes

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

Disk identifier: 0x14806a23

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83  Linux

/dev/sdb2           22528    41943039    20960256    5  Extended

/dev/sdb5           24576       45055       10240   83  Linux

/dev/sdb6           47104       67583       10240   83  Linux

/dev/sdb7           69632       90111       10240   83  Linux

 

Command (m for help): n

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l

First sector (92160-41943039, default 92160):

Using default value 92160

Last sector, +sectors or +size{K,M,G} (92160-41943039, default 41943039): +10M

 

Command (m for help): p

 

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 size (logical/physical): 512 bytes / 512 bytes

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

Disk identifier: 0x14806a23

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83  Linux

/dev/sdb2           22528    41943039    20960256    5  Extended

/dev/sdb5           24576       45055       10240   83  Linux

/dev/sdb6           47104       67583       10240   83  Linux

/dev/sdb7           69632       90111       10240   83  Linux

/dev/sdb8           92160      112639       10240   83  Linux

 

Command (m for help): n

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l

First sector (114688-41943039, default 114688):

Using default value 114688

Last sector, +sectors or +size{K,M,G} (114688-41943039, default 41943039): +10M

 

Command (m for help): p

 

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 size (logical/physical): 512 bytes / 512 bytes

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

Disk identifier: 0x14806a23

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83  Linux

/dev/sdb2           22528    41943039    20960256    5  Extended

/dev/sdb5           24576       45055       10240   83  Linux

/dev/sdb6           47104       67583       10240   83  Linux

/dev/sdb7           69632       90111       10240   83  Linux

/dev/sdb8           92160      112639       10240   83  Linux

/dev/sdb9          114688      135167       10240   83  Linux

 

#下面演示创建一个分区然后删除

Command (m for help): n     #再创建逻辑分区

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l

First sector (137216-41943039, default 137216):

Using default value 137216

Last sector, +sectors or +size{K,M,G} (137216-41943039, default 41943039): +100M

 

Command (m for help): p     #已创建了分区/dev/sdb10

 

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 size (logical/physical): 512 bytes / 512 bytes

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

Disk identifier: 0x14806a23

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83  Linux

/dev/sdb2           22528    41943039    20960256    5  Extended

/dev/sdb5           24576       45055       10240   83  Linux

/dev/sdb6           47104       67583       10240   83  Linux

/dev/sdb7           69632       90111       10240   83  Linux

/dev/sdb8           92160      112639       10240   83  Linux

/dev/sdb9          114688      135167       10240   83  Linux

/dev/sdb10         137216      342015      102400   83  Linux

 

Command (m for help): d         #输入d删除分区

Partition number (1-10): 10    #输入10删除/dev/sdb10分区

 

Command (m for help): p     #查看磁盘分区表,/dev/sdb10已被删除。

 

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 size (logical/physical): 512 bytes / 512 bytes

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

Disk identifier: 0x14806a23

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83  Linux

/dev/sdb2           22528    41943039    20960256    5  Extended

/dev/sdb5           24576       45055       10240   83  Linux

/dev/sdb6           47104       67583       10240   83  Linux

/dev/sdb7           69632       90111       10240   83  Linux

/dev/sdb8           92160      112639       10240   83  Linux

/dev/sdb9          114688      135167       10240   83  Linux

 

Command (m for help): 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   

 6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .

 7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility  

 8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt        

 9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access    

 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O       

 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor     

 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs       

 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT           

 f  W95 Ext‘d (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/

10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b

11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor     

12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor     

14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary 

16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS   

17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE

18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto

1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep       

1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT           

1e  Hidden W95 FAT1

 

Command (m for help): t     #调整分区类型

Partition number (1-9): 9   #调整9分区

Hex code (type L to list codes): 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   

 6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .

 7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility  

 8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt        

 9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access    

 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O       

 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor     

 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs       

 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT           

 f  W95 Ext‘d (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/

10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b

11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor     

12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor     

14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary 

16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS   

17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE

18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto

1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep       

1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT           

1e  Hidden W95 FAT1

Hex code (type L to list codes): 8e    #调整为8e

Changed system type of partition 9 to 8e (Linux LVM)

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 size (logical/physical): 512 bytes / 512 bytes

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

Disk identifier: 0x14806a23

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1           2       10240   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sdb2               2        2611    20960256    5  Extended

Partition 2 does not end on cylinder boundary.

/dev/sdb5               2           3       10240   83  Linux

/dev/sdb6               3           5       10240   83  Linux

/dev/sdb7               5           6       10240   83  Linux

/dev/sdb8               6           8       10240   83  Linux

/dev/sdb9               8           9       10240   8e  Linux

 

注意:LVM  #不能动态调整

 

Command (m for help): w     #保存并退出

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

 

提示:

现在写分区表linux内核是不知道的,所以执行命令把修改分区表信息告诉linux内核,说改了分区表,执行以下命令:

[root@CentOS66-15 /]# partprobe /dev/sdb 

[root@CentOS66-15 /]# man partprobe

partprobe - inform the OS of partition table changes

注意:partprobe不接设备名会报错

 

2.fdisk 如何非交互分区?

提示:

分区大小不同有目的的,为后面扩容做准备!

对新添加的磁盘快速分区方法:

#echo -e "n\np\n1\n+10G\nn\np\n2\n\n+20G\nw"|fdisk /dev/sdc

#partprobe /dev/sdc

 

 

 

 

 

本文出自 “微风清凉” 博客,请务必保留此出处http://jiay1.blog.51cto.com/9144615/1707287

Linux系统磁盘分区

原文:http://jiay1.blog.51cto.com/9144615/1707287

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!