一、添加磁盘
物理机上操作:
1.1、创建磁盘
# qemu-img create -f qcow2 hadoop1246_1.qcow2 100G
1.2、 给虚拟机添加磁盘
# virsh attach-disk hadoop1247 /data/disk/hadoop1247_1.qcow2 vdb --cache=none --subdriver=qcow2
Disk attached successfully
1.3、 虚拟机上检查磁盘
# fdisk -l|grep -i disk
Disk /dev/sda: 53.7 GB, 53687091200 bytes
Disk identifier: 0x0007c952
Disk /dev/mapper/VolGroup-lv_root: 47.8 GB, 47789899776 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 5368 MB, 5368709120 bytes
Disk identifier: 0x00000000
Disk /dev/vda: 107.4 GB, 107374182400 bytes
Disk identifier: 0x00000000
Disk /dev/vda: 107.4 GB, 107374182400 bytes即为新增磁盘
1.4、 将磁盘配置信息写入到xml文件中(标红部分)
virsh # dumpxml hadoop1247
<domain type='kvm' id='3'>
<name>hadoop1247</name>
<uuid>c5114a7a-2f71-4846-805d-504ef543efff</uuid>
<memory unit='KiB'>8388608</memory>
<currentMemory unit='KiB'>8388608</currentMemory>
<vcpu placement='static'>2</vcpu>
<resource>
<partition>/machine</partition>
</resource>
<os>
<type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu mode='custom' match='exact'>
<model fallback='allow'>IvyBridge</model>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
<on\_poweroff>destroy</on\_poweroff>
<on\_reboot>restart</on\_reboot>
<on\_crash>restart</on\_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/data/hadoop/hadoop1247.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw'/>
<backingStore/>
<target dev='hdb' bus='ide'/>
<readonly/>
<alias name='ide0-0-1'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
**<disk type='file' device='disk'>**
** <driver name='qemu' type='qcow2' cache='none'/>**
** <source file='/data/disk/hadoop1247_1.qcow2'/>**
** <backingStore/>**
** <target dev='vdb' bus='virtio'/>**
** <alias name='virtio-disk1'/>**
** <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>**
** </disk>**
<controller type='usb' index='0' model='ich9-ehci1'>
<alias name='usb'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci1'>
<alias name='usb'/>
<master startport='0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci2'>
<alias name='usb'/>
<master startport='2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci3'>
<alias name='usb'/>
<master startport='4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'>
<alias name='pci.0'/>
</controller>
<controller type='ide' index='0'>
<alias name='ide'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<interface type='bridge'>
<mac address='52:54:00:4b:9b:d6'/>
<source bridge='br0'/>
<target dev='vnet1'/>
<model type='rtl8139'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<source path='/dev/pts/2'/>
<target port='0'/>
<alias name='serial0'/>
</serial>
<console type='pty' tty='/dev/pts/2'>
<source path='/dev/pts/2'/>
<target type='serial' port='0'/>
<alias name='serial0'/>
</console>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='5901' autoport='yes' listen='127.0.0.1'>
<listen type='address' address='127.0.0.1'/>
</graphics>
<video>
<model type='cirrus' vram='16384' heads='1'/>
<alias name='video0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<alias name='balloon0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</memballoon>
</devices>
<seclabel type='dynamic' model='selinux' relabel='yes'>
<label>system\_u:system\_r:svirt_t:s0:c309,c550</label>
<imagelabel>system\_u:object\_r:svirt\_image\_t:s0:c309,c550</imagelabel>
</seclabel>
</domain>
virsh # edit hadoop1247
二、扩展虚拟机/目录
2.1、给新增的盘 /dev/vda创建分区
# fdisk /dev/vda
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-208050, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-208050, default 208050):
Using default value 208050
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
进入交互模式,敲n创建新分区,敲p创建首要分区,敲1从1开始敲回车磁盘空间全选,敲w完成并保存退出。
2.2、查看虚拟机的磁盘分区情况
# fdisk -l
Disk /dev/vda: 107.4 GB, 107374182400 bytes
16 heads, 63 sectors/track, 208050 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: 0x9c3dc3ae
Device Boot Start End Blocks Id System
**/dev/vda1 1 208050 104857168+ 83 Linux**
2.3、创建逻辑卷
# pvcreate /dev/vda1
Physical volume "/dev/vda1" successfully created
# vgscan
Reading all physical volumes. This may take a while...
Found volume group "**VolGroup**" using metadata type lvm2
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/**VolGroup**-lv_root
44G 3.5G 39G 9% /
tmpfs 3.9G 72K 3.9G 1% /dev/shm
/dev/sda1 477M 33M 419M 8% /boot
2.4、扩展/目录
# vgextend VolGroup /dev/vda1
Volume group "VolGroup" successfully extended
# lvextend -l +100%FREE /dev/mapper/VolGroup-lv_root
Size of logical volume VolGroup/lv_root changed from 44.51 GiB (11394 extents) to 144.50 GiB (36993 extents).
Logical volume lv_root successfully resized
# 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 = 10
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 37880832 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 37880832 blocks long.
# df -h
Filesystem Size Used Avail Use% Mounted on
**/dev/mapper/VolGroup-lv_root**
** 143G 3.5G 132G 3% /**
tmpfs 3.9G 72K 3.9G 1% /dev/shm
/dev/sda1 477M 33M 419M 8% /boot
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
** lv_root VolGroup -wi-ao---- 144.50g**
lv_swap VolGroup -wi-ao---- 5.00g
磁盘空间已成功在线扩展。
参考链接
http://www.it165.net/os/html/201309/6249.html