new file: docs/stupid_kvm_tricks.md

This commit is contained in:
Trent Palmer 2018-02-10 23:31:16 -08:00
parent b752c45a62
commit 632b56756d
26 changed files with 682 additions and 21 deletions

View File

@ -19,6 +19,7 @@ Obviously, the commit history will reflect the time when these documents are wri
* [Self Signed Certs](self_signed_certs.md)
* [Selfoss on Centos7](selfoss_on_centos7.md)
* [Stupid Package Manager Tricks](stupid_package_manager_tricks.md)
* [Stupid KVM Tricks](stupid_kvm_tricks.md)
<!---
* [Template](Template.md)

146
docs/stupid_kvm_tricks.md Normal file
View File

@ -0,0 +1,146 @@
# Stupid KVM Tricks
## virt-install ubuntu16.04
Create the disk image
`qemu-img create -f qcow2 /var/lib/libvirt/images/xenial.qcow2 20G`
Command to run the install
```bash
virt-install \
--name xenial \
--ram 4096 \
--disk path=/var/lib/libvirt/images/xenial.qcow2,size=20 \
--vcpus 4 \
--os-type linux \
--os-variant ubuntu16.04 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location ./ubuntu-16.04.3-server-amd64.iso \
--extra-args 'console=ttyS0,115200n8 serial'
```
## Change the Network Interface
br0 gets addresses from the network router, but what if you want
your vm to have be on the virbr0 192.168.122.0/24 subnet?
`virsh edit xenial`
And then 'J' all the way down to the bottom, change the interface name from br0 to
virbr0,
`virsh start xenial`
and then look for the machine with nmap
`nmap -sn 192.168.122.0/24`
## Clone the VM
In this case we don't have to pre-allocate the disk image because virt-clone will do that
for us.
```bash
virt-clone --original xenial --name xenial-clone \
--file /var/lib/libvirt/images/xenial-clone.qcow2
```
## Clone the VM to another Machine
First dump the xml that defines the virtual machine.
```bash
virsh dumpxml xenial > xenial.xml
```
Then copy both `xenial.xml` and `xenial.qcow2` to the new host machine. On the new kvm
host you'll want to at least make sure your vm has the correct CPU architecture.
The command to get a list of supported kvm cpu architectures is:
```bash
virsh cpu-models <arch>
# i.e.
virsh cpu-models x86_64
```
After you edit `xenial.xml` and update the correct cpu architecture, mv `xenial.qcow2`
to `/var/lib/libvirt/images/`, clone it. `virt-clone` will handle generating new
mac addresses for the network interfaces.
```xml
<cpu mode='custom' match='exact'>
<model fallback='allow'>Haswell-noTSX</model>
</cpu>
# i.e. change to above to
<cpu mode='custom' match='exact'>
<model fallback='allow'>SandyBridge</model>
</cpu>
```
```bash
virt-clone --original-xml xenial.xml --name xenial-clone \
--file /var/lib/libvirt/images/xenial-clone.qcow2
```
## What is the os-type and os-variant type names?
`osinfo-query os`
## misc
* Start the vm `virsh start xenial`
* List all the vms `virsh list --all`
* Stop the vm `virsh destroy xenial`
* Delete the vm `virsh undefine xenial`
## virsh help
The `virsh help` command returns a long chart of help information. But each section has
a keyword.
Take for instance the command `virsh help monitor`. From this we
see the `domiflist` subcommand (among others). Unfortunately `domifaddr` doesn't seem to
work on the Ubuntu:16.04 host, but there are other ways to find the ip address of
a virtual machine.
So now if you want to see what host interface the vm `xenial` is attached to,
type.
```bash
virsh domiflist xenial
```
which returns:
```bash
Interface Type Source Model MAC
-------------------------------------------------------
vnet1 bridge virbr0 virtio 52:54:00:58:bf:75
```
So now we can find the address of virbr0 on the host machine.
```bash
ifconfig virbr0
```
which returns:
```bash
virbr0 Link encap:Ethernet HWaddr 52:54:00:38:87:38
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1351 errors:0 dropped:0 overruns:0 frame:0
TX packets:3037 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:232346 (232.3 KB) TX bytes:502916 (502.9 KB)
```
and thus we know what subnet to scan with nmap to find the ip address of the vm
```bash
nmap -sn 192.168.122.0/24
```

