linux lvm卷扩容磁盘大小
目的:扩展/dev/mapper/真实路径 卷
前提:虚拟机已增加一块40G硬盘。
- 1、查看增加的硬盘信息
[root@zzzzzz ~]# fdisk -l
Disk /dev/vdb: 42.9 GB, 42949672960 bytes
16 heads, 63 sectors/track, 83220 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
- 2、硬盘分区、格式化(指定文件系统)
[root@zzzzzz ~]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklab
el
Building a new DOS disklabel with disk identifier 0x1e92d533.
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)
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): 1
First cylinder (1-83220, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-83220, default 83220):
Using default value 83220
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@ggzymb ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (
Device or resource busy). As a result, it may not reflect all of your changes u
ntil after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/vda (
Device or resource busy). As a result, it may not reflect all of your changes u
ntil after reboot.
[root@zzzzzz ~]# mkfs.ext4 /dev/vdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2621440 inodes, 10485712 blocks
524285 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
320 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@zzzzz ~]#
- 3、转换/dev/vdb1分区为PV
[root@zzzzzz ~]# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created
- 4、查看系统所有pv,这里vdb1已成功转换
[root@zzzzzz ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name 真实路径
PV Size 199.80 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 51149
Free PE 0
Allocated PE 51149
PV UUID md802e-NvFL-eI1I-S9XN-55iy-pWRP-lIOmtU
"/dev/vdb1" is a new physical volume of "40.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdb1
VG Name
PV Size 40.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID dBhELv-37Zq-kGt5-GBEX-vMcF-GAhx-6CDXDA
[root@ggzymb ~]#
- 5、查看当前VG名称
[root@zzzzzz ~]# vgdisplay |grep Name
VG Name 真实路径
添加vdb1到VG:
[root@zzzzzz ~]# vgextend 真实路径 /dev/vdb1
Volume group "真实路径" successfully extended
查看VG情况,可以看到原有VG已扩展到240G:
[root@zzzzzz ~]# vgdisplay
--- Volume group ---
VG Name 真实路径
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 4
Open LV 4
Max PV 0
Cur PV 2
Act PV 2
VG Size 239.80 GiB
PE Size 4.00 MiB
Total PE 61388
Alloc PE / Size 51149 / 199.80 GiB
Free PE / Size 10239 / 40.00 GiB
VG UUID JFLsS9-8JET-g8xS-WxEw-8aFy-1Nxy-BGmI6B
[root@zzzzzz ~]#
- 6、调整分区容量,原来为79G,+40G调整为119G
[root@zzzzzz ~]# lvextend -L 119G /dev/mapper/真实路径
Size of logical volume 真实路径 changed from 80.00 GiB (20480
extents) to 119.00 GiB (30464 extents).
Logical volume LogVol01_opt successfully resized.
[root@zzzzz ~]#
lvextend -l +100%FREE /dev/mapper/真实路径
- 7、执行重设大小,对当前分区有效:
[root@zzzzzz ~]# resize2fs /dev/mapper/真实路径
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/真实路径 is mounted on /opt; on-line r
esizing required
old desc_blocks = 5, new_desc_blocks = 8
Performing an on-line resize of /dev/mapper/真实路径 to 31195136
(4k) blocks.
The filesystem on /dev/mapper/真实路径 is now 31195136 blocks lo
ng.
- 8、确认已扩展成功:
[root@zzzzzz ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_真实路径
73G 2.9G 66G 5% /
tmpfs 7.8G 224K 7.8G 1% /dev/shm
/dev/vda1 190M 77M 103M 43% /boot
/dev/mapper/真实路径
30G 44M 28G 1% /home
/dev/mapper/真实路径
118G 60M 112G 1% /opt
/dev/sda1 985G 72M 935G 1% /iscsidata
[root@zzzzzz ~]#