1、虚拟机关机给硬盘增加20G
2、查看现有分区大小
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 44G 3.1G 94% /
tmpfs 931M 92K 931M 1% /dev/shm
/dev/sda1 477M 69M 383M 16% /boot
/dev/mapper/VolGroup-lv_home
43G 286M 41G 1% /home
目前根目录总共53G,使用了47G
3、查看磁盘结构
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 120G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 99.5G 0 part
├─VolGroup-lv_root (dm-0) 253:0 0 50G 0 lvm /
├─VolGroup-lv_swap (dm-1) 253:1 0 5.8G 0 lvm [SWAP]
└─VolGroup-lv_home (dm-2) 253:2 0 43.7G 0 lvm /home
sr0 11:0 1 1024M 0 rom
磁盘大小120G,有20G空余
4、创建新分区
[root@localhost ~]# fdisk /dev/sda
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').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (13055-15665, default 13055):
Using default value 13055
Last cylinder, +cylinders or +size{K,M,G} (13055-15665, default 15665):
Using default value 15665
Command (m for help): p
Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 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: 0x0006372f
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 13055 104344576 8e Linux LVM
/dev/sda3 13055 15665 20971512+ 83 Linux
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: 设备或资源忙.
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.
5、刷新分区
[root@localhost ~]# partprobe /dev/sda
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (设备或资源忙). As a result, it may not reflect all of your changes until after reboot.
报错,重启设备
6、创建物理卷
[root@localhost ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
7、查看卷组名称及使用情况
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 99.51 GiB
PE Size 4.00 MiB
Total PE 25474
Alloc PE / Size 25474 / 99.51 GiB
Free PE / Size 0 / 0
VG UUID Cvtddv-VzMi-wGeE-ZoDX-door-HsPt-CV83A0
8、将物理卷扩展到卷组
[root@localhost ~]# vgextend VolGroup /dev/sda3
Volume group "VolGroup" successfully extended
9、查看逻辑卷名称及使用情况
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/VolGroup/lv_root
LV Name lv_root
VG Name VolGroup
LV UUID 8cr93l-olWM-cl76-ei2q-uw89-RtUR-IZi2zY
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-11-01 04:32:57 +0800
LV Status available
# open 1
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/VolGroup/lv_home
LV Name lv_home
VG Name VolGroup
LV UUID lTSehz-ENYB-3Wwd-Bebw-e19v-ria5-NzjDID
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-11-01 04:33:04 +0800
LV Status available
# open 1
LV Size 43.68 GiB
Current LE 11182
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/VolGroup/lv_swap
LV Name lv_swap
VG Name VolGroup
LV UUID dvJ5oq-kOqg-9PgR-gVSh-v8rw-6tti-fkwMpn
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-11-01 04:33:06 +0800
LV Status available
# open 1
LV Size 5.83 GiB
Current LE 1492
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
10、将卷组中的空闲空间扩展到根分区逻辑卷
[root@localhost ~]# lvextend -l +100%FREE /dev/VolGroup/lv_root
Size of logical volume VolGroup/lv_root changed from 50.00 GiB (12800 extents) to 70.00 GiB (17919 extents).
Logical volume lv_root successfully resized.
11、刷新根分区
[root@localhost ~]# resize2fs /dev/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 = 4, new_desc_blocks = 5
Performing an on-line resize of /dev/VolGroup/lv_root to 18349056 (4k) blocks.
The filesystem on /dev/VolGroup/lv_root is now 18349056 blocks long.
12、查看磁盘使用情况
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
69G 44G 22G 67% /
tmpfs 931M 16K 931M 1% /dev/shm
/dev/sda1 477M 69M 383M 16% /boot
/dev/mapper/VolGroup-lv_home
43G 287M 41G 1% /home
发表评论