View File

@ -21,3 +21,4 @@ pages:
- 'Self Signed Certs': self_signed_certs.md
- 'Selfoss on Centos7': selfoss_on_centos7.md
- 'Stupid Package Manager Tricks': stupid_package_manager_tricks.md
- 'Stupid KVM Tricks': stupid_kvm_tricks.md

View File

@ -130,6 +130,11 @@
<a class="" href="/stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="/stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -143,6 +143,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -143,6 +143,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -143,6 +143,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -143,6 +143,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -161,6 +161,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -157,6 +157,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -153,6 +153,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -143,6 +143,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -149,6 +149,11 @@
<a class="" href="stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;
@ -202,6 +207,7 @@
<li><a href="self_signed_certs/">Self Signed Certs</a></li>
<li><a href="selfoss_on_centos7/">Selfoss on Centos7</a></li>
<li><a href="stupid_package_manager_tricks/">Stupid Package Manager Tricks</a></li>
<li><a href="stupid_kvm_tricks/">Stupid KVM Tricks</a></li>
</ul>
<!---
* [Template](Template.md)
@ -255,5 +261,5 @@
<!--
MkDocs version : 0.17.2
Build Date UTC : 2018-02-10 05:10:51
Build Date UTC : 2018-02-11 07:30:59
-->

View File

