zoukankan      html  css  js  c++  java
  • 搭建KVM环境——06 创建虚拟机

    若转载请于明显处标明出处:https://www.cnblogs.com/kelamoyujuzhen/p/9071181.html

    虚拟机磁盘格式

    创建一个raw格式的虚拟机磁盘

    [root@CenoOS1 opt]# qemu-img create -f raw CentOS-7.2-x86_64.raw 10G
    Formatting 'CentOS-7.2-x86_64.raw', fmt=raw size=10737418240 
    [root@CenoOS1 opt]# ll -h
    total 16K
    -rw-r--r-- 1 root root 10G May 22 19:23 CentOS-7.2-x86_64.raw
    drwx------ 2 root root 16K May 22 19:03 lost+found

    使用物理机上面的安装盘制作一个ISO文件放到KVM虚拟机里面,会比较耗时,因为要从物理机里面要一份到虚拟机里面

    [root@CenoOS1 opt]# dd if=/dev/cdrom of=/opt/CentOS-7.2.iso
    8456192+0 records in
    8456192+0 records out
    4329570304 bytes (4.3 GB) copied, 78.9541 s, 54.8 MB/s
    [root@CenoOS1 opt]# ll -h
    total 4.1G
    -rw-r--r-- 1 root root 4.1G May 22 19:32 CentOS-7.2.iso
    -rw-r--r-- 1 root root  10G May 22 19:23 CentOS-7.2-x86_64.raw
    drwx------ 2 root root  16K May 22 19:03 lost+found

    下面创建虚拟机

    [root@CenoOS1 opt]# virt-install --name CentOS-7-x86_64 --virt-type kvm --ram 1024 --cdrom=/opt/CentOS-7.2.iso --disk path=/opt/CentOS-7.2-x86_64.raw --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole

     执行完命令以后立即登陆VNC来安装Linux。VNC参考:TightVNC安装

    在VNC里面安装虚拟机和搭建KVM环境——01 创建虚拟机(最小化安装)过程一样

     

    按照到最后重启,这是VNC会优雅的退出。如果尝试VNC连接,是链接不上的。查看虚拟机状态,是关闭的。打开虚拟机,再次用VNC连接,连接OK。

    [root@CenoOS1 opt]# virsh list --all
     Id    Name                           State
    ----------------------------------------------------
     -     CentOS-7-x86_64                shut off
    
    [root@CenoOS1 opt]# virsh start CentOS-7-x86_64
    Domain CentOS-7-x86_64 started
    
    [root@CenoOS1 opt]# virsh list --all
     Id    Name                           State
    ----------------------------------------------------
     3     CentOS-7-x86_64                running

    查看刚刚创建虚拟机的配置文件

    [root@CenoOS1 qemu]# ll -h
    total 4.0K
    -rw------- 1 root root 3.8K May 23 03:56 CentOS-7-x86_64.xml
    drwx------ 3 root root   40 May 22 18:39 networks

    virsh edit domain可以编辑虚拟机配置文件

    不光KVM 虚拟机有配置文件,KVM宿主机也有配置文件

     再创建一台winXP

    拷贝winxp的镜像文件到虚拟机磁盘

    [root@CenoOS1 opt]# dd if=/dev/cdrom of=/opt/win-xp.iso
    1281660+0 records in
    1281660+0 records out
    656209920 bytes (656 MB) copied, 43.354 s, 15.1 MB/s
    [root@CenoOS1 opt]# ll -h
    total 5.8G
    -rw-r--r-- 1 qemu qemu 4.1G May 22 19:32 CentOS-7.2.iso
    -rw-r--r-- 1 root root  10G May 23 04:31 CentOS-7.2-x86_64.raw
    drwx------ 2 root root  16K May 22 19:03 lost+found
    -rw-r--r-- 1 root root 626M May 23 07:23 win-xp.iso

    创建虚拟机磁盘文件

    [root@CenoOS1 opt]# qemu-img create -f raw /opt/win-xp.raw 10G
    Formatting '/opt/win-xp.raw', fmt=raw size=10737418240 
    [root@CenoOS1 opt]# ll -h
    total 5.8G
    -rw-r--r-- 1 qemu qemu 4.1G May 22 19:32 CentOS-7.2.iso
    -rw-r--r-- 1 root root  10G May 23 04:31 CentOS-7.2-x86_64.raw
    drwx------ 2 root root  16K May 22 19:03 lost+found
    -rw-r--r-- 1 root root 626M May 23 07:23 win-xp.iso
    -rw-r--r-- 1 root root  10G May 23 07:28 win-xp.raw

    安装winxp虚拟机

    [root@CenoOS1 opt]# virt-install --name winxp1 --virt-type kvm --ram 1024 --cdrom=/opt/win-xp.iso --disk path=/opt/win-xp.raw --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole
    
    Starting install...
    Creating domain...                                                                   |    0 B  00:00:00     
    Domain installation still in progress. Waiting for installation to complete.

    同意许可协议那一步按F8,下面创建一个分区,按C

    指定一个8G的分区

    在新创建的分区上安装OS

    复制结束后会要求重启,引入一个问题,VNC断开连接,而且重启系统的时候,winxp虚拟机找不到安装盘。编辑虚拟机配置文件,让他启动时自动加载iso文件

    [root@CenoOS1 opt]# cd /etc/libvirt/qemu
    [root@CenoOS1 qemu]# ls
    CentOS-7-x86_64.xml  networks  winxp1.xml
    [root@CenoOS1 qemu]# virsh edit winxp1.xml 
    error: failed to get domain 'winxp1.xml'
    error: Domain not found: no domain with matching name 'winxp1.xml'
    
    [root@CenoOS1 qemu]# virsh edit winxp1
    Domain winxp1 XML configuration edited.
    
    [root@CenoOS1 qemu]# 

    修改完后启动虚拟机

    [root@CenoOS1 qemu]# virsh start winxp1
    Domain winxp1 started

     密钥:MRX3F-47B9T-2487J-KWKMF-RPWBY

    剩下一路默认,安装过程会比较耗时,建议在固态磁盘上做实验。

  • 相关阅读:
    python note 30 断点续传
    python note 29 线程创建
    python note 28 socketserver
    python note 27 粘包
    python note 26 socket
    python note 25 约束
    Sed 用法
    python note 24 反射
    python note 23 组合
    python note 22 面向对象成员
  • 原文地址:https://www.cnblogs.com/kelamoyujuzhen/p/9071181.html
Copyright © 2011-2022 走看看