" /> " />

目 录CONTENT

文章目录

从qcow2和xml启动虚机(持续更新)

Administrator
2024-09-06 / 0 评论 / 0 点赞 / 25 阅读 / 7844 字

虚机管理

[root@NMA04-304-D-06-SEV-NF5468M5-04U25 raid]# lsblk

NAME    MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda       8:0    0 447.1G  0 disk  
├─sda1    8:1    0   200M  0 part  /boot/efi
├─sda2    8:2    0     1G  0 part  /boot
└─sda3    8:3    0 445.9G  0 part  /
sdb       8:16   0   1.8T  0 disk  
└─sdb1    8:17   0   1.8T  0 part  
  └─md0   9:0    0   1.8T  0 raid1 /mnt/raid
sdc       8:32   0   1.8T  0 disk  
└─sdc1    8:33   0   1.8T  0 part  
  └─md0   9:0    0   1.8T  0 raid1 /mnt/raid
[root@NMA04-304-D-06-SEV-NF5468M5-04U25 raid]# pwd
/mnt/raid
[root@NMA04-304-D-06-SEV-NF5468M5-04U25 raid]# ll -rht
total 24K
drwx------. 2 root root  16K Sep  5 11:44 lost+found
drwxr-xr-x. 2 root root 4.0K Sep  5 11:52 qcow2
drwxr-xr-x. 2 root root 4.0K Sep  5 11:55 os

文件位置

  • 卷:/mnt/raid
  • 磁盘:/dev/sdb1 and /dev/sdc1

磁盘raid(可选)

将前面的sdb 和 sdc组raid1,挂载到/mnt/raid,待补充

虚机配置

/mnt/raid/os,里面有qcow2和xml文件

<?xml version="1.0" encoding="utf-8"?>

<domain type="kvm" id="44"> 
  <name>centos_1</name>  
  <metadata> 
    <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">  
      <libosinfo:os id="http://redhat.com/rhl/7"/> 
    </libosinfo:libosinfo> 
  </metadata>  
  <memory unit="KiB">16777216</memory>  
  <currentMemory unit="KiB">16777216</currentMemory>  
  <vcpu placement="static">16</vcpu>  
  <resource> 
    <partition>/machine</partition> 
  </resource>  
  <os> 
    <type arch="x86_64">hvm</type>  
    <boot dev="hd"/> 
  </os>  
  <features> 
    <acpi/>  
    <apic/> 
  </features>  
  <cpu mode='host-model' check='partial'/>
  <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" cache="none"/>  
      <source file="/mnt/raid/os/CentOS-7-x86_64-GenericCloud.qcow2" index="1"/>  
      <backingStore/>  
      <target dev="sda" bus="scsi"/>  
      <alias name="scsi0-0-0-0"/>  
      <address type="drive" controller="0" bus="0" target="0" unit="0"/> 
    </disk>  
    <controller type="usb" index="0" model="ich9-ehci1"> 
      <alias name="usb"/>  
      <address type="pci" domain="0x0000" bus="0x00" slot="0x04" 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="0x04" function="0x0" multifunction="on"/> 
    </controller>  
    <interface type='network'>
      <source network='default'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <controller type="usb" index="0" model="ich9-uhci2"> 
      <alias name="usb"/>  
      <master startport="2"/>  
      <address type="pci" domain="0x0000" bus="0x00" slot="0x04" 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="0x04" function="0x2"/> 
    </controller>  
    <controller type="pci" index="0" model="pci-root"> 
      <alias name="pci.0"/> 
    </controller>  
    <controller type="scsi" index="0" model="virtio-scsi"> 
      <alias name="scsi0"/>  
      <address type="pci" domain="0x0000" bus="0x00" slot="0x05" function="0x0"/> 
    </controller>  
    <controller type="virtio-serial" index="0"> 
      <alias name="virtio-serial0"/>  
      <address type="pci" domain="0x0000" bus="0x00" slot="0x06" function="0x0"/> 
    </controller>  
    <serial type="pty"> 
      <source path="/dev/pts/3"/>  
      <target type="isa-serial" port="0"> 
        <model name="isa-serial"/> 
      </target>  
      <alias name="serial0"/> 
    </serial>  
    <console type="pty" tty="/dev/pts/3"> 
      <source path="/dev/pts/3"/>  
      <target type="serial" port="0"/>  
      <alias name="serial0"/> 
    </console>  
    <channel type="unix"> 
      <source mode="bind" path="/var/lib/libvirt/qemu/org.qemu.guest_agent.0.13b421fe-bc3f-7b60-da01-d00b1ebd45fb.sock"/>  
      <target type="virtio" name="org.qemu.guest_agent.0" state="connected"/>  
      <alias name="channel0"/>  
      <address type="virtio-serial" controller="0" bus="0" port="1"/> 
    </channel>  
    <input type="mouse" bus="ps2"> 
      <alias name="input0"/> 
    </input>  
    <input type="keyboard" bus="ps2"> 
      <alias name="input1"/> 
    </input>  
    <graphics type="vnc" port="5903" autoport="yes" listen="0.0.0.0"> 
      <listen type="address" address="0.0.0.0"/> 
    </graphics>  
    <video> 
      <model type="qxl" ram="65536" vram="65536" vgamem="16384" heads="1" primary="yes"/>  
      <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="0x07" function="0x0"/> 
    </memballoon> 
  </devices>  
  <seclabel type="dynamic" model="dac" relabel="yes"> 
    <label>+107:+985</label>  
    <imagelabel>+107:+985</imagelabel> 
  </seclabel> 
</domain>

虚机管理

virsh list --all

virsh define .xml

virsh start

virsh console

修改虚机大小

  • 需要需求在shutdown状态修改

qemu-img resize CentOS-7-x86_64-GenericCloud.qcow2 200G

  • 需要虚机在start状态重新对分区

分区表

fdisk /dev/sda

需要删除分区
需要重建分区
使用默认配置即可,最大分区

partprobe

cat /proc/mounts

xfs_growfs /dev/sda1

[root@localhost ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
└─sda1   8:1    0  200G  0 part /

修改虚机密码

  • 此命令会直接修改qcow2

virsh set-user-password centos_1 root XXXXX

密码示例

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区