@ -149,6 +149,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -157,6 +157,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -155,6 +155,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -161,6 +161,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -159,6 +159,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -130,6 +130,11 @@
<a class="" href="stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -2,7 +2,7 @@
"docs": [
{
"location": "/",
"text": "Welcome to Trent Docs\n\n\nGit Repo For These Docs\n\n\nObviously, the commit history will reflect the time when these documents are written.\n\n\n\n\nApt Pinning Artful Aardvark Packages in Xenial Xerus\n\n\nLXD Container Home Server Networking For Dummies\n\n\nLXD Container Foo\n\n\nHow To Reassign A Static Ip Address with dnsmasq\n\n\nServe And Share Apps From Your Phone With Fdroid\n\n\nNspawn Containers\n\n\nGentoo LXD Container\n\n\nMastodon on Arch\n\n\nDebian Nspawn Container On Arch For Testing Apache Configurations\n\n\nDynamic Cacheing Nginx Reverse Proxy For Pacman\n\n\nFreeBSD Jails on FreeNAS\n \n\n\nQuick Dirty Redis Nspawn Container on Arch Linux\n\n\nQuick Dirty Postgresql Nspawn Container on Arch Linux\n\n\nMisc Tips, Trouble Shooting\n\n\nSelf Signed Certs\n\n\nSelfoss on Centos7\n\n\nStupid Package Manager Tricks",
"text": "Welcome to Trent Docs\n\n\nGit Repo For These Docs\n\n\nObviously, the commit history will reflect the time when these documents are written.\n\n\n\n\nApt Pinning Artful Aardvark Packages in Xenial Xerus\n\n\nLXD Container Home Server Networking For Dummies\n\n\nLXD Container Foo\n\n\nHow To Reassign A Static Ip Address with dnsmasq\n\n\nServe And Share Apps From Your Phone With Fdroid\n\n\nNspawn Containers\n\n\nGentoo LXD Container\n\n\nMastodon on Arch\n\n\nDebian Nspawn Container On Arch For Testing Apache Configurations\n\n\nDynamic Cacheing Nginx Reverse Proxy For Pacman\n\n\nFreeBSD Jails on FreeNAS\n \n\n\nQuick Dirty Redis Nspawn Container on Arch Linux\n\n\nQuick Dirty Postgresql Nspawn Container on Arch Linux\n\n\nMisc Tips, Trouble Shooting\n\n\nSelf Signed Certs\n\n\nSelfoss on Centos7\n\n\nStupid Package Manager Tricks\n\n\nStupid KVM Tricks",
"title": "Home"
},
{
@ -12,7 +12,7 @@
},
{
"location": "/#git-repo-for-these-docs",
"text": "Obviously, the commit history will reflect the time when these documents are written. Apt Pinning Artful Aardvark Packages in Xenial Xerus LXD Container Home Server Networking For Dummies LXD Container Foo How To Reassign A Static Ip Address with dnsmasq Serve And Share Apps From Your Phone With Fdroid Nspawn Containers Gentoo LXD Container Mastodon on Arch Debian Nspawn Container On Arch For Testing Apache Configurations Dynamic Cacheing Nginx Reverse Proxy For Pacman FreeBSD Jails on FreeNAS Quick Dirty Redis Nspawn Container on Arch Linux Quick Dirty Postgresql Nspawn Container on Arch Linux Misc Tips, Trouble Shooting Self Signed Certs Selfoss on Centos7 Stupid Package Manager Tricks",
"text": "Obviously, the commit history will reflect the time when these documents are written. Apt Pinning Artful Aardvark Packages in Xenial Xerus LXD Container Home Server Networking For Dummies LXD Container Foo How To Reassign A Static Ip Address with dnsmasq Serve And Share Apps From Your Phone With Fdroid Nspawn Containers Gentoo LXD Container Mastodon on Arch Debian Nspawn Container On Arch For Testing Apache Configurations Dynamic Cacheing Nginx Reverse Proxy For Pacman FreeBSD Jails on FreeNAS Quick Dirty Redis Nspawn Container on Arch Linux Quick Dirty Postgresql Nspawn Container on Arch Linux Misc Tips, Trouble Shooting Self Signed Certs Selfoss on Centos7 Stupid Package Manager Tricks Stupid KVM Tricks",
"title": "Git Repo For These Docs"
},
{
@ -579,6 +579,51 @@
"location": "/stupid_package_manager_tricks/#apt-apt-get-aptitude-dpkg",
"text": "Wait what was that list of suggested packages? apt-cache depends <package> \nor apt-cache depends <package> | grep -i Suggests What versions of a package are available, (based on currently configured repositories)? apt-cache madison <package>",
"title": "apt, apt-get ,aptitude, dpkg"
},
{
"location": "/stupid_kvm_tricks/",
"text": "Stupid KVM Tricks\n\n\nvirt-install ubuntu16.04\n\n\nCreate the disk image\n\n\nqemu-img create -f qcow2 /var/lib/libvirt/images/xenial.qcow2 20G\n\n\nCommand to run the install\n\n\nvirt-install \\\n --name xenial \\\n --ram 4096 \\\n --disk path=/var/lib/libvirt/images/xenial.qcow2,size=20 \\\n --vcpus 4 \\\n --os-type linux \\\n --os-variant ubuntu16.04 \\\n --network bridge=br0 \\\n --graphics none \\\n --console pty,target_type=serial \\\n --location ./ubuntu-16.04.3-server-amd64.iso \\\n --extra-args 'console=ttyS0,115200n8 serial'\n\n\n\n\nChange the Network Interface\n\n\nbr0 gets addresses from the network router, but what if you want\nyour vm to have be on the virbr0 192.168.122.0/24 subnet?\n\n\nvirsh edit xenial\n\n\nAnd then 'J' all the way down to the bottom, change the interface name from br0 to\nvirbr0, \n\n\nvirsh start xenial\n\n\nand then look for the machine with nmap\n\n\nnmap -sn 192.168.122.0/24\n\n\nClone the VM\n\n\nIn this case we don't have to pre-allocate the disk image because virt-clone will do that\nfor us.\n\n\nvirt-clone --original xenial --name xenial-clone \\\n --file /var/lib/libvirt/images/xenial-clone.qcow2\n\n\n\n\nClone the VM to another Machine\n\n\nFirst dump the xml that defines the virtual machine.\n\n\nvirsh dumpxml xenial > xenial.xml\n\n\n\n\nThen copy both \nxenial.xml\n and \nxenial.qcow2\n to the new host machine. On the new kvm\nhost you'll want to at least make sure your vm has the correct CPU architecture.\nThe command to get a list of supported kvm cpu architectures is:\n\n\nvirsh cpu-models <arch>\n# i.e.\nvirsh cpu-models x86_64\n\n\n\n\nAfter you edit \nxenial.xml\n and update the correct cpu architecture, mv \nxenial.qcow2\n\nto \n/var/lib/libvirt/images/\n, clone it. \nvirt-clone\n will handle generating new\nmac addresses for the network interfaces.\n\n\n <cpu mode='custom' match='exact'>\n <model fallback='allow'>Haswell-noTSX</model>\n </cpu>\n# i.e. change to above to\n <cpu mode='custom' match='exact'>\n <model fallback='allow'>SandyBridge</model>\n </cpu>\n\n\n\n\n\nvirt-clone --original-xml xenial.xml --name xenial-clone \\\n --file /var/lib/libvirt/images/xenial-clone.qcow2\n\n\n\n\nWhat is the os-type and os-variant type names?\n\n\nosinfo-query os\n\n\nmisc\n\n\n\n\nStart the vm \nvirsh start xenial\n \n\n\nList all the vms \nvirsh list --all\n \n\n\nStop the vm \nvirsh destroy xenial\n \n\n\nDelete the vm \nvirsh undefine xenial\n \n\n\n\n\nvirsh help\n\n\nThe \nvirsh help\n command returns a long chart of help information. But each section has\na keyword.\n\n\nTake for instance the command \nvirsh help monitor\n. From this we\nsee the \ndomiflist\n subcommand (among others). Unfortunately \ndomifaddr\n doesn't seem to\nwork on the Ubuntu:16.04 host, but there are other ways to find the ip address of\na virtual machine.\n\n\nSo now if you want to see what host interface the vm \nxenial\n is attached to,\ntype. \n\n\nvirsh domiflist xenial\n\n\n\n\nwhich returns:\n\n\nInterface Type Source Model MAC\n-------------------------------------------------------\nvnet1 bridge virbr0 virtio 52:54:00:58:bf:75\n\n\n\n\nSo now we can find the address of virbr0 on the host machine.\n\n\nifconfig virbr0\n\n\n\n\nwhich returns:\n\n\nvirbr0 Link encap:Ethernet HWaddr 52:54:00:38:87:38 \n inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0\n UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1\n RX packets:1351 errors:0 dropped:0 overruns:0 frame:0\n TX packets:3037 errors:0 dropped:0 overruns:0 carrier:0\n collisions:0 txqueuelen:1000 \n RX bytes:232346 (232.3 KB) TX bytes:502916 (502.9 KB)\n\n\n\n\nand thus we know what subnet to scan with nmap to find the ip address of the vm\n\n\nnmap -sn 192.168.122.0/24",
"title": "Stupid KVM Tricks"
},
{
"location": "/stupid_kvm_tricks/#stupid-kvm-tricks",
"text": "",
"title": "Stupid KVM Tricks"
},
{
"location": "/stupid_kvm_tricks/#virt-install-ubuntu1604",
"text": "Create the disk image qemu-img create -f qcow2 /var/lib/libvirt/images/xenial.qcow2 20G Command to run the install virt-install \\\n --name xenial \\\n --ram 4096 \\\n --disk path=/var/lib/libvirt/images/xenial.qcow2,size=20 \\\n --vcpus 4 \\\n --os-type linux \\\n --os-variant ubuntu16.04 \\\n --network bridge=br0 \\\n --graphics none \\\n --console pty,target_type=serial \\\n --location ./ubuntu-16.04.3-server-amd64.iso \\\n --extra-args 'console=ttyS0,115200n8 serial'",
"title": "virt-install ubuntu16.04"
},
{
"location": "/stupid_kvm_tricks/#change-the-network-interface",
"text": "br0 gets addresses from the network router, but what if you want\nyour vm to have be on the virbr0 192.168.122.0/24 subnet? virsh edit xenial And then 'J' all the way down to the bottom, change the interface name from br0 to\nvirbr0, virsh start xenial and then look for the machine with nmap nmap -sn 192.168.122.0/24",
"title": "Change the Network Interface"
},
{
"location": "/stupid_kvm_tricks/#clone-the-vm",
"text": "In this case we don't have to pre-allocate the disk image because virt-clone will do that\nfor us. virt-clone --original xenial --name xenial-clone \\\n --file /var/lib/libvirt/images/xenial-clone.qcow2",
"title": "Clone the VM"
},
{
"location": "/stupid_kvm_tricks/#clone-the-vm-to-another-machine",
"text": "First dump the xml that defines the virtual machine. virsh dumpxml xenial > xenial.xml Then copy both xenial.xml and xenial.qcow2 to the new host machine. On the new kvm\nhost you'll want to at least make sure your vm has the correct CPU architecture.\nThe command to get a list of supported kvm cpu architectures is: virsh cpu-models <arch>\n# i.e.\nvirsh cpu-models x86_64 After you edit xenial.xml and update the correct cpu architecture, mv xenial.qcow2 \nto /var/lib/libvirt/images/ , clone it. virt-clone will handle generating new\nmac addresses for the network interfaces. <cpu mode='custom' match='exact'>\n <model fallback='allow'>Haswell-noTSX</model>\n </cpu>\n# i.e. change to above to\n <cpu mode='custom' match='exact'>\n <model fallback='allow'>SandyBridge</model>\n </cpu> virt-clone --original-xml xenial.xml --name xenial-clone \\\n --file /var/lib/libvirt/images/xenial-clone.qcow2",
"title": "Clone the VM to another Machine"
},
{
"location": "/stupid_kvm_tricks/#what-is-the-os-type-and-os-variant-type-names",
"text": "osinfo-query os",
"title": "What is the os-type and os-variant type names?"
},
{
"location": "/stupid_kvm_tricks/#misc",
"text": "Start the vm virsh start xenial List all the vms virsh list --all Stop the vm virsh destroy xenial Delete the vm virsh undefine xenial",
"title": "misc"
},
{
"location": "/stupid_kvm_tricks/#virsh-help",
"text": "The virsh help command returns a long chart of help information. But each section has\na keyword. Take for instance the command virsh help monitor . From this we\nsee the domiflist subcommand (among others). Unfortunately domifaddr doesn't seem to\nwork on the Ubuntu:16.04 host, but there are other ways to find the ip address of\na virtual machine. So now if you want to see what host interface the vm xenial is attached to,\ntype. virsh domiflist xenial which returns: Interface Type Source Model MAC\n-------------------------------------------------------\nvnet1 bridge virbr0 virtio 52:54:00:58:bf:75 So now we can find the address of virbr0 on the host machine. ifconfig virbr0 which returns: virbr0 Link encap:Ethernet HWaddr 52:54:00:38:87:38 \n inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0\n UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1\n RX packets:1351 errors:0 dropped:0 overruns:0 frame:0\n TX packets:3037 errors:0 dropped:0 overruns:0 carrier:0\n collisions:0 txqueuelen:1000 \n RX bytes:232346 (232.3 KB) TX bytes:502916 (502.9 KB) and thus we know what subnet to scan with nmap to find the ip address of the vm nmap -sn 192.168.122.0/24",
"title": "virsh help"
}
]
}

