mac.qemu.xp.虚拟机.开机就还原的虚拟机

创建虚拟机镜像

$ qemu-img create -f qcow2 100G.qcow2 100G
$ qemu-img info 100G.qcow2
image: 100G.qcow2
file format: qcow2
virtual size: 100 GiB (107374182400 bytes)
disk size: 196 KiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

创建的镜像是一个稀疏文件,也就是说刚创建出来的文件并没有100G,它会随着数据的增多慢慢增加

启动镜像安装系统

准备virtio镜像

到 https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/ 下载驱动。安装驱动可以在安装时就指定好驱动文件,后面系统安装成功后,再安装下网卡驱动即可。

指定virtio驱动+安装xp

(XP的安装程序只支持从软盘加载驱动程序)

$qemu-system-x86_64 
-drive file=./100G.qcow2,format=qcow2,cache=none,if=virtio 
-m 1512 
-net nic,model=virtio -net user 
-fda ./virtio-win_x86.vfd 
-cdrom ./xp_professional_with_service_pack_3_x86.iso -boot d

有看到个参数,format=qcow2,未试过,应该没什么问题

$qemu-system-x86_64 
-drive file=./100G.qcow2,format=qcow2,cache=none,if=virtio 
-m 1512 
-net nic,model=virtio -net user 
-fda ./virtio-win_x86.vfd 
-cdrom ./xp_professional_with_service_pack_3_x86.iso -boot d

其中部分参数说明如下:

  • -cdrom file-boot d

    指定启动光盘,并指定启动顺序为从光盘启动:

    -cdrom file     use 'file' as IDE cdrom image (cdrom is ide1 master)
    
    -boot [order=drives][,once=drives][,menu=on|off]
          [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time][,strict=on|off]
                    'drives': floppy (a), hard disk (c), CD-ROM (d), network (n)
                    'sp_name': the file's name that would be passed to bios as logo picture, if menu=on
                    'sp_time': the period that splash picture last if menu=on, unit is ms
                    'rb_timeout': the timeout before guest reboot when boot failed, unit is ms
    
  • -m 1512

    指定内存的大小

    -m [size=]megs[,slots=n,maxmem=size]
                    configure guest RAM
                    size: initial amount of guest memory
                    slots: number of hotplug slots (default: none)
                    maxmem: maximum amount of guest memory (default: none)
    

启动后到安装界面时按F6:

到安装界面时按F6

第一个

按提示选择,我们是第一个

回车继续

后面会有个警告提示,按提示操作

当然是继续安装啦

安装后,进入桌面,我的电脑-》设备管理

看下C盘的属性

image.png

网卡的要再安装下

可以看到网卡的驱动还是问号,继续安装下:

仍然继续

安全完毕

平时启动

$qemu-system-x86_64 
-drive file=./100G.qcow2,format=qcow2,cache=none,if=virtio 
-m 1512 
-net nic,model=virtio -net user 

使用远程桌面连接

主要使用参数-nographic -vnc :0

注:-vnc与:0之间有空格

$qemu-system-x86_64 
-drive file=./100G.qcow2,format=qcow2,cache=none,if=virtio 
-m 1512 
-net nic,model=virtio -net user 
-nographic -vnc :0

使用vncviewer连接就可以了,下图是我的设置,就一个0,如果上面的命令是1,这边也是1

image.png

远程桌面连接鼠标位置不准

需要两个操作

1.将提高指针精确度关闭

不选

2.启动虚拟机时加上参数-usbdevice tablet

现在启动命令是

$qemu-system-x86_64 
-drive file=./100G.qcow2,format=qcow2,cache=none,if=virtio 
-m 1512 
-net nic,model=virtio -net user 
-nographic -vnc :0
-usbdevice tablet

会好一些,但还有一些偏移就是了

虚拟机关机还原

如果是想试验某个操作,比如当某个软件的小白鼠,使用-snapshot参数:

-snapshot       write to temporary files instead of disk image files
$qemu-system-x86_64 
-drive file=./100G.qcow2,format=qcow2,cache=none,if=virtio 
-m 1512 
-net nic,model=virtio -net user 
-nographic -vnc :0
-usbdevice tablet
-snapshot

注意,重新启动后,变化还是在的,是在完全关机后再用命令启动,就还原成之前的状态了。

参考

1.https://www.cnblogs.com/jusonalien/p/4772618.html 
  qemu-kvm磁盘读写的缓冲(cache)的五种模式
2.https://blog.csdn.net/jinguangliu/article/details/50661982
  磁盘格式

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章