1.fdisk进行磁盘分区(如图)


rescue版本安装在U盘,光盘中。基于MBR分区机制,

GPT用parted 分区工具

2.使用说明(在Oracle VM virtualBox中为虚拟机添加一块硬盘,以便用于实验)

(1)fdisk -l   列出计算机上安装的硬盘及其分区信息。(两个又添加了一个)

fdisk -l:

Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors     ---->>>>6527个柱面,每个柱面有63个扇区,每个扇区有255个磁头
Units = sectors of 1 * 512 = 512 bytes                                                            ---------->>>>>  最终大小:6527*63*255*512bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00021777


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   102762495    51380224   83  Linux       ----->>>分区号,起始柱面和结束柱面也就是大小,后面是分区大小,id代表分区的类型,system是对id的解释
/dev/sda2       102764542   104855551     1045505    5  Extended
/dev/sda5       102764544   104855551     1045504   82  Linux swap / Solaris


Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 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: 0x00000000


Disk /dev/sdb doesn't contain a valid partition table  --------------->>>>>>>>>>没有分区表

(2)直接使用fdisk+ 要分区的磁盘名称,进行分区

fdisk /dev/sdb            -------->>>>>进入分区交互式界面


键入命令:n 会提示你想建立一个什么样的分区

e   :扩展分区

P  :主分区(只能创建4个)之前的一节讲过

root@ming-computer:~# fdisk /dev/
Display all 203 possibilities? (y or n)
root@ming-computer:~# 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 0xf59855f8.
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: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 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: 0xf59855f8


   Device Boot      Start         End      Blocks   Id  System


Command (m for help): n        ---->>>>>创建新分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)      ------------------>>>>>>>>>>>创建主分区
   e   extended                                                         ------------------>>>>>>>创建扩展分区
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-16777215, default 2048): 2048               ------->>>>>起始柱面
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215): +2G           -------->>>>大小格式:+大小单位


Command (m for help): p


Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 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: 0xf59855f8


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux                          ------------>>>>>>>>创建主分区成功


Command (m for help): 


接下来创建扩展分区


Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e                                    ---------------->>>>>>>>>>>创建扩展分区
Partition number (1-4, default 2): 2
First sector (4196352-16777215, default 4196352):               ---------->>>>>>>>>>>默认
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-16777215, default 16777215):                 ---------->>>>>>>默认为剩余全部,还要在扩展分区的基础上创建逻辑分区

Using default value 16777215


Command (m for help): p


Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 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: 0xf59855f8


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux          
/dev/sdb2         4196352    16777215     6290432    5  Extended                     ------>>>>>>创建成功,扩展分区不能使用,创建逻辑分区才能使用


一般情况下将系统创建在主分区之上其余的都放在逻辑分区之上

接下来创建逻辑分区:再按n

Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)         ----->>>>>>逻辑分区的号永远是从5开始的
Select (default p): l

Adding logical partition 5
First sector (4198400-16777215, default 4198400):          ------->>>和刚才创建扩展分区时的数字是一样的
Using default value 4198400
Last sector, +sectors or +size{K,M,G} (4198400-16777215, default 16777215): +2G


Command (m for help): p


Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 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: 0xf59855f8


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux          ------------>>>>主分区
/dev/sdb2         4196352    16777215     6290432    5  Extended              ---------->>>>扩展分区   
/dev/sdb5         4198400     8392703     2097152   83  Linux                     ------------->>>>>2G的逻辑分区

为了方便系统识别还要指定id,id是用来表示这个分区是个什么样的分区


Command (m for help): t
Partition number (1-5): 1                   ------------------>>>>>>>>>>>第一个分区sdb1
Hex code (type L to list codes): L                -------------->>>>>>列出所有的类型


 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list codes): 83                          -------------->>>>>>>>>>>83是Linux型


Command (m for help):

到这之前的操作还可以反悔,因为没有保存,写到MBR中,用w命令

Command (m for help): w                 --------->>>>>存储
The partition table has been altered!


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

 

 

查看操作结果。

root@ming-computer:~# ls /dev/sdb*
/dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb5 ------->>>>>新的分区信息,有的时候可能还未更新,需要使用partprobe进行更新
root@ming-computer:~#


root@ming-computer:~# fdisk -l


Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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: 0x00021777


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   102762495    51380224   83  Linux
/dev/sda2       102764542   104855551     1045505    5  Extended
/dev/sda5       102764544   104855551     1045504   82  Linux swap / Solaris


Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 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: 0xf59855f8


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352    16777215     6290432    5  Extended
/dev/sdb5         4198400     8392703     2097152   83  Linux
root@ming-computer:~# cat /proc/partitions              ----------->>>>>>>>>>还可以查看这个文件,也会列出相应信息
major minor  #blocks  name


   8        0   52428800 sda
   8        1   51380224 sda1
   8        2          1 sda2
   8        5    1045504 sda5
   8       16    8388608 sdb
   8       17    2097152 sdb1
   8       18          1 sdb2
   8       21    2097152 sdb5
  11        0    1048575 sr0
root@ming-computer:~# 



 


分区化出来后并不能直接进行使用,还需要在上面创建文件系统才可以用



Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