View File

@ -143,6 +143,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -143,6 +143,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -171,6 +171,11 @@
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;

View File

@ -4,7 +4,7 @@
<url>
<loc>/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -12,7 +12,7 @@
<url>
<loc>/apt_pinning_artful_aardvark_packages_in_xenial_xerus/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -20,7 +20,7 @@
<url>
<loc>/lxd_container_home_server_networking_for_dummies/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -28,7 +28,7 @@
<url>
<loc>/lxd_container_foo/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -36,7 +36,7 @@
<url>
<loc>/how_to_reassign_a_static_ip_address_with_dnsmasq/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -44,7 +44,7 @@
<url>
<loc>/serve_and_share_apps_from_your_phone_with_fdroid/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -52,7 +52,7 @@
<url>
<loc>/nspawn/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -60,7 +60,7 @@
<url>
<loc>/gentoo_lxd_container/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -68,7 +68,7 @@
<url>
<loc>/mastodon_on_arch/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -76,7 +76,7 @@
<url>
<loc>/debian_nspawn_container_on_arch_for_testing_apache_configurations/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -84,7 +84,7 @@
<url>
<loc>/dynamic_cacheing_nginx_reverse_proxy_for_pacman/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -92,7 +92,7 @@
<url>
<loc>/freebsd_jails_on_freenas/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -100,7 +100,7 @@
<url>
<loc>/arch_redis_nspawn/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -108,7 +108,7 @@
<url>
<loc>/arch_postgresql_nspawn/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -116,7 +116,7 @@
<url>
<loc>/misc_tips_troubleshooting/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -124,7 +124,7 @@
<url>
<loc>/self_signed_certs/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -132,7 +132,7 @@
<url>
<loc>/selfoss_on_centos7/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
@ -140,7 +140,15 @@
<url>
<loc>/stupid_package_manager_tricks/</loc>
<lastmod>2018-02-09</lastmod>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>/stupid_kvm_tricks/</loc>
<lastmod>2018-02-10</lastmod>
<changefreq>daily</changefreq>
</url>

