VirtualBox: How to Use Snapshots

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there how's it going everybody so in the near future I'm going to be putting together some system administration videos and in those videos I'll be using some virtual machines within VirtualBox and in this video we'll be looking at how we can create and restore snapshots within VirtualBox so snapshots in VirtualBox allow us to save the state of our machines so that we can always restore the machine to the exact state in the future so it's extremely powerful because it allows us to quickly roll back changes without needing to do a complete reinstall and configuration from scratch so I've got my VirtualBox pulled up here and I currently have three virtual machines so one is a boom to desktop and the other is Kali Linux and the last one here is another oven to desktop machine and that is a completely fresh install that we'll use to create some snapshots and I do have separate videos on installing the operating systems within VirtualBox if you'd like to see how that was done now when we have one of these top virtual machines here selected we can see that we have this snapshots tab over here to the right so if we click on this you can see that I have a few snapshots here already so I took an initial snapshot right after the initial installation and another snapshot after I installed guest additions and the last snapshot I took here was after I changed some network settings now snapshots are going to allow me to go back and forth between these safe states so if I was to screw something up while changing those Network settings then I could just revert back to the snapshot of the state of the Machine right after I installed guest additions and it would be like those Network setting changes never happened so I've got a fresh install of a boon to desktop here that doesn't have any snapshots of the Machine yet so all I've done on this machine so far is install the operating system and then powered down the machine so I always like to create a snapshot of my virtual machines at this initial state because if I screw something up and want to go back to the initial and install state then I don't want to have to reinstall the entire operating system from scratch so it's a lot easier just restore the snapshot of that initial installation state so to take the snapshot it's really as simple as selecting the virtual machine opening up that snapshots tab and then clicking this camera on Khanh up here that says take a snapshot so when we click that it will ask us to give our snapshot a name and some details as to what the snapshot contains so it's nice to be as detailed as possible but I'm just going to fill this in here by saying initial install and I'll do that both for the snapshot name and the details and then I'll click OK now once we've taken that snapshot then we can revert this machine back to that initial State at any point by clicking on the snapshot and then up here we can choose this is restore the snapshot this is delete and this opens up details and you can also right-click on these as well and you can see that we have restore delete and show details so you can see here that our snapshot has this little red square here at the bottom right of this icon and that just means that the snapshot was taking while the machine was offline so if you take a snapshot of a running machine then that icon will be different and we'll take a look at that here in just a minute but for now let's go ahead and make a few changes to the fresh install of this virtual machine and take a few more snapshots so I'm going to go ahead and fire this machine up so now that we have this virtual machine running I'm going to go ahead and maximize this and you can see that we don't have guest additions installed because if we had guest additions installed then we'd be able to view this in full screen so let's go ahead and install these really quick so I'm going to go ahead and put my password here now I showed these steps in a separate video where we walk through this installation but basically we're just going to click on devices up here at the top and install guest additions CD and now we just need to walk through these steps I'm going to click run and then it's probably going to ask us for a password here and now we'll just let this install so once that's finished installing I'll go ahead and hit enter there and now I'll shut this computer down or this machine down for those changes to take effect so I'll shut this down now while I'm powered down here we can see that it says that our current state has changed now I'm going to go ahead and create a new snapshot at this point since we've installed guest additions so I'll create a new snapshot for the name and the description I'll just say installed guest additions and and copy this and paste this in here so now we have two snapshots so notice that it makes a little tree here so basically this is saying that all the changes we made up to this point can be traced back down this tree but we can also have separate branches of these trees so for example I'm going to power up this machine again and this time I'll install an Apache web server so when the machine powers up here we can see that it is in full-screen so we do have those guest additions installed so now I'm going to pull up my terminal once this desktop runs so we'll go up here and search for the terminal and we can tell if a patchy is installed by typing in service Apache to status and if we hit enter then we can see that that wasn't found so I'm going to install it by saying sudo apt-get install apache2 and type in the sudo password so now after that installation finished we can rerun that status command again and if we run that then we can see that now Apache is installed so now I'm going to power down the machine here real quick now that Apache is installed so with that machine powered down I'm going to create another snapshot here and now for the name and for the description I'm going to put installed Apache for both of these okay so now here's where we can do something a little interesting so I'm going to revert back to before I installed Apache so I'm going to restore this snapshot right after we installed it guest additions so to do that I can just click on the snapshot and we can either restore by clicking this button here or we can right click and click restore so then it asks you if you're sure so I'll say yes that I want to restore to that point and now we can see that our current state is down here beside the Apache snapshot but it's not derived from that snapshot so if we spin up our machine now so I'll just log back in here really fast and then again we'll go ahead and open up that terminal so now just like before let's check and see if Apache is installed so we'll say service Apache - and then we'll do a status on that so we can see that that isn't found because we restored the snapshot before we installed that so now let's install nginx so we can install nginx by saying sudo apt-get install and engine X and put on our password and now we can check to make sure that was installed by typing service and this time we'll search for Engine X and then status and we can see that that was installed successfully so now I'm going to power down the machine here one more time so now with that machine powered down I'm going to create a snapshot of this engine X installation also but there's one quick thing that I want to show you here first so you see how it says that our current state is changed well if we try to restore a previous snapshot while our current state has changed then I'll ask us if we want to first take a snapshot of that change State so to show you this I'll go ahead and try to restore this earlier snapshot while we're in this change State so I will click on restore snapshot for this install guest additions and you can see that since we are in that change state it pops up a warning here that says that you can create a snapshot of the current state first and if we don't then our changes will be lost forever and it defaults to having this selected so that we will create that snapshot now a lot of the time when I'm reverting back to a previous snapshot it's usually because I want to get rid of the current state of my machine because I've messed something up so usually I uncheck this so that I don't create a new snapshot but in this case I want to take that snapshot of the engine X installation so I'll go ahead and leave that checked and I'll click restore and so now it pops up the details of that snapshot that we want to create so for this one I'll just say installed engine X and for the description there's a typo there but that's not a big deal and for the description I will say the same thing so now we have two snapshots branching off of our guest additions snapshot now one has Apache installed and the other one has nginx installed so we can see how useful this is so instead of having multiple virtual machines all with different setups we instead have one virtual machine that we can use to test multiple different setups and switching back and forth between these is just as easy as clicking on a snapshot and clicking restore so now that we've restored that snapshot if we fire up our machine then we'll have a machine that has nginx installed and not Apache ok so what are these snapshots actually saving about our machine state so I have the VirtualBox documentation about snapshots pulled up here so I'm going to go ahead and maximize this and I'm going to scroll down here to snapshot contents now we can see here that there are basically three different bullet points as to what the snapshot contents contain so in short the snapshots saved for the first bullet point here they save a complete copy of the VM settings including the hardware configuration and the second bullet point here and you can read these on your own I'm just kind of paraphrasing the second bullet point basically says that it also saves the complete state of all virtual disk and this basically means that all the changes that had been made to the disk will be reverted back to the exact state of that snapshot so any files that were created since the snapshot will disappear files that were deleted will be restored and files that were modified will be reverted to what they were and this last point point here says that if you take a snapshot while the machine is running the memory state of the machine is also saved so when you restored the snapshot the execution will resume at exactly the point when the snapshot was taken so the memory state file can be as large as the memory size of the virtual machine itself and it says here that that can occupy a lot of this space so if you imagine you have a few gigs loaded into memory and save that machine state then it's going to dump all of that into a file and that can be pretty large so that last bullet point is why I generally try to avoid taking snapshots of machines while they're running so my main use case for snapshots is to be able to go back and forth between changes and settings or back and forth between software installs and things like that but the snapshot of a running machine could be useful if you really need it so let's go ahead and see what that would look like so I'll just log in to our machine here so let's say that you're working within your virtual machine and you have a lot of work pulled up and for some reason you have to restart your host machine or something like that so within this document here I'm just going to type in important document or we could even be in terminal and be half way through a bunch of commands and we have to shut down our virtual machine so let's say that I want to save the exact state of this machine so to do this we can come up here to machine and if we click on a machine then we can go to take snapshot and now for the name and the description here I'll just say working and working and then we'll click ok so now that saved the state of our running machine so now I'm going to power down this virtual machine here and just shut this down without saving anything now if I minimize this and open back up Virtual Box here so we can see that under our nginx snapshot we have a working snapshot and the icon is a green play button which means that this machine was running when we took the snapshot so if we restore this snapshot and I'm just going to uncheck to create a new snapshot from the current state so now we've restored that working snapshot now I'm going to fire this machine back up and you can see it comes back up with everything that we had open and our unsaved changes are still in our document so that's pretty cool but remember that the snapshots of these running machines do take up a lot more space so I hardly ever use them so I usually have time to power down before I take any snapshots that I need but the feature is there if you need it ok so now we can just power this down for the last time ok so I think that is going to do it for this video so I hope that you learned a lot about how you can use snapshots within your virtual machines so when I first started using VirtualBox I didn't really know how to properly use these snapshots so I would always be scrapping entire machines when I made mistakes and reinstalling the entire operating system from scratch but learning how to use these snapshots has really saved me a lot of time and hassle and hopefully it'll do the same for you but if you do have any questions about what we covered in this video then feel free to ask in the comment section below and I'll do my best to answer those and if you enjoy these tutorials and would like to support them then there are several ways you can do that the easiest way is to simply like the video and give it a thumbs up and also it's a huge help to share these videos with anyone who you think would find them useful and if you have the means you can contribute through patreon and there's a link to that page in the description section below be sure to subscribe for future videos and thank you all for watching you
Info
Channel: Corey Schafer
Views: 44,298
Rating: undefined out of 5
Keywords: virtualbox, virtualbox snapshot, snapshot, virtualbox snapshots, how to use virtualbox snapshots, virtual box, virtualbox (software), virtual machine, vm, snapshots, programming tutorial, software engineering, tutorial
Id: Qte4X-rdr2Q
Channel Id: undefined
Length: 14min 40sec (880 seconds)
Published: Wed Jul 12 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.