**************操作之前請看章節6,看系統是否支持LVM分區管理方式***************
1:新增磁盤
插入新的磁盤,比如物理機可以直接在卡槽插入,虛擬機可以在控制台添加磁盤或者擴充磁盤,如下圖所示
2:查找新插入的磁盤名稱
插入磁盤操作執行完以后,可以執行fdisk -l查看新磁盤的名稱,如下面的文字所示,有一個1G的磁盤未分區,磁盤sda已分區,如下圖所示/dev/sda1,/dev/sda2,/dev/sda3,/dev/sda4,/dev/sda5
---------------------------------------------------------------------------------------------------------------------------------
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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: 0x08eecc1c
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 41940991 40939522 19.5G 5 Extended
/dev/sda3 999424 1001469 2046 1023K 83 Linux
/dev/sda4 41940992 83886079 41945088 20G 83 Linux
/dev/sda5 1001472 41940991 40939520 19.5G 8e Linux LVM
Partition table entries are not in disk order.
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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
由上面的操作可以看出,新的磁盤名稱是/dev/sdb
3:對新增磁盤進行分區
登錄系統,執行fdisk 新添加的磁盤名稱,我這里新增加的磁盤是/dev/sdb
root@kingserver10:~# fdisk /dev/sdb
下面來到fdisk的分區工具的操作界面,會有一個過程
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x565ca282.
Command (m for help): p
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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: 0x565ca282
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-2097151, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-2097151, default 2097151):
Created a new partition 1 of type 'Linux' and of size 1023 MiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
上面對新增磁盤分區的操作,下面查看一下分區是否成功,可以看到在sdb盤多了一個/dev/sdb1的分區,說明分區成功
root@kingserver10:~# fdisk -l
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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: 0x08eecc1c
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 41940991 40939522 19.5G 5 Extended
/dev/sda3 999424 1001469 2046 1023K 83 Linux
/dev/sda4 41940992 83886079 41945088 20G 83 Linux
/dev/sda5 1001472 41940991 40939520 19.5G 8e Linux LVM
Partition table entries are not in disk order.
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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: 0x565ca282
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 2097151 2095104 1023M 83 Linux
Disk /dev/mapper/kingserver8--vg-root: 30.5 GiB, 32770097152 bytes, 64004096 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 /dev/mapper/kingserver8--vg-swap_1: 8 GiB, 8589934592 bytes, 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
4:擴展文件分區
4.1:將新增物理硬盤分區初始化為物理卷
pvcreate命令用於將物理硬盤分區初始化為物理卷,以便LVM使用。
root@kingserver10:~# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
4.2:查看VG NAME
root@kingserver10:~# vgdisplay
--- Volume group ---
VG Name kingserver8-vg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 39.52 GiB
PE Size 4.00 MiB
Total PE 10117
Alloc PE / Size 9861 / 38.52 GiB
Free PE / Size 256 / 1.00 GiB
VG UUID kBq0j1-qE2e-O1Ap-CURx-krhU-ydKi-lOZA4d
4.3:擴展VG
語法:vgextend vg-name 新增的要擴展的物理卷名稱
root@kingserver10:~# vgextend kingserver8-vg /dev/sdb1
Volume group "kingserver8-vg" successfully extended
4.4:查看 LV Path
要擴展的LV Path對應的是 root對應的LV Path,而不是swap對應的LV Path
root@kingserver10:~# lvdisplay
--- Logical volume ---
LV Path /dev/kingserver8-vg/root
LV Name root
VG Name kingserver8-vg
LV UUID 19Bpd4-Yhe8-ZgEI-kQaD-oKav-n5O4-HXakw2
LV Write Access read/write
LV Creation host, time kingserver8, 2017-12-07 18:21:36 +0800
LV Status available
# open 1
LV Size 30.52 GiB
Current LE 7813
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
--- Logical volume ---
LV Path /dev/kingserver8-vg/swap_1
LV Name swap_1
VG Name kingserver8-vg
LV UUID xnTj8x-BcQd-24mH-gqZJ-v9Oa-bRm0-33x26V
LV Write Access read/write
LV Creation host, time kingserver8, 2017-12-07 18:21:37 +0800
LV Status available
# open 2
LV Size 8.00 GiB
Current LE 2048
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:1
4.5:擴展LV Path
語法:lvextend –L +新增的要擴展的物理卷大小 root目錄的LV-Path
root@kingserver10:~# lvextend -L +1G /dev/kingserver8-vg/root
Size of logical volume kingserver8-vg/root changed from 30.52 GiB (7813 extents) to 31.52 GiB (8069 extents).
Logical volume root successfully resized.
4.6:重置主分區的大小
root@kingserver10:~# resize2fs /dev/kingserver8-vg/root
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/kingserver8-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 2
The filesystem on /dev/kingserver8-vg/root is now 8262656 (4k) blocks long.
5:查看擴展后的文件系統
發現原來的/dev/mapper/kingserver8--vg-root從30G變為了31G說明擴展成功
root@kingserver10:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 797M 9.0M 788M 2% /run
/dev/mapper/kingserver8--vg-root 31G 18G 12G 61% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 472M 57M 391M 13% /boot
cgmfs 100K 0 100K 0% /run/cgmanager/fs
tmpfs 797M 0 797M 0% /run/user/0
root@kingserver10:~#
6:操作的可行性(LVM)
需要注意的是,並不是所有的磁盤都可以擴展,安裝的時候需要支持LVM,LVM是什么?
如下:總之一句話,支持了LVM之后,新增加一個磁盤,就可以用來擴充文件分區的目錄了;
LVM是邏輯盤卷管理(LogicalVolumeManager)的簡稱,它是Linux環境下對磁盤分區進行管理的一種機制,LVM是建立在硬盤和 分區之上的一個邏輯層,來提高磁盤分區管理的靈活性。通過LVM系統管理員可以輕松管理磁盤分區,如:將若干個磁盤分區連接為一個整塊的卷組 (volumegroup),形成一個存儲池。管理員可以在卷組上隨意創建邏輯卷組(logicalvolumes),並進一步在邏輯卷組上創建文件系 統。管理員通過LVM可以方便的調整存儲卷組的大小,並且可以對磁盤存儲按照組的方式進行命名、管理和分配,例如按照使用用途進行定義:“development”和“sales”,而不是使用物理磁盤名“sda”和“sdb”。而且當系統添加了新的磁盤,通過LVM管理員就不必將磁盤的 文件移動到新的磁盤上以充分利用新的存儲空間,而是直接擴展文件系統跨越磁盤即可。
7: 查看是否支持LVM
7.1、df -h 可以看到root目錄有vg的標示
7.2、vgdisplay ,可以看到vg name
7.3、lvdisplay 可以看到 LV path
