QEMU/KVM for absolute beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
oh this is weird it's like a machine inside the machine inside the machine inside the machine inside the [Music] greetings and welcome to another exciting episode of veronica explains today i'm going to talk about something incredibly exciting kernel-based virtual machines okay well i think they're exciting kernel-based virtual machine or kvm is a fantastic hypervisor baked into the linux kernel since linux 2.6.20. what is a hypervisor you ask well according two to twitter [Music] [Applause] [Music] don't listen to them hypervisors let you run complete isolated operating systems or virtual machines inside your existing real-life actual factual computer if you aren't familiar with the concept of the hypervisor and you want me to make a broader video covering that topic hit me up in the comments why are virtual machines helpful there are tons of great reasons to use vms but here's one from my own life as a dev backup and restore i can't begin to tell you how many times i've borked an install of some tool on a linux server but with virtual machine snapshots i can simply take a snapshot of the vm before running the install and then revert if something goes awry worked an install of some tool on a linux server similarly i can clone a working vm into multiple environments simplifying testing and bug fixing kvm lets you turn your linux box into a fantastic hypervisor without downloading tons of complex programs for managing the whole thing because it's baked into the linux kernel instead of a separate program running on top it's fantastically efficient other hypervisors include virtualbox vmware and hyper-v but i've always gravitated toward using kvm because it's open source baked into linux and free to use ready to dive into kvm first things first in this video i'm assuming you're on an x86 machine like a typical laptop running linux in 2021 if you're on a chromebook a raspberry pi a cloud machine or a mainframe these instructions may not work for you in addition virtual machines take up space and ram so you're probably going to want at least 50 free gigabytes of storage on your machine and at least 8 gigabytes of ram in both cases more is much much better i'm also assuming you're already running some kind of linux distribution on your machine in my case i'm running popos 21.04 which is based on the most up-to-date ubuntu at the time i've made the video i've tested these instructions on my main pop machine as well as my fedora 34 laptop but as always your experience may look a bit different the first thing you're going to need to do is to make sure your system has enabled all of the virtualization tools needed in the firmware if you're running a desktop or laptop from the last five years you probably have what you need but you need to make sure it's all ready to go every distro is different but i find this egrep command works pretty well if you want to know what this command does i'll flash an explanatory title on the screen for four seconds pause to learn more right so if the number displayed by the egrep command is more than zero congratulations you're all set for kvm if the number is zero that means you'll need to go into your bios and tweak the settings to allow virtualization my advice is to look up the instructions for whatever desktop laptop or motherboard you're using and figure out how to enable virtualization on your machine once you're done biosing try that egrep command again and make sure you've got a number greater than zero with that you're ready to install what you need now the install process is obviously going to be different from distro to distro my advice is to look up the specific processes for your distro by using duckduckgo to google your distro and the words install kvm a quick side note there's no shame in looking up a how-to i don't have every command memorized all the time and it doesn't make me any less of a linux expert learning to find new answers is so much more important than memorizing old ones and i don't know any other professional sysadmin who doesn't feel the exact same way anywho in fedora 34 you can just install the whole virtualization group with sudo dnf install at virtualization in other distros like ubuntu you'll have to pick the preferred packages personally preferably precisely and possibly perfectly qemew is the emulator itself and the qemu kvm package installs the main bits your operating system will need libvert daemon is very important a demon is a program that runs something in the background so the libvert daemon is the program that runs virtualization in the background bridge utils is vital for networking your vm to the rest of your network which may come up in your install and vert manager is a graphical program we'll use to manage the whole thing there could be lots of other packages and differences that's why the best option is for you to look up specific instructions for your current distro once you finish up the install you're going to want to check these instructions for how to proceed next on ubuntu-based systems i usually have to add the user to the kvm and libvert group and then restart in my recent experience fedora makes this easy since they ask for permissions as you work in the gui as usual consult your distro's instructions for help once the group memberships are sorted you'll want to make sure the live vert daemon starts up and starts on boot for that we'll need to tell our trusty systemd to start the daemon now and again on startup with sudo system control start lib vert d followed by sudo system control enable libertd with that we should be ready to go with creating vms before we continue i just want to address the fact that i'm doing all of this with the very very good graphical program for kvm which is creatively titled virtual machine manager or vert manager for short truthfully i find this program to be great for interacting with my vms however there's a ton that can be done with kvm at the command line using verse and if you want more terminal nerditude let me know in the comments perhaps i could do a whole playlist on kvm tutorials is that what they call it a playlist before we do anything with vert manager though we're going to need an iso to install an iso file is a disk image which is often used to create boot media to install operating systems i'm going to assume you already know how to find the iso of your preferred distribution i'm electing to try out the fedora 35 beta running mate because nostalgia i'm just going to leave the iso in my downloads folder for now in a minute i'll show you how we can use the downloads folder with invert manager anywho now we need to start virtual machine manager i'm using my main machine which as a reminder is currently rocking popos 21.04 in pop i use the handy dandy launcher by hitting the super key but your distro might do this totally differently however you launch an app you want to load vert manager inside vert manager to set up a virtual machine you select this new icon at the top left corner of the window when you do this a five step wizard starts up and this is an extremely helpful way to get started in our case we're going to use the local install media option since we have an iso we downloaded don't forget to let me know if you want to learn more about these other options next we're going to create a storage pool for our iso files in kvm a storage pool is exactly what it sounds like it's an area of storage set aside for your vms and disk images in our case i want to use the downloads folder as a storage pool for the iso files i'm collecting because firefox conveniently drops them there when i download them i can create the storage pool by selecting the browse option and then hitting the plus at the bottom left of the screen the plus is for add a storage pool logic then in the add a new storage pool pop-up i name the storage pool downloads in my case and then i browse to the specific location on my machine where i want to keep iso files in this case the downloads folder then i just hit finish now i can select the downloads pool and can easily see the iso files located in that directory now i choose the fedora iso and we should be almost ready for the next step last bit here is that the vert manager will look up the os you're installing and apply some sane defaults based on your choice if it automatically detects the correct operating system from the iso name that's wonderful otherwise you can select an option manually either way when we have the right choice we press forward to advance to the ram and cpu selector this section only has two options to set memory and cpus the memory section specifies how much ram you're giving the vm in my case i have 32 gigabytes on the machine so i can give a lot i'm going to specify 4 gig or 4096 meg if you have an 8 gig machine you should consider only specifying 2 gig or 2048 meg the cpu selector lets you specify the number of cpu cores you're letting the vm use in my case i have plenty so i'm going to give it two if it were my laptop i might consider giving the vm just one once you've made your decision we can move forward into storage the storage section lets you specify the amount of storage available to your vm if you have plenty of space on your main drive you can probably just accept the default and move forward however i'm going to create a separate pool on a second ssd because it has more space in my case that that's hard to say basically these files are big and i want to keep them in a separate location you might prefer to do something differently and that's okay if you want to do like i do select the custom storage option and then select manage then we hit the plus again like we did earlier for making the downloads pool from there you browse to the location you want to use for your vm storage once you're there you give the pool a good clean name and then click finish then we can click on that new pool and use the plus next to the word volumes to add a new disk when creating the storage volume i like to specify a clear name as it makes managing these much easier once you have a lot of them for now we're just going to stick with the qcow2 format as it's a good default and i'm not looking to make this video any longer you can also specify the total storage available to your vm and in my case i'm going to give it a little bit more because why not i have the room here from here you hit finish and then choose that volume from the list after that we get to move forward to the last step the last step in this wizard is naming your virtual machine and reviewing what you've done pretty straightforward but i like to give my vms a clear name because when you end up with 20 fedoras it'll get really weird i should address network selection real quick if you're using wi-fi for the internet connection on your host machine you'll likely just want to stick with the default here of virtual network this has a disadvantage of not letting your host communicate over the network with your vm now for using vms to test operating systems that's probably fine but if you're trying to learn about servers or application development inside a vm you'll likely want to get creative with these options and that's outside the scope of this video again let me know if you want to see that in a future video once we're happy with the result we hit finish and just like that we have a virtual machine running inside our real machine it's super neat i'll skip over installing the operating system for now but it's just like installing any other operating system the installer sees the virtual machine just like a real machine which is awesome and it looks good but i want to make the screen a little bit bigger in my case i'm just going to go into fedora and select a larger screen size and then resize the window with view followed by resize to vm now that our window is a bit easier to see let's talk about two of my favorite features of kvm snapshots and usb redirect snapshots are life-saving technology which lets you roll back your virtual machine to an earlier state this is extremely useful if you're a sysadmin or developer and need to roll back some change because your software broke kvm makes rollback trivial and vert manager makes it just a few mouse clicks away to start with i'm going to write up a file in vim that i'll later change i save the file and then exit them now we make a snapshot i hit this snapshot icon and then hit the plus in the lower left hand corner from there i name the snapshot and can provide it a description when i click finish it takes a moment and creates a snapshot of this live system i love these snapshots because they are time stamped in invert manager you can even see a screenshot of how it looked when you made the snapshot super cool now we go back into our vm and edit the file in this case i'm simply going to add some additional text to use as a demonstration pretend somehow this text broke your favorite web app to roll back we click on the snapshot icon again and then hit the run icon it'll ask if we're sure and we say yes this resets things to the way it was and if i go back into the vm you can see that the text has been reverted you can imagine how helpful this is when you're developing an app and you break something or when you're testing a new operating system and you break something basically snapshots help you recover when you break something which happens a lot when you're a developer don't let anybody tell you otherwise snapshots aren't the only trick up kvm sleeve we've also got usb redirection usb redirection lets you send a usb device from the host computer into a virtual machine in our example i'm going to use this here flash drive which exists in the real world but i'm going to use it inside our virtual machine first off i plug the usb into my desktop and then inside vert manager i select virtual machine followed by redirect usb device then you select the device in my case it's this flash drive and as soon as i select it the device gets rerouted from the host to the vm the vm then sees it just as though it's plugged in there amazing from here we can add a file to it and when we're finished i simply eject the drive from within the vm and remove the redirection from the vm using the inverse of what we did earlier now the next time i plug it into the host machine i can see the files on it magic i think kvm is a fantastic hypervisor for most folks it's quick the gui has amazing usb redirect and the snapshot features have saved me countless hours on production work and we've barely scratched the surface on what we can do remote vm management migrations complex network connections there's so much to explore leave a comment with what you want to see next the thing i appreciate most about kvm is that it's a fully integrated part of linux and of course it is because linux is awesome and so are you one two three [Music] [Applause] [Music] you
Info
Channel: Veronica Explains
Views: 977
Rating: 5 out of 5
Keywords:
Id: BgZHbCDFODk
Channel Id: undefined
Length: 17min 50sec (1070 seconds)
Published: Sat Oct 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.