標籤:kvm
磁碟不夠使用,添加新的硬碟,或者擴容當前磁碟。
1、子機的當前磁碟狀態
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/74/96/wKiom1YiXBGSEgqpAAENvM3dPMY211.jpg" title="Image.png" alt="wKiom1YiXBGSEgqpAAENvM3dPMY211.jpg" />
母機中查看該系統
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/74/96/wKiom1YiXEaQxodAAAFrPP8G_SM586.jpg" title="Image.png" alt="wKiom1YiXEaQxodAAAFrPP8G_SM586.jpg" />
[[email protected] ~]# qemu-img resize /caimz/caimz2.img +5G
Image resized.
[[email protected] ~]# qemu-img info /caimz/caimz2.img
image: /caimz/caimz2.img
file format: raw
virtual size: 35G (37580963840 bytes)
disk size: 30G
[[email protected] ~]# virsh start caimz2 --console
error: Domain is already active
[[email protected] ~]#
[[email protected] ~]# virsh start caimz2 --console
error: Domain is already active
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/74/96/wKiom1YiXGbRp6zjAAKVR0L0mWs869.jpg" title="Image.png" alt="wKiom1YiXGbRp6zjAAKVR0L0mWs869.jpg" />
操作步驟:
[[email protected] ~]# fdisk -l
Disk /dev/vda: 37.6 GB, 37580963840 bytes
16 heads, 63 sectors/track, 72817 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: 0x0004583c
Device Boot Start End Blocks Id System
/dev/vda1 * 3 1018 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2 1018 62416 30944256 8e Linux LVM
Partition 2 does not end on cylinder boundary.
Disk /dev/mapper/VolGroup-lv_root: 30.6 GB, 30610030592 bytes
255 heads, 63 sectors/track, 3721 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: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0x00000000
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
28G 720M 26G 3% /
tmpfs 250M 0 250M 0% /dev/shm
/dev/vda1 477M 31M 421M 7% /boot
[[email protected] ~]# fdisk -l
Disk /dev/vda: 37.6 GB, 37580963840 bytes
16 heads, 63 sectors/track, 72817 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: 0x0004583c
Device Boot Start End Blocks Id System
/dev/vda1 * 3 1018 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2 1018 62416 30944256 8e Linux LVM
Partition 2 does not end on cylinder boundary.
Disk /dev/mapper/VolGroup-lv_root: 30.6 GB, 30610030592 bytes
255 heads, 63 sectors/track, 3721 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: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0x00000000
[[email protected] ~]# fdisk /dev/vda
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 (1-72817, default 1): 62417
Last cylinder, +cylinders or +size{K,M,G} (62416-72817, default 72817): 72817
Command (m for help): p
Disk /dev/vda: 37.6 GB, 37580963840 bytes
16 heads, 63 sectors/track, 72817 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: 0x0004583c
Device Boot Start End Blocks Id System
/dev/vda1 * 3 1018 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2 1018 62416 30944256 8e Linux LVM
Partition 2 does not end on cylinder boundary.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 4
First cylinder (1-72817, default 1): 62417 #inode 在/dev/vda2 都是62416 所以應從62417開始
Last cylinder, +cylinders or +size{K,M,G} (62417-72817, default 72817): 72817#結束
Command (m for help): p
Disk /dev/vda: 37.6 GB, 37580963840 bytes
16 heads, 63 sectors/track, 72817 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: 0x0004583c
Device Boot Start End Blocks Id System
/dev/vda1 * 3 1018 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2 1018 62416 30944256 8e Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda4 62417 72817 5242104 83 Linux #新增加的那5G
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.
[[email protected] ~]# fdisk -l
Disk /dev/vda: 37.6 GB, 37580963840 bytes
16 heads, 63 sectors/track, 72817 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: 0x0004583c
Device Boot Start End Blocks Id System
/dev/vda1 * 3 1018 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2 1018 62416 30944256 8e Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda4 62417 72817 5242104 83 Linux
Disk /dev/mapper/VolGroup-lv_root: 30.6 GB, 30610030592 bytes
255 heads, 63 sectors/track, 3721 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: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0x00000000
建立物理卷
然後再把這個/dev/vda4 加入到lvm裡面去:
ls /dev/vda4 如果沒有這個分區,需要重啟一下。
[[email protected] ~]# pvcreate /dev/vda4
Physical volume "/dev/vda4" successfully created
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/74/93/wKioL1YiXLOxka8FAACc7M6-1Mc723.jpg" title="Image.png" alt="wKioL1YiXLOxka8FAACc7M6-1Mc723.jpg" />
現在吧vda4加入到VolGroup裡面
[[email protected] ~]# vgextend VolGroup /dev/vda4
Volume group "VolGroup" successfully extended
查看vda4是不是屬於VolGroup組裡面。
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/74/96/wKiom1YiXK-QwtoDAACzxWmJHAg257.jpg" title="Image.png" alt="wKiom1YiXK-QwtoDAACzxWmJHAg257.jpg" />
[[email protected] ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 2 2 0 wz--n- 34.50g 5.00g
看邏輯卷
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 28.51g
lv_swap VolGroup -wi-ao---- 1.00g
現在要把之前添加的5G 加到lv_root裡面
[[email protected] ~]# lvextend -l +100%FREE /dev/VolGroup/lv_root
Size of logical volume VolGroup/lv_root changed from 28.51 GiB (7298 extents) to 33.50 GiB (8577 extents).
Logical volume lv_root successfully resized
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 33.50g
lv_swap VolGroup -wi-ao---- 1.00g
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/74/96/wKiom1YiXNTy73oDAASKVVNECgg938.jpg" title="Image.png" alt="wKiom1YiXNTy73oDAASKVVNECgg938.jpg" />650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/74/93/wKioL1YiXQqjJq7yAAPKqaulDW8909.jpg" title="Image.png" alt="wKioL1YiXQqjJq7yAAPKqaulDW8909.jpg" />
增加一個新的硬碟來擴容:
1、建立新的磁碟
[[email protected] ~]# qemu-img create -f raw /caimz/caimz2_extend.img 5G
Formatting ‘/caimz/caimz2_extend.img‘, fmt=raw size=5368709120
2、編輯設定檔
[[email protected] ~]# virsh edit caimz2
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/74/96/wKiom1YiXQXDA6LvAAN8_HpA0vg800.jpg" title="Image.png" alt="wKiom1YiXQXDA6LvAAN8_HpA0vg800.jpg" />
添加剛才建立的.img磁碟。
virsh edit caimz2 增加如下:
<disk type=‘file‘ device=‘disk‘>
<driver name=‘qemu‘ type=‘raw‘ cache=‘none‘/>
<source file=‘/caimz/caimz2_extend.img‘/>
<target dev=‘vdb‘ bus=‘virtio‘/>
<address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x07‘ function=‘0x0‘/>
</disk>
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/74/93/wKioL1YiXUHAGQH0AALz8426WJ8141.jpg" title="Image.png" alt="wKioL1YiXUHAGQH0AALz8426WJ8141.jpg" />
儲存退出。
[[email protected] ~]# virsh edit caimz2
Domain caimz2 XML configuration edited.
開啟虛擬機器:virsh start ciamz2
進入虛擬機器:virsh console caizm2
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/74/97/wKiom1YiXTDyojYOAAMtzn3leS0294.jpg" title="Image.png" alt="wKiom1YiXTDyojYOAAMtzn3leS0294.jpg" /> 格式化:mkfs.ext4 /dev/vdb
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/74/97/wKiom1YiXUOz3HNOAAJ7YZ0X0W8035.jpg" title="Image.png" alt="wKiom1YiXUOz3HNOAAJ7YZ0X0W8035.jpg" />
掛載使用。
[[email protected] ~]# qemu-img resize /caimz/caimz1.qcow2 +5G
This image format does not support resize
KVM ---- 虛擬磁碟擴容