我的zabbix监控机部署在了hyper-v的虚拟环境里,初始创建的时候硬盘分配了50GB,运行半年多后,尴尬的发现,磁盘空间不够了,幸亏创建时候使用的是动态扩张磁盘。
那么接下来我就为这台centos6.6的虚拟机来动态扩容硬盘,扩展之前先让我展示下分区和磁盘情况:
[root@zabbix-test ~]# vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 49.51 GiB
PE Size 4.00 MiB
Total PE 12674
Alloc PE / Size 12674 / 49.51 GiB
Free PE / Size 0 / 0
VG UUID swdQhX-7DhD-qiWW-8oeV-ewSP-Djjy-ozdCpy
[root@zabbix-test ~]# lvdisplay
--- Logical volume ---
LV Path /dev/VolGroup/lv_root
LV Name lv_root
VG Name VolGroup
LV UUID mduTSv-NAbg-wKVi-HHbB-JSrq-YzVu-pOZ6SD
LV Write Access read/write
LV Creation host,time localhost.localdomain,2016-06-01 01:43:46 +0800
LV Status available
# open 1
LV Size 45.60 GiB
Current LE 11674
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/VolGroup/lv_swap
LV Name lv_swap
VG Name VolGroup
LV UUID Jrud8e-iuls-u8uZ-m8IX-c0lQ-pgAe-VK7pJE
LV Write Access read/write
LV Creation host,2016-06-01 01:43:49 +0800
LV Status available
# open 1
LV Size 3.91 GiB
Current LE 1000
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
[root@zabbix-test ~]# df -HP
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 49G 37G 9.2G 80% /
tmpfs 3.1G 0 3.1G 0% /dev/shm
/dev/sda1 500M 73M 402M 16% /boot
//10.11.0.6/zabbix_MysqL_backup 837G 769G 69G 92% /MysqLbackup
[root@zabbix-test ~]# fdisk -l /dev/sda
Disk /dev/sda: 268.4 GB,268435456000 bytes
255 heads,63 sectors/track,32635 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x0002c75c
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 6528 51915776 8e Linux LVM
磁盘分区情况总结如下:
/dev/mapper/VolGroup-lv_root 空间不足
/dev/sda 有2个分区
操作步骤:
1)首先关闭虚拟机,然后再操作之前备份一下所属的硬盘,免得手残
2)编辑所属磁盘,选择扩展磁盘,将大小调整为250GB。
3)开机进入zabbix系统,分区磁盘,转换磁盘类型
[root@zabbix-test ~]# fdisk /dev/sda
The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended,or performance may be impacted.
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): p
Disk /dev/sda: 268.4 GB,32635 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x0002c75c
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 6528 51915776 8e Linux LVM
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (6528-32635,default 6528):
Using default value 6528
Last cylinder,+cylinders or +size{K,M,G} (6528-32635,default 32635):
Using default value 32635
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sda: 268.4 GB,32635 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x0002c75c
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 6528 51915776 8e Linux LVM
/dev/sda3 6528 32635 209711837+ 8e Linux LVM
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.
[root@zabbix-test ~]# sync
[root@zabbix-test ~]# sync
[root@zabbix-test ~]# init 6
查看挂载分区,分区已经变为250GB,将扩容的磁盘/dev/sda内未分配的空间分区,然后转化为8e LVM格式,然后重启重新识别磁盘
4)格式化分区,重新识别根分区
[root@zabbix-test ~]# mkfs.ext4 /dev/sda3
mke2fs 1.41.12 (17-May-2010)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=1 blocks,Stripe width=0 blocks
13107200 inodes,52427959 blocks
2621397 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1600 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,11239424,20480000,23887872
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 30 mounts or
180 days,whichever comes first. Use tune2fs -c or -i to override.
[root@zabbix-test ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
[root@zabbix-test ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup
PV Size 49.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 12674
Free PE 0
Allocated PE 12674
PV UUID 257toR-VCpi-ZkbK-6xuM-Vfmh-iywx-CLt1hp
"/dev/sda3" is a new physical volume of "200.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 200.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 9xcLAh-dIDQ-Q7F5-eSuP-Kzf2-5VGx-i5H7C1
[root@zabbix-test ~]# vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 49.51 GiB
PE Size 4.00 MiB
Total PE 12674
Alloc PE / Size 12674 / 49.51 GiB
Free PE / Size 0 / 0
VG UUID swdQhX-7DhD-qiWW-8oeV-ewSP-Djjy-ozdCpy
[root@zabbix-test ~]# vgextend VolGroup /dev/sda3
Volume group "VolGroup" successfully extended
[root@zabbix-test ~]# 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 249.50 GiB
PE Size 4.00 MiB
Total PE 63872
Alloc PE / Size 12674 / 49.51 GiB
Free PE / Size 51198 / 199.99 GiB
VG UUID swdQhX-7DhD-qiWW-8oeV-ewSP-Djjy-ozdCpy
[root@zabbix-test ~]# lvdisplay
--- Logical volume ---
LV Path /dev/VolGroup/lv_root
LV Name lv_root
VG Name VolGroup
LV UUID mduTSv-NAbg-wKVi-HHbB-JSrq-YzVu-pOZ6SD
LV Write Access read/write
LV Creation host,2016-06-01 01:43:49 +0800
LV Status available
# open 1
LV Size 3.91 GiB
Current LE 1000
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
[root@zabbix-test ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup
PV Size 49.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 12674
Free PE 0
Allocated PE 12674
PV UUID 257toR-VCpi-ZkbK-6xuM-Vfmh-iywx-CLt1hp
--- Physical volume ---
PV Name /dev/sda3
VG Name VolGroup
PV Size 200.00 GiB / not usable 4.72 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 51198
Free PE 51198
Allocated PE 0
PV UUID 9xcLAh-dIDQ-Q7F5-eSuP-Kzf2-5VGx-i5H7C1
[root@zabbix-test ~]# lvextend -l +51198 /dev/VolGroup/lv_root
Size of logical volume VolGroup/lv_root changed from 45.60 GiB (11674 extents) to 245.59 GiB (62872 extents).
Logical volume lv_root successfully resized
#此处的+51198就是添加的分区sda3加入物理卷组之后所剩余的PE,全部加入到逻辑卷组/dev/VolGroup/lv_root
[root@zabbix-test ~]# df -hP
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 45G 34G 8.6G 80% /
tmpfs 2.9G 0 2.9G 0% /dev/shm
/dev/sda1 477M 69M 383M 16% /boot
[root@zabbix-test ~]# resize2fs /dev/mapper/VolGroup-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 3,new_desc_blocks = 16
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 64380928 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 64380928 blocks long.
[root@zabbix-test ~]# df -hP
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 242G 34G 196G 15% /
tmpfs 2.9G 0 2.9G 0% /dev/shm
/dev/sda1 477M 69M 383M 16% /boot
至此/dev/mapper/VolGroup-lv_root 对应的根分区终于变大了,扩容完成
此案例同样适用于vmware或KVM环境,或者LVM的卷组管理