創建分區:fdisk命令和parted命令

1、MBR與GPT分區格式
MBR:(Master Boot Record)主引導記錄的特點:
1)有三種分區:主分區、擴展分區、邏輯分區,一塊MBR分區格式的磁盤有4個主分區,其中擴展分區佔一個主分區的位置,且最多一個擴展分區。
2)最大隻能建立2TB大小的分區
3)擴展分區不能直接用來存數據,不能格式化,主分區、邏輯分區可以用來存數據
4)編號:1-4主分區使用
,邏輯分區的編號大於等於5(從5開始)

GPT:GUID Partition Table,全局唯一標識分區表:

1)是EFI(可擴展固件接口標準)的一部分,用來替代BIOS中的主引導記錄分區表。

2) GPT磁盤分區樣式支持最大卷爲18 EB(Exabytes)並且每磁盤的分區數沒有上限。

3)MBR不支持大於2T的分區,而GPT支持創建大於2T的分區。


2、命令

1)創建MBR格式的分區使用命令:fdisk

2)創建GPT格式的分區使用命令:parted

使用parted命令的一個特性:parted工具比fdisk工具分區危險,因爲分區的時候直接生效,不能撤銷。fdisk可以退出不保存。


3、fdisk命令

一般步驟:創建分區-->格式化-->掛載使用

1)創建分區
[root@localhost ~]# fdisk -l       //查看磁盤的分區情況
[root@localhost ~]# fdisk  /dev/sdb    //編輯/dev/sdb這塊磁盤,將/dev/sdb磁盤劃分多個分區。
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): n             //
新建分區
Command action
  e   extended                          //e表示創建擴展分區
  p   primary partition (1-4)    //p表示創建主分區
p                                            
 //指創建primary partition
Partition number (1-4): 1    主分區的編號,即後面中產生的sdb1中的1的編號
First cylinder (1-10443, default 1):               //起始柱面是多少,不寫就是從默認柱面開始
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): +10G  
#指定分區的大小
Command (m for help): p  輸出/dev/sdb這塊磁盤的信息

Disk /dev/sdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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: 0x38913320

  Device Boot      Start         End      Blocks   Id  System
/dev/sdb
1               1        1306    10490413+  83  Linux

Command (m for help): w    
//退出並且保存
The partition table has been altered!

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

2)格式化分區

[root@localhost ~]# mkfs.ext4   /dev/sdb1   //格式化sdb1這個分區
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655776 inodes, 2622603 blocks
131130 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2688548864
81 block groups
32768 blocks per group, 32768 fragments per group
8096 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]#
===
3)掛載使用
[root@localhost ~]# mkdir  /music      
//新建掛載目錄
[root@localhost ~]#  mount /dev/sdb1  /music    //掛載使用新的分區


4、parted 命令

1)創建分區

[root@linux-6 ~]# parted /dev/sdc   //使用parted命令,在磁盤/dev/sdc中創建gpt格式的分區

GNU Parted 2.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help                                           //使用help尋求幫助
 align-check TYPE N                        check partition N for TYPE(min|opt)
       alignment
 check NUMBER                             do a simple check on the file system
 cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER   copy file system to another partition
 ……
 ……
 mkpart PART-TYPE [FS-TYPE] START END     make a partition
 mkpartfs PART-TYPE FS-TYPE START END     make a partition with a file system
 ……
 ……
       copyright information of GNU Parted

(parted) mkpart software 1 100000            
Error: /dev/sdc: unrecognised disk label      //出錯                            
(parted) mklabel GPT                              //
指定創建分區所屬格式
(parted) mkpart xix 1 100000   //本來xix位置是一個文件系統類型,比如primary等,但是由於這裏不限主分區數,所以可以是任意標誌,mkpart創建gpt格式分區大小以M爲單位,或G。這塊符呢區大小從1M開始到100000M結束。

(parted)  
(parted) mkpart
Partition name?  []? luamin-photo
File system type?  [ext2]? ext4                                          
Start?                                                                    
Start? 100001      //起始大小                                                        
End? 200000         //結束大小                                                      
(parted) print           //打印出上述創建的磁盤大小等內容。                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 1074GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End    Size   File system  Name          Flags
1      1049kB  100GB  100GB               xix
2      100GB   200GB  100GB               luamin-photo

(parted) quit                                                            
Information: You may need to update /etc/fstab.                          

[root@linux-6 ~]# parted /dev/sdc print          
//查看parted創建的分區
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 1074GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End    Size   File system  Name          Flags
1      1049kB  100GB  100GB  ext4         software
2      100GB   200GB  100GB  ext4         luamin-photo

[root@lichao520 ~]#partprobe  /dev/sdc     //更新分區表,使得上述新建分區生效。


2)格式化分區

[root@localhost ~]# mkfs.ext4   /dev/sdc1

[root@localhost ~]# mkfs.ext4   /dev/sdc2  


3)更新/etc/fstab文件

[root@linux-6 ~]# blkid
/dev/sdc1: UUID="3d1fc399-3fd3-40ff-8db1-7ca792a2a8b7" TYPE="ext4"
/dev/sdc2: UUID="ecf75120-b80d-456c-a7b2-c79bb068b336" TYPE="ext4"
[root@linux-6 ~]#
將新建的/dev/sdc1分區和/dev/sdc2 磁盤的UUID按照/etc/fstab文件中的格式寫入該文件就OK了。


4)掛載使用,和fdisk命令使用的是一樣的。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章