目錄:
1、MBR分區介紹
2、創建主分區
3、創建擴展分區
4、創建邏輯分區
1、MBR分區介紹
1.1 分區規定:
每個磁盤設備最多4個主分區,或者3個主分區+1個擴展分區,是因為MBR(主引導記錄)的分區表(主分區表)只能存放4個分區 (GPT分區沒有這個限制)。
擴展分區只能有一個。
邏輯分區可以有多個。
可以從擴展分區中再次划分多個邏輯分區,邏輯分區編號直接從5開始。
1.2 分區作用:
主分區:主要是用來啟動操作系統的,它主要放的是操作系統的啟動或引導程序,/boot分區最好放在主分區上;
擴展分區是不能使用的,它只是做為邏輯分區的容器存在的,先創建一個擴展分區,在擴展分區之上創建邏輯分區;
我們真正存放數據的是主分區和邏輯分區,大量數據都放在邏輯分區中。
2、創建主分區
[root@servera ~]# fdisk /dev/vdb
Command (m for help): n # 創建新分區 Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p # 創建主分區 Partition number (1-4, default 1): # 回車 First sector (2048-10485759, default 2048): # 回車,設置起始扇區 Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): 409600 # 設置結尾扇區 Created a new partition 1 of type 'Linux' and of size 199 MiB. Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): p # 創建主分區 Partition number (2-4, default 2): # 回車 First sector (409601-10485759, default 411648): # 回車,設置起始扇區 Last sector, +sectors or +size{K,M,G,T,P} (411648-10485759, default 10485759): 819200 # 設置結尾扇區 Created a new partition 2 of type 'Linux' and of size 199 MiB.
Command (m for help): w # 保存配置 The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@servera ~]# fdisk -l /dev/vdb Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 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 Disklabel type: dos Disk identifier: 0x03864530 Device Boot Start End Sectors Size Id Type /dev/vdb1 2048 409600 407553 199M 83 Linux /dev/vdb2 411648 819200 407553 199M 83 Linux
3、創建擴展分區
[root@servera ~]# fdisk /dev/vdb
Command (m for help): n # 創建新分區 Partition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions) Select (default p): e # 創建擴展分區 Partition number (3,4, default 3): # 選擇分區號 First sector (409601-10485759, default 821248): # 起始扇區 Last sector, +sectors or +size{K,M,G,T,P} (821248-10485759, default 10485759): # 結尾扇區 Created a new partition 3 of type 'Extended' and of size 4.6 GiB. Command (m for help): w # 保存配置 The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@servera ~]# fdisk -l /dev/vdb Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 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 Disklabel type: dos Disk identifier: 0x03864530 Device Boot Start End Sectors Size Id Type /dev/vdb1 2048 409600 407553 199M 83 Linux # 主分區 /dev/vdb2 411648 819200 407553 199M 83 Linux # 主分區 /dev/vdb3 821248 10485759 9664512 4.6G 5 Extended # 擴展分區
4、創建邏輯分區
[root@servera ~]# fdisk /dev/vdb Command (m for help): n # 創建新分區 All space for primary partitions is in use. # 提示所有空間都已經分配給主分區使用 Adding logical partition 5 # 從擴展分區中,自動划分邏輯分區 First sector (823296-10485759, default 823296): # 起始扇區 Last sector, +sectors or +size{K,M,G,T,P} (823296-10485759, default 10485759): # 結尾扇區 Created a new partition 5 of type 'Linux' and of size 4.6 GiB. Command (m for help): t # 分區類型 Partition number (1-3,5, default 5): Hex code (type L to list all codes): 8e # LVM類型 Changed type of partition 'Linux' to 'Linux LVM'. Command (m for help): w # 保存配置 The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@servera ~]# fdisk -l /dev/vdb Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 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 Disklabel type: dos Disk identifier: 0x03864530 Device Boot Start End Sectors Size Id Type /dev/vdb1 2048 409600 407553 199M 83 Linux /dev/vdb2 411648 819200 407553 199M 83 Linux /dev/vdb3 821248 10485759 9664512 4.6G 5 Extended /dev/vdb5 823296 10485759 9662464 4.6G 8e Linux LVM [root@servera ~]# mkfs.xfs /dev/vdb5 # 格式化邏輯分區 meta-data=/dev/vdb5 isize=512 agcount=4, agsize=301952 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=1207808, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@servera ~]# mount /dev/vdb5 /var/tmp # 掛載邏輯分區
5、Parted格式化2TB以上的磁盤
通常我們使用fdisk工具來進行磁盤分區,但是fdisk只能格式化小於2TB的磁盤。因此大於2TB的磁盤分區就需要parted工具。
5.1 設置DiskLable Type
# parted /dev/sdb mklabel gpt
5.2 創建分區並格式化
# parted /dev/sdb mkpart primary xfs 0 100%
# mkfs.xfs /dev/sdb1
5.3 掛載分區
# mount /dev/sdb1 /var/tmp
5.4 刪除分區
# parted /dev/sdb rm 1