View File

@ -0,0 +1,355 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="../img/favicon.ico">
<title>Stupid KVM Tricks - Trent Docs</title>
<link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="../css/theme.css" type="text/css" />
<link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
<link rel="stylesheet" href="../css/highlight.css">
<script>
// Current page data
var mkdocs_page_name = "Stupid KVM Tricks";
var mkdocs_page_input_path = "stupid_kvm_tricks.md";
var mkdocs_page_url = "/stupid_kvm_tricks/";
</script>
<script src="../js/jquery-2.1.1.min.js"></script>
<script src="../js/modernizr-2.8.3.min.js"></script>
<script type="text/javascript" src="../js/highlight.pack.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
<div class="wy-side-nav-search">
<a href=".." class="icon icon-home"> Trent Docs</a>
<div role="search">
<form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1">
<a class="" href="..">Home</a>
</li>
<li class="toctree-l1">
<a class="" href="../apt_pinning_artful_aardvark_packages_in_xenial_xerus/">Apt Pinning Artful Aardvark Packages in Xenial Xerus</a>
</li>
<li class="toctree-l1">
<a class="" href="../lxd_container_home_server_networking_for_dummies/">LXD Container Home Server Networking For Dummies</a>
</li>
<li class="toctree-l1">
<a class="" href="../lxd_container_foo/">LXD Container Foo</a>
</li>
<li class="toctree-l1">
<a class="" href="../how_to_reassign_a_static_ip_address_with_dnsmasq/">How To Reassign A Static Ip Address with dnsmasq</a>
</li>
<li class="toctree-l1">
<a class="" href="../serve_and_share_apps_from_your_phone_with_fdroid/">Serve And Share Apps From Your Phone With Fdroid</a>
</li>
<li class="toctree-l1">
<a class="" href="../nspawn/">Nspawn</a>
</li>
<li class="toctree-l1">
<a class="" href="../gentoo_lxd_container/">Gentoo LXD Container</a>
</li>
<li class="toctree-l1">
<a class="" href="../mastodon_on_arch/">Mastodon on Arch</a>
</li>
<li class="toctree-l1">
<a class="" href="../debian_nspawn_container_on_arch_for_testing_apache_configurations/">Debian Nspawn Container On Arch For Testing Apache Configurations</a>
</li>
<li class="toctree-l1">
<a class="" href="../dynamic_cacheing_nginx_reverse_proxy_for_pacman/">Dynamic Cacheing Nginx Reverse Proxy For Pacman</a>
</li>
<li class="toctree-l1">
<a class="" href="../freebsd_jails_on_freenas/">FreeBSD Jails on FreeNAS</a>
</li>
<li class="toctree-l1">
<a class="" href="../arch_redis_nspawn/">Quick Dirty Redis Nspawn Container on Arch Linux</a>
</li>
<li class="toctree-l1">
<a class="" href="../arch_postgresql_nspawn/">Quick Dirty Postgresql Nspawn Container on Arch Linux</a>
</li>
<li class="toctree-l1">
<a class="" href="../misc_tips_troubleshooting/">Misc Tips, Trouble Shooting</a>
</li>
<li class="toctree-l1">
<a class="" href="../self_signed_certs/">Self Signed Certs</a>
</li>
<li class="toctree-l1">
<a class="" href="../selfoss_on_centos7/">Selfoss on Centos7</a>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_package_manager_tricks/">Stupid Package Manager Tricks</a>
</li>
<li class="toctree-l1 current">
<a class="current" href="./">Stupid KVM Tricks</a>
<ul class="subnav">
<li class="toctree-l2"><a href="#stupid-kvm-tricks">Stupid KVM Tricks</a></li>
<ul>
<li><a class="toctree-l3" href="#virt-install-ubuntu1604">virt-install ubuntu16.04</a></li>
<li><a class="toctree-l3" href="#change-the-network-interface">Change the Network Interface</a></li>
<li><a class="toctree-l3" href="#clone-the-vm">Clone the VM</a></li>
<li><a class="toctree-l3" href="#clone-the-vm-to-another-machine">Clone the VM to another Machine</a></li>
<li><a class="toctree-l3" href="#what-is-the-os-type-and-os-variant-type-names">What is the os-type and os-variant type names?</a></li>
<li><a class="toctree-l3" href="#misc">misc</a></li>
<li><a class="toctree-l3" href="#virsh-help">virsh help</a></li>
</ul>
</ul>
</li>
</ul>
</div>
&nbsp;
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="..">Trent Docs</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="..">Docs</a> &raquo;</li>
<li>Stupid KVM Tricks</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main">
<div class="section">
<h1 id="stupid-kvm-tricks">Stupid KVM Tricks</h1>
<h2 id="virt-install-ubuntu1604">virt-install ubuntu16.04</h2>
<p>Create the disk image</p>
<p><code>qemu-img create -f qcow2 /var/lib/libvirt/images/xenial.qcow2 20G</code></p>
<p>Command to run the install</p>
<pre><code class="bash">virt-install \
--name xenial \
--ram 4096 \
--disk path=/var/lib/libvirt/images/xenial.qcow2,size=20 \
--vcpus 4 \
--os-type linux \
--os-variant ubuntu16.04 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location ./ubuntu-16.04.3-server-amd64.iso \
--extra-args 'console=ttyS0,115200n8 serial'
</code></pre>
<h2 id="change-the-network-interface">Change the Network Interface</h2>
<p>br0 gets addresses from the network router, but what if you want
your vm to have be on the virbr0 192.168.122.0/24 subnet?</p>
<p><code>virsh edit xenial</code></p>
<p>And then 'J' all the way down to the bottom, change the interface name from br0 to
virbr0, </p>
<p><code>virsh start xenial</code></p>
<p>and then look for the machine with nmap</p>
<p><code>nmap -sn 192.168.122.0/24</code></p>
<h2 id="clone-the-vm">Clone the VM</h2>
<p>In this case we don't have to pre-allocate the disk image because virt-clone will do that
for us.</p>
<pre><code class="bash">virt-clone --original xenial --name xenial-clone \
--file /var/lib/libvirt/images/xenial-clone.qcow2
</code></pre>
<h2 id="clone-the-vm-to-another-machine">Clone the VM to another Machine</h2>
<p>First dump the xml that defines the virtual machine.</p>
<pre><code class="bash">virsh dumpxml xenial &gt; xenial.xml
</code></pre>
<p>Then copy both <code>xenial.xml</code> and <code>xenial.qcow2</code> to the new host machine. On the new kvm
host you'll want to at least make sure your vm has the correct CPU architecture.
The command to get a list of supported kvm cpu architectures is:</p>
<pre><code class="bash">virsh cpu-models &lt;arch&gt;
# i.e.
virsh cpu-models x86_64
</code></pre>
<p>After you edit <code>xenial.xml</code> and update the correct cpu architecture, mv <code>xenial.qcow2</code>
to <code>/var/lib/libvirt/images/</code>, clone it. <code>virt-clone</code> will handle generating new
mac addresses for the network interfaces.</p>
<pre><code class="xml"> &lt;cpu mode='custom' match='exact'&gt;
&lt;model fallback='allow'&gt;Haswell-noTSX&lt;/model&gt;
&lt;/cpu&gt;
# i.e. change to above to
&lt;cpu mode='custom' match='exact'&gt;
&lt;model fallback='allow'&gt;SandyBridge&lt;/model&gt;
&lt;/cpu&gt;
</code></pre>
<pre><code class="bash">virt-clone --original-xml xenial.xml --name xenial-clone \
--file /var/lib/libvirt/images/xenial-clone.qcow2
</code></pre>
<h2 id="what-is-the-os-type-and-os-variant-type-names">What is the os-type and os-variant type names?</h2>
<p><code>osinfo-query os</code></p>
<h2 id="misc">misc</h2>
<ul>
<li>Start the vm <code>virsh start xenial</code> </li>
<li>List all the vms <code>virsh list --all</code> </li>
<li>Stop the vm <code>virsh destroy xenial</code> </li>
<li>Delete the vm <code>virsh undefine xenial</code> </li>
</ul>
<h2 id="virsh-help">virsh help</h2>
<p>The <code>virsh help</code> command returns a long chart of help information. But each section has
a keyword.</p>
<p>Take for instance the command <code>virsh help monitor</code>. From this we
see the <code>domiflist</code> subcommand (among others). Unfortunately <code>domifaddr</code> doesn't seem to
work on the Ubuntu:16.04 host, but there are other ways to find the ip address of
a virtual machine.</p>
<p>So now if you want to see what host interface the vm <code>xenial</code> is attached to,
type. </p>
<pre><code class="bash">virsh domiflist xenial
</code></pre>
<p>which returns:</p>
<pre><code class="bash">Interface Type Source Model MAC
-------------------------------------------------------
vnet1 bridge virbr0 virtio 52:54:00:58:bf:75
</code></pre>
<p>So now we can find the address of virbr0 on the host machine.</p>
<pre><code class="bash">ifconfig virbr0
</code></pre>
<p>which returns:</p>
<pre><code class="bash">virbr0 Link encap:Ethernet HWaddr 52:54:00:38:87:38
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1351 errors:0 dropped:0 overruns:0 frame:0
TX packets:3037 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:232346 (232.3 KB) TX bytes:502916 (502.9 KB)
</code></pre>
<p>and thus we know what subnet to scan with nmap to find the ip address of the vm</p>
<pre><code class="bash">nmap -sn 192.168.122.0/24
</code></pre>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../stupid_package_manager_tricks/" class="btn btn-neutral" title="Stupid Package Manager Tricks"><span class="icon icon-circle-arrow-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<!-- Copyright etc -->
</div>
Built with <a href="http://www.mkdocs.org">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<div class="rst-versions" role="note" style="cursor: pointer">
<span class="rst-current-version" data-toggle="rst-current-version">
<span><a href="../stupid_package_manager_tricks/" style="color: #fcfcfc;">&laquo; Previous</a></span>
</span>
</div>
<script>var base_url = '..';</script>
<script src="../js/theme.js"></script>
<script src="../search/require.js"></script>
<script src="../search/search.js"></script>
</body>
</html>

View File

@ -149,6 +149,11 @@
</ul>
</li>
<li class="toctree-l1">
<a class="" href="../stupid_kvm_tricks/">Stupid KVM Tricks</a>
</li>
</ul>
</div>
&nbsp;
@ -196,6 +201,8 @@ or
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../stupid_kvm_tricks/" class="btn btn-neutral float-right" title="Stupid KVM Tricks">Next <span class="icon icon-circle-arrow-right"></span></a>
<a href="../selfoss_on_centos7/" class="btn btn-neutral" title="Selfoss on Centos7"><span class="icon icon-circle-arrow-left"></span> Previous</a>
@ -226,6 +233,8 @@ or
<span><a href="../selfoss_on_centos7/" style="color: #fcfcfc;">&laquo; Previous</a></span>
<span style="margin-left: 15px"><a href="../stupid_kvm_tricks/" style="color: #fcfcfc">Next &raquo;</a></span>
</span>
</div>
<script>var base_url = '..';</script>