感谢支持
我们一直在努力

Linux基础教程:关于fdisk分区

fdisk 挺好学的,因为基本上按个m它就能告诉你该怎么做了。我这里有一个20g的虚拟磁盘。实际操作下。

开始对磁盘/dev/sdb分区
[root@rhel6 sjb]# 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): 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  显示已知的分区类型以及对应的id号
  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          改变分区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
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: 0xce4aaddb

  Device Boot      Start        End      Blocks  Id  System
/dev/sdb1  *          1        131    1048576  83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2            131        784    5242880  83  Linux
Partition 2 does not end on cylinder boundary.
/dev/sdb3            784        1045    2097152  82  Linux swap / Solaris
Partition 3 does not end on cylinder boundary.
/dev/sdb4            1045        2611    12580864    f  W95 Ext’d (LBA)
Partition 4 does not end on cylinder boundary.
/dev/sdb5            1045        2611    12579840  83  Linux
删除磁盘分区
Command (m for help): d
Partition number (1-5): 1
Command (m for help): d
Partition number (1-5): 2
Command (m for help): d
Partition number (1-5): 3
Command (m for help): d
Partition number (1-5): 4
Command (m for help): d
Partition number (1-5): 5
查看删除情况
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: 0xce4aaddb

  Device Boot      Start        End      Blocks  Id  System
 

新建主分区1,起始磁柱为1,分区大小我们用+100M来指定分区大小为100M.
Command (m for help): n
Command action
  e  extended
  p  primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +100M

指定其为活动分区
Command (m for help): a
Partition number (1-6): 1

建立主分区2,大小为1G
Command (m for help): n
Command action
  e  extended
  p  primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (15-2610, default 15):
Using default value 15
Last cylinder, +cylinders or +size{K,M,G} (15-2610, default 2610): +1G

查看支持的文件系统类型
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

由上可以,swap代号id为83,将分区2变为swap分区
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap / Solaris)
 


建立主分区3,大小为10G
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (147-2610, default 147):
Using default value 147
Last cylinder, +cylinders or +size{K,M,G} (147-2610, default 2610): +10G
 


建立扩展分区,将剩余空间全部划分给它
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Selected partition 4
First cylinder (1453-2610, default 1453):
Using default value 1453
Last cylinder, +cylinders or +size{K,M,G} (1453-2610, default 2610):
Using default value 2610
在扩展分区下建立两个逻辑分区,一个大小5g,一个使用剩余全部扩展分区空间。注意,在这里我们新建的时候,已经没有提示我们要建立主分区还是扩展分区了,因为系统中除了扩展分区外没有其它额外空间了,所以直接进入就扩展分区了。另外,在扩展分区下建立逻辑分区是不用指定分区号的,系统会自动从5开始向后编号,如我们现在的建立的分区就是/dev/sdb5。
Command (m for help): n
First cylinder (1453-2610, default 1453):
Using default value 1453
Last cylinder, +cylinders or +size{K,M,G} (1453-2610, default 2610): +5G


Command (m for help): n
First cylinder (2107-2610, default 2107):
Using default value 2107
Last cylinder, +cylinders or +size{K,M,G} (2107-2610, default 2610):
Using default value 2610


查看磁盘分区情况,可以看到,我们建立的几个分区都建立好了。并且sdb1是活动的。


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: 0xce4aaddb


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          14      112423+  83  Linux
/dev/sdb2              15         146     1060290   82  Linux swap / Solaris
/dev/sdb3             147        1452    10490445   83  Linux
/dev/sdb4            1453        2610     9301635    5  Extended
/dev/sdb5            1453        2106     5253223+  83  Linux
/dev/sdb6            2107        2610     4048348+  83  Linux
 


将修改写入磁盘
Command (m for help): w
The partition table has been altered!


Calling ioctl() to re-read partition table.
Syncing disks.
 


查看新磁盘的分区情况
[root@rhel6 sjb]# fdisk -l /dev/sdb


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: 0xce4aaddb


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          14      112423+  83  Linux
/dev/sdb2              15         146     1060290   82  Linux swap / Solaris
/dev/sdb3             147        1452    10490445   83  Linux
/dev/sdb4            1453        2610     9301635    5  Extended
/dev/sdb5            1453        2106     5253223+  83  Linux
/dev/sdb6            2107        2610     4048348+  83  Linux
可以看到,分区成功了!当然,这时还不能用啊,因为还没格式化呢!

赞(0) 打赏
转载请注明出处:服务器评测 » Linux基础教程:关于fdisk分区
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