3 案例3:調整現有磁盤的分區
3.1 問題
本例要求沿用前一天案例,對磁盤/dev/vdb的分區表進行調整,要求如下:不更改原有分區,利用剩餘空間新增三個分區,大小依次爲:500MIB、2000MIB、512MIB
然後再基於剛建立的2000MIB分區構建新的LVM存儲:
- 新的邏輯卷命名爲database,大小爲50個物理擴展單元(Physical Extent),屬於datastore卷組
- 在datastore卷組中的所有邏輯卷,其物理擴展單元(Physical Extent)的大小爲16MIB
- 使用ext3文件系統對邏輯卷database格式化,此邏輯卷應該在開機時自動掛載到/mnt/database目錄
3.2 方案
創建卷組時,可以通過-s選項指定PE的大小
在給新建的邏輯卷分配空間時,空間大小隻能是PE大小的倍數
3.3 步驟
實現此案例需要按照如下步驟進行。
步驟一:調整現有磁盤分區
1)新建擴展分區(使用剩餘可用空間)
[root@server0 ~]# fdisk /dev/vdb
Command (m for help): p //確認原有分區表
.. ..
Device Boot Start End Blocks Id System
/dev/vdb1 2048 411647 204800 8e Linux LVM
/dev/vdb2 411648 4507647 2048000 83 Linux
/dev/vdb3 4507648 6555647 1024000 83 Linux
Command (m for help): n //新建分區
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): e //類型指定爲e(擴展分區)
Selected partition 4 //只一個可用編號,自動選取
First sector (6555648-20971519, default 6555648): //起始位置默認
Using default value 6555648
Last sector, +sectors or +size{K,M,G} (6555648-20971519, default 20971519):
Using default value 20971519 //結束位置默認
Partition 4 of type Extended and of size 6.9 GiB is set
Command (m for help): p
.. ..
Device Boot Start End Blocks Id System
/dev/vdb1 2048 411647 204800 8e Linux LVM
/dev/vdb2 411648 4507647 2048000 83 Linux
/dev/vdb3 4507648 6555647 1024000 83 Linux
/dev/vdb4 6555648 20971519 7207936 5 Extended
2)在擴展分區中新建3個邏輯分區
創建第1個邏輯卷(由於主分區編號已用完,分區類型自動選I邏輯分區):
Command (m for help): n
All primary partitions are in use
Adding logical partition 5 //分區編號5
First sector (6557696-20971519, default 6557696): //起始位置默認
Using default value 6557696
Last sector, +sectors or +size{K,M,G} (6557696-20971519, default 20971519): +500M
//結束位置默認
Partition 5 of type Linux and of size 500 MiB is set
創建第2個邏輯卷:
Command (m for help): n
All primary partitions are in use
Adding logical partition 6 //分區編號6
First sector (7583744-20971519, default 7583744): //起始位置默認
Using default value 7583744
Last sector, +sectors or +size{K,M,G} (7583744-20971519, default 20971519): +2000M
//結束位置默認
Partition 6 of type Linux and of size 2 GiB is set
創建第3個邏輯卷:
Command (m for help): n
All primary partitions are in use
Adding logical partition 7 //分區編號7
First sector (11681792-20971519, default 11681792): //起始位置默認
Using default value 11681792
Last sector, +sectors or +size{K,M,G} (11681792-20971519, default 20971519): +512M
//結束位置默認
Partition 7 of type Linux and of size 512 MiB is set
根據預計的用途調整分區類型(可選):
Command (m for help): t //修改
Partition number (1-7, default 7): 5 //第5個分區
Hex code (type L to list all codes): 8e //類型爲8e(LVM)
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): t //修改
Partition number (1-7, default 7): 6 //第6個分區
Hex code (type L to list all codes): 8e //類型爲8e(LVM)
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): t //修改
Partition number (1-7, default 7): 7 //第7個分區
Hex code (type L to list all codes): 82 //類型爲82(交換分區)
Changed type of partition 'Linux' to 'Linux swap / Solaris'
確認分區結果並保存:
Command (m for help): p
.. ..
Device Boot Start End Blocks Id System
/dev/vdb1 2048 411647 204800 8e Linux LVM
/dev/vdb2 411648 4507647 2048000 83 Linux
/dev/vdb3 4507648 6555647 1024000 83 Linux
/dev/vdb4 6555648 20971519 7207936 5 Extended
/dev/vdb5 6557696 7581695 512000 8e Linux LVM
/dev/vdb6 7583744 11679743 2048000 8e Linux LVM
/dev/vdb7 11681792 12730367 524288 82 Linux swap / Solaris
Command (m for help): w //保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks. //提示重啓
3)刷新分區表
[root@server0 ~]# partprobe /dev/vdb
[root@server0 ~]# reboot
步驟二:新建卷組、邏輯卷
1)新建卷組datastore,指定PE大小爲16MIB
[root@server0 ~]# lvcreate -l 50 -n database datastore
Logical volume "database" created
[root@server0 ~]# lvscan //確認新建的邏輯卷
ACTIVE '/dev/systemvg/vo' [180.00 MiB] inherit
ACTIVE '/dev/datastore/database' [800.00 MiB] inherit
步驟三:格式化及使用邏輯卷
1)格式化邏輯卷/dev/datastore/database
[root@server0 ~]# mkfs.ext3 /dev/datastore/database
.. ..
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
2)配置開機掛載
[root@server0 ~]# mkdir /mnt/database //創建掛載點
[root@server0 ~]# vim /etc/fstab
.. ..
/dev/datastore/database /mnt/database ext3 defaults 0 0
3)驗證掛載配置
[root@server0 ~]# mount -a
[root@server0 ~]# df -hT /mnt/database/ //確認掛載點設備
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/datastore-database ext3 772M 828K 715M 1% /mnt/database