[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
howtos:emulators:helper_script_for_managing_qemu_virtual_machines [2016/09/01 06:30 (UTC)] – [A Smart Way to Input Data For New VM] louigi600 | howtos:emulators:helper_script_for_managing_qemu_virtual_machines [2016/09/02 08:04 (UTC)] – [Sources] louigi600 | ||
---|---|---|---|
Line 357: | Line 357: | ||
===== Networking ===== | ===== Networking ===== | ||
- | As mentioned above I want my VMs to look like real machines on the LAN the host server is connected on, this will require bridging the tap devices. Newer versions of qemu can automatically create and use tap0 but I don't think it would do the bridging | + | As mentioned above I want my VMs to look like real machines on the LAN the host server is connected on, this will require bridging the tap devices. Newer versions of qemu can automatically create and use tap device |
- | I like to write a single script qemu-nethelper and have qemu-ifup and qemu-ifdown linked to it. | + | I like to write a single script qemu-nethelper and have qemu-ifup and qemu-ifdown linked to it. The qemu-system-* emulators all execute / |
+ | |||
+ | As mentioned above newer versions of qemu (I think 1.1+) automatically create the tap device so the qemu-nethelper only needs to do the bridging. Now to make things a lot easier I like to have the host on which I run VMs with br0 configured at boot and then the qemu-nethelper only needs to add the tap device to the bridge, making it extremely simple. If br0 is already configured at boot then you need not restart any iptables so long as the chains use the bridge devices and the kernel has support for ebtables. | ||
#!/bin/bash | #!/bin/bash | ||
NAME=$(basename $0) | NAME=$(basename $0) | ||
- | [ $(/ | ||
tun_up () | tun_up () | ||
- | { $SUDO / | + | { / |
/ | / | ||
- | | + | /sbin/brctl addif br0 $1 |
} | } | ||
| | ||
tun_down () | tun_down () | ||
- | { $SUDO / | + | { / |
/ | / | ||
- | | + | /sbin/brctl delif br0 $1 |
} | } | ||
| | ||
Line 382: | Line 383: | ||
esac | esac | ||
+ | ===== Using Qemu from Unprivileged Users ===== | ||
+ | Using root for doing your everyday tasks is commonly discouraged so let's see how we can work around using qemu from unprivileged users. | ||
+ | Some say that it's sufficient to give sudo execution on / | ||
+ | |||
+ | User_Alias QEMUERS = al, john, jack | ||
+ | | ||
+ | Cmnd_Alias QEMUCMD = / | ||
+ | | ||
+ | QEMUERS ALL=(ALL) NOPASSWD: QEMU | ||
+ | |||
+ | This would be sufficient to run the VMs as any of the unprivileged users in QEMUERS user alias (al, john, jack) but the management script would need to run sudo qemu-system-* .... this is easy to obtain: | ||
+ | |||
+ | [ $(/ | ||
+ | eval $(echo "$CMD &" | ||
+ | |||
+ | Alternatively you could give privileges to execute the management script as root. | ||
===== Examples ===== | ===== Examples ===== | ||
Here are examples of the dialogs that user would see wile creating, starting, stopping and deleting a VM. | Here are examples of the dialogs that user would see wile creating, starting, stopping and deleting a VM. | ||
Line 600: | Line 617: | ||
====== Sources ====== | ====== Sources ====== | ||
+ | I've a blog entry on LQ where I talk a little more extensively on minimizing the code in bash scripts. | ||
+ | [[http:// | ||
<!-- If you are copying information from another source, then specify that source --> | <!-- If you are copying information from another source, then specify that source --> |