Skip to content

Instantly share code, notes, and snippets.

@artsok
Last active December 7, 2021 17:33
Show Gist options
  • Save artsok/dde1b6d53fcd3893d2560d0b5c596835 to your computer and use it in GitHub Desktop.
Save artsok/dde1b6d53fcd3893d2560d0b5c596835 to your computer and use it in GitHub Desktop.
Moon - Windows Image
If you have your local company image (*.img) and you want to make qemu snapshot from it, follow next steps:
For example, let's say we have image: as-win7-v33-1.img
1. Create shapshot
qemu-img create -b as-win7-v33-1.img -f qcow2 snapshot.img
2. Load and save state to snapshot. Image (as-win7-v33-1.img) located at the same path as snapshot.img. Don't forget to change SCREEN RESOLUTION in snapshot.
qemu-system-x86_64 -machine q35 -smp sockets=1,cores=2,threads=2 -m 2048 -usb -device usb-tablet -enable-kvm -net nic,model=virtio -net user,hostfwd=tcp::4444-:4444,hostfwd=tcp::8080-:8080 -drive file=snapshot.img,media=disk,snapshot=off,format=qcow2,if=virtio -rtc base=localtime -monitor stdio
2.1 Make changes and save state
(qemu) savevm windows
(qemu) quit
2.2 Check snapshot. Load state
qemu-system-x86_64 -machine q35 -smp sockets=1,cores=2,threads=2 -m 2048 -usb -device usb-tablet -enable-kvm -net nic,model=virtio -net user,hostfwd=tcp::4444-:4444,hostfwd=tcp::8080-:8080 -drive file=snapshot.img,media=disk,snapshot=off,format=qcow2,if=virtio -rtc base=localtime -loadvm windows
3. In my way, I have image (as-win7-v33-1.img) about 30GB size. Moved it to another directory
4. Fixed entrypoint.sh
#!/bin/sh
#!/bin/bash
SCREEN_RESOLUTION=${SCREEN_RESOLUTION:-"1280x1024x24"}
ENABLE_WINDOW_MANAGER=${ENABLE_WINDOW_MANAGER:-""}
DISPLAY_NUM=99
export DISPLAY=":$DISPLAY_NUM"
VERBOSE=${VERBOSE:-""}
if [ -n "$VERBOSE" ]; then
sed -i 's|@@DRIVER_ARGS@@|, "--log", "debug"|g' /etc/selenoid/browsers.json
fi
clean() {
if [ -n "$XVFB_PID" ]; then
kill -TERM "$XVFB_PID"
fi
if [ -n "$X11VNC_PID" ]; then
kill -TERM "$X11VNC_PID"
fi
}
trap clean SIGINT SIGTERM
xvfb-run -l -n $DISPLAY_NUM -s "-ac -screen 0 $SCREEN_RESOLUTION -noreset -listen tcp" \
qemu-system-x86_64 -machine q35 -smp sockets=1,cores=2,threads=2 -m 2048 \
-usb -device usb-tablet -enable-kvm -net nic,model=virtio \
-net user,hostfwd=tcp::4444-:4444,hostfwd=tcp::8080-:8080 \
-drive file=snapshot.img,media=disk,snapshot=off,format=qcow2,if=virtio \
-rtc base=localtime -loadvm windows &
XVFB_PID=$!
retcode=1
until [ $retcode -eq 0 ]; do
xdpyinfo -display $DISPLAY >/dev/null 2>&1
retcode=$?
if [ $retcode -ne 0 ]; then
echo Waiting xvfb...
sleep 1
fi
done
x11vnc -display $DISPLAY -passwd selenoid -shared -forever -loop500 -rfbport 5900 -rfbportv6 5900 -logfile /dev/null &
X11VNC_PID=$!
wait
5. Fixed Dockerfile
FROM ubuntu:18.04
RUN apt update && \
apt -y upgrade && \
apt -y install xvfb x11-utils x11vnc qemu
COPY snapshot.img /
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
6. Build docker image
docker build -t windows/ie:11 .
7. Run docker image. Set image as volume
docker run -it --rm --privileged --volume /home/artsok/workspace/as-win7-v33-1.img:/as-win7-v33-1.img -p 4444:4444 -p 5900:5900 windows/ie:11
8. View Windows screen inside running container. selenoid as password
sudo apt install virt-viewer
remote-viewer vnc://localhost:5900
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment