DEV Community

Cover image for QEMU VM with snapshot setup + samba file sharing
Guilherme Sousa
Guilherme Sousa

Posted on • Edited on

QEMU VM with snapshot setup + samba file sharing

Requirements

  • telnet
  • qemu
  • samba

Command to install the requirements:

apt-get update && \
  apt-get install -y \
  qemu-system-x86 libvirt-clients \
  libvirt-daemon qemu-kvm samba telnet
Enter fullscreen mode Exit fullscreen mode

Lets do it

Assuming that our terminal is open at /opt/vm create the folder that will be shared with the VM:

mkdir -p shared-resources
Enter fullscreen mode Exit fullscreen mode

Considering that the VM is located in /opt/vm/system-image/windows-11 create the snapshot image /opt/vm/snapshot:

qemu-img create -b /opt/vm/system-image/windows-11 -f qcow2 -F qcow2 /opt/vm/snapshot
Enter fullscreen mode Exit fullscreen mode

Now, run the VM using the previously created snapshot image file and enable the monitor via telnet:

qemu-system-x86_64 -enable-kvm \
    -machine q35 -m 4096 -smp 2 \
    -usb -device usb-kbd -device usb-tablet -rtc base=localtime \
    -device virtio-net-pci,netdev=net0 \
    -netdev user,id=net0,hostfwd=tcp::3000-:3389,hostfwd=tcp::2222-:22,smb=/opt/vm/shared-resources \
    -drive file=snapshot,media=disk,if=virtio \
    -monitor telnet:0.0.0.0:1234,server,nowait \
    -nographic -serial mon:stdio
Enter fullscreen mode Exit fullscreen mode

To save the vm snapshot its recommended to wait for the desired system state before "taking a picture" of it.
Considering that the VM is in the expected state, let's save it:

telnet localhost 1234
savevm state
Enter fullscreen mode Exit fullscreen mode

To close the telnet session press ctrl + [ and type q and ENTER.

With the snapshot saved, now it is possible to boot the VM and load our saved snapshot:

qemu-system-x86_64 -enable-kvm \
    -machine q35 -m 4096 -smp 2 \
    -usb -device usb-kbd -device usb-tablet -rtc base=localtime \
    -device virtio-net-pci,netdev=net0 \
    -netdev user,id=net0,hostfwd=tcp::3000-:3389,hostfwd=tcp::2222-:22,smb=/opt/vm/shared-resources \
    -drive file=/opt/vm/snapshot,media=disk,if=virtio \
    -loadvm state \
    -nographic -serial mon:stdio
Enter fullscreen mode Exit fullscreen mode

Inside the VM (connected remotely with RDP) you can access the shared folder using the following address: 10.0.2.4/qemu

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay