首先擴大原有分區只針對與邏輯卷格式 物理卷無效node
先查詢 增長的磁盤 而且對其進行分區 格式化app
[root@localhost ~]# fdisk -ldom
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x000b2e43ide
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 5222 41430016 8e Linux LVMui
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x00000000spa
[root@localhost ~]# 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 0xdd2a01a6.
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).net
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').orm
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): ## 劃分最大空間
Using default value 1305ip
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x000b2e43
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 5222 41430016 8e Linux LVM
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0xdd2a01a6
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 83 Linux
格式化分區 指定 ext4格式:
[root@localhost ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系統標籤=
操做系統:Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2620595 blocks
....
正在寫入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost /]# pvdisplay ##顯示物理卷
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup
PV Size 39.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 10114
Free PE 0
Allocated PE 10114
PV UUID 6LL9QX-ULqY-RHs8-NyWS-P5Vf-g5qi-eqZMKh
"/dev/sdb1" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID iF8Gno-3nEP-cp24-hcCZ-dQz8-SjGf-Cjj9ad
[root@localhost /]# pvscan ##顯示物理卷 做用同上
PV /dev/sda2 VG VolGroup lvm2 [39.51 GiB / 0 free]
PV /dev/sdb1 lvm2 [10.00 GiB]
Total: 2 [49.50 GiB] / in use: 1 [39.51 GiB] / in no VG: 1 [10.00 GiB]
擴容 VG 將剛纔建立好的pv 添加到系統根分區所在的卷組中 經過df -h 查看到的 /dev/mapper/VolGroup-lv_root 36G 7.4G 26G 23% /
組名爲 VolGroup-lv
邏輯卷名爲 lv_root
[root@localhost /]# vgextend VolGroup /dev/sdb1 ###將/dev/sdb1/ 添加到邏輯卷組 VolGroup中
Volume group "VolGroup" successfully extended
[root@localhost /]# vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
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 49.50 GiB ##此時VG的大小以及改變
PE Size 4.00 MiB
Total PE 12672
Alloc PE / Size 10114 / 39.51 GiB
Free PE / Size 2558 / 9.99 GiB
VG UUID XhRR19-HGRS-ObYb-NLfd-vM41-XgS4-ZiD0o4
此時在將其擴展lv 即根分區
[root@localhost /]# lvextend -L +10G /dev/mapper/VolGroup-lv_root
Extending logical volume lv_root to 45.65 GiB
Insufficient free space: 2560 extents needed, but only 2558 available
##報錯 是由於此時可用pe塊只有2558個 2558*4/1024=9.992G
[root@localhost /]# lvextend -L +9.992G /dev/mapper/VolGroup-lv_root
Rounding size to boundary between physical extents: 9.99 GiB
Extending logical volume lv_root to 45.64 GiB
Logical volume lv_root successfully resized ###成功
[root@localhost /]# lvdisplay
--- Logical volume ---
LV Path /dev/VolGroup/lv_root
LV Name lv_root
VG Name VolGroup
LV UUID obpkNc-TjiE-YTln-23wo-c6KS-lofw-BRm50Y
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-09-13 21:56:39 +0800
LV Status available
# open 1
LV Size 45.64 GiB
Current LE 11684
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
可是 df -h 並未生效
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 36G 7.4G 26G 23% /
tmpfs 996M 72K 996M 1% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
[root@localhost /]# resize2fs /dev/mapper/VolGroup-lv_root ## 使擴容立刻生效
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required
old desc_blocks = 3, new_desc_blocks = 3
Performing an on-line resize of /dev/VolGroup/lv_root to 11964416 (4k) blocks.
The filesystem on /dev/VolGroup/lv_root is now 11964416 blocks long.
此時 根分區已經改變
[root@localhost /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 45G 7.4G 36G 18% / tmpfs 996M 72K 996M 1% /dev/shm /dev/sda1 485M 39M 421M 9% /boot