设为首页 收藏本站
查看: 4492|回复: 1

[经验分享] hyper-v虚拟机内为centos6的虚拟机动态扩容硬盘

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-2-22 09:00:03 | 显示全部楼层 |阅读模式
我的zabbix监控机部署在了hyper-v的虚拟环境里,初始创建的时候硬盘分配了50GB,运行半年多后,尴尬的发现,磁盘空间不够了,幸亏创建时候使用的是动态扩张磁盘。
那么接下来我就为这台centos6.6的虚拟机来动态扩容硬盘,扩展之前先让我展示下分区和磁盘情况:
[iyunv@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

[iyunv@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, time localhost.localdomain, 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

[iyunv@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

[iyunv@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系统,分区磁盘,转换磁盘类型
[iyunv@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, 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
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, 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/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.
[iyunv@zabbix-test ~]# sync
[iyunv@zabbix-test ~]# sync
[iyunv@zabbix-test ~]# init 6
查看挂载分区,分区已经变为250GB,将扩容的磁盘/dev/sda内未分配的空间分区,然后转化为8e LVM格式,然后重启重新识别磁盘
4)格式化分区,重新识别根分区
[iyunv@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.
[iyunv@zabbix-test ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
[iyunv@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

[iyunv@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

[iyunv@zabbix-test ~]# vgextend VolGroup /dev/sda3
  Volume group "VolGroup" successfully extended
[iyunv@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

[iyunv@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, time localhost.localdomain, 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

[iyunv@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

[iyunv@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
[iyunv@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

[iyunv@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.
[iyunv@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的卷组管理


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-345461-1-1.html 上篇帖子: HyperLedger-fabric V0.6 for CentOS7.2开发环境搭建 下篇帖子: Hyperledger Fabric V1.0 for Centos7.2 开发环境搭建 虚拟机 动态
累计签到:88 天
连续签到:1 天
发表于 2017-4-11 09:36:12 | 显示全部楼层
我理解有错?动态硬盘,不是你存多少进去,那个虚拟文件就会增大多少的?

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表