KVM總結文檔二(CentOS-6.5)

來源:互聯網
上載者:User

標籤:kvm

五:kvm虛擬機器磁碟擴充



兩種方式:

1.添加一塊新的虛擬磁碟

2.擴充原有磁碟的容量大小


注意:

只有磁碟格式為qcow2的磁碟才支援磁碟快照和磁碟動態擴充.

測試的虛擬機器磁碟大小和格式.


方法一:添加新磁碟

1.查看已存在盤的大小

[[email protected] vm]# qemu-img   info  api1-qcow2.img image: api1-qcow2.imgfile format: qcow2virtual size: 8.0G (8589934592 bytes)disk size: 1.5Gcluster_size: 65536

    <disk type=‘file‘ device=‘disk‘>      <driver name=‘qemu‘ type=‘qcow2‘ cache=‘none‘/>      <source file=‘/vm/api1-qcow2.img‘/>      <target dev=‘vda‘ bus=‘virtio‘/>      <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x05‘ function=‘0x0‘/>    </disk>

2.添加一塊qcow2的盤,大小為10G

cd /vm  &&   qemu-img  create  -f  qcow2  api1-qcow2_add1.img   8G
[[email protected] vm]# qemu-img  info  api1-qcow2_add1.img image: api1-qcow2_add1.imgfile format: qcow2virtual size: 10G (10737418240 bytes)disk size: 140Kcluster_size: 65536
[[email protected] vm]# ll   /vm 總用量 3161404-rwxr-xr-x 1 qemu qemu 1580662784 1月  11 14:55 api2-qcow2.img-rw-r--r-- 1 root root     197120 1月  11 14:53 api1-qcow2_add1.img-rw-r--r-- 1 qemu qemu 1653407744 1月  11 14:55 api1-qcow2.img

3.添加api1-qcow2_add1.img到設定檔中

[[email protected] vm]# virsh  shutdown  api1域 api4 被關閉

[[email protected] vm]# virsh  list --all Id    名稱                         狀態---------------------------------------------------- 2     api2                           running -     api1                           關閉

virsh  edit  api1,添加新磁碟

<disk type=‘file‘ device=‘disk‘>      <driver name=‘qemu‘ type=‘qcow2‘ cache=‘none‘/>      <source file=‘/vm/api1-qcow2_add1.img‘/>      <target dev=‘vdb‘ bus=‘virtio‘/></disk>

4.登入到api1終端,然後查看,並分區/dev/vdb

[[email protected] ~]# fdisk  -lDisk /dev/vdb: 8589 MB, 8589934592 bytes16 heads, 63 sectors/track, 16644 cylindersUnits = cylinders of 1008 * 512 = 516096 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000

5.格式化分區/dev/vdb,並且轉換為lvm格式.

fdisk  /dev/vdb  >>  lvm
[[email protected] ~]# fdisk  -lDisk /dev/vdb: 8589 MB, 8589934592 bytes16 heads, 63 sectors/track, 16644 cylindersUnits = cylinders of 1008 * 512 = 516096 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xa91642d5   Device Boot      Start         End      Blocks   Id  System/dev/vdb1               1       16644     8388544+  8e  Linux LVM

[[email protected] ~]# pvcreate  /dev/vdb1  Physical volume "/dev/vdb1" successfully created
[[email protected] ~]# vgs  VG       #PV #LV #SN Attr   VSize VFree  VolGroup   1   2   0 wz--n- 7.51g    0
[[email protected] ~]# vgextend VolGroup  /dev/vdb1  Volume group "VolGroup" successfully extended
[[email protected] ~]# lvs  LV      VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert  lv_root VolGroup -wi-ao----   6.71g                                                      lv_swap VolGroup -wi-ao---- 816.00m
[[email protected] ~]# lvextend -l  +100%FREE  /dev/VolGroup/lv_root   Size of logical volume VolGroup/lv_root changed from 6.71 GiB (1718 extents) to 14.71 GiB (3765 extents).  Logical volume lv_root successfully resized
[[email protected] ~]# resize2fs  /dev/VolGroup/lv_rootresize2fs 1.41.12 (17-May-2010)Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing requiredold desc_blocks = 1, new_desc_blocks = 1Performing an on-line resize of /dev/VolGroup/lv_root to 3855360 (4k) blocks.The filesystem on /dev/VolGroup/lv_root is now 3855360 blocks long.

