mirror of
				https://github.com/TrentSPalmer/trentdocs_website.git
				synced 2025-11-03 22:28:25 -08:00 
			
		
		
		
	new file: docs/stupid_kvm_tricks.md
This commit is contained in:
		@@ -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"
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user