6.再次查看vm的磁碟大小

[[email protected] ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root                       15G  652M   13G   5% /tmpfs                 246M     0  246M   0% /dev/shm/dev/vda1             477M   25M  427M   6% /boot

方法二:擴充原有磁碟的大小

1.查看原磁碟的大小

[[email protected] vm]# qemu-img  info  /vm/api2-qcow2.img image: /vm/api2-qcow2.imgfile format: qcow2virtual size: 8.0G (8589934592 bytes)disk size: 2.4Gcluster_size: 65536Snapshot list:ID        TAG                 VM SIZE                DATE       VM CLOCK2         api2_ftp               320M 2016-01-08 16:59:52   01:17:18.6393         api2_httpd             385M 2016-01-08 17:27:16   00:53:48.096

2.關閉vm,然後直接擴充api2-qcow2.img

[[email protected] vm]# virsh  shutdown  api2

域 api2 被關閉

[[email protected] vm]# virsh  list --all Id    名稱                         狀態---------------------------------------------------- 3     api1                           running -     api2                           關閉
[[email protected] vm]# qemu-img   resize  api2-qcow2.img  +8GThis image format does not support resize   //提示不能這種格式不支援擴充
[[email protected] vm]# virsh  歡迎使用 virsh,虛擬化的互動式終端。輸入:‘help‘ 來獲得命令的協助資訊       ‘quit‘ 退出virsh # snapshot-list  api2 名稱               Creation Time             狀態------------------------------------------------------------ api2_ftp             2016-01-08 16:59:52 +0800 running api2_httpd           2016-01-08 17:27:16 +0800 runningvirsh # snapshot-delete   apiapi1-qcow2_add1.img  api1-qcow2.img       api2-qcow2.img       virsh # snapshot-delete   api2   api2_ftpDomain snapshot api2_ftp deletedvirsh # snapshot-delete   api2   api2_httpdDomain snapshot api2_httpd deleted

[[email protected] vm]# qemu-img   resize  api2-qcow2.img  +8GImage resized.

3.查看已經擴充的磁碟

[[email protected] vm]# qemu-img    info   api2-qcow2.img image: api2-qcow2.imgfile format: qcow2virtual size: 16G (17179869184 bytes)disk size: 2.4Gcluster_size: 65536

4.啟動vm,然後分區,並格式化

[[email protected] vm]# virsh  start  api2域 api2 已開始

[[email protected] ~]# pvcreate  /dev/vda3  Physical volume "/dev/vda3" successfully created

[[email protected] ~]# vgs  VG       #PV #LV #SN Attr   VSize VFree  VolGroup   1   2   0 wz--n- 7.51g    0
[[email protected] ~]# vgextend   VolGroup  /dev/vda3  Volume group "VolGroup" successfully extended
[[email protected] ~]# lvextend   -l  +100%FREE  /dev/VolGroup/lv_root  Size of logical volume VolGroup/lv_root changed from 6.71 GiB (1718 extents) to 14.71 GiB (3765 extents).  Logical volume lv_root successfully resized
[[email protected] ~]# resize2fs   /dev/VolGroup/lv_rootresize2fs 1.41.12 (17-May-2010)Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing requiredold desc_blocks = 1, new_desc_blocks = 1Performing an on-line resize of /dev/VolGroup/lv_root to 3855360 (4k) blocks.The filesystem on /dev/VolGroup/lv_root is now 3855360 blocks long.

[[email protected] ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root                       15G  655M   13G   5% /tmpfs                 246M     0  246M   0% /dev/shm/dev/vda1             477M   25M  427M   6% /boot



成功添加了磁碟.

本文出自 “不求最好,只求更好” 部落格,請務必保留此出處http://yujianglei.blog.51cto.com/7215578/1733873

KVM總結文檔二(CentOS-6.5)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.