If you want to try out Linux you care about, I think you will use a virtual machine such as VirtualBox. If it is an experimental or temporary environment, that is enough, but if you use a virtual machine as a software execution environment or development environment, the work required to build the environment may be troublesome.
If you want to return to the initial state when the environment gets dirty to some extent, or if you want to prepare another environment, you can use Vagrant to automatically proceed with the environment construction procedure, so you can save time and effort. I can
install
Download and install the Vagrant and Virtual Box packages from the URL below
Find the OS image (BOX) you want from the Vagrant Cloud site
https://app.vagrantup.com/boxes/search
There are boxes made by various people, and there are good and bad things, but it will be safe to choose the following ones
init
Download the published image to your PC and initialize the virtual machine. Execute the vagrant init
command with the name of the Box found in Vatrant Cloud.
Open a terminal (PowerShell for Windows) and run the command
Image download and initialization
#Create a working directory before execution and work in it
> mkdir vagrant
> cd vagrant
#Ubuntu as an example/Download xenial
> vagrant init ubuntu/xenial64
A Vagrantfile will be created where you ran it
Execution result
> vagrant init ubuntu/xenial64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
When you want to set the virtual machine you want to prepare as needed, edit the generated Vagrantfile. If you make a mistake and want to return to the initial state, you can delete the Vagrantfile and execute vagrant init <Box name>
again to start over.
See https://www.vagrantup.com/docs/vagrantfile for a detailed description of Vagrantfile. Most of the items are tied to the VirtualBox setting operation, so you can feel the necessary parts.
Run with the --provision
option to apply the modified Vagrantfile
#If the virtual machine is not started
> vagrant up --provision
#When restarting a running virtual machine and applying it
> vagrant reload --provision
Run vagrant up
in the directory where your Vagrantfile is located
> vagrant up
#If you have multiple virtual machines installed`--provider`Explicitly run as an option
> vagrant up --provider virtualbox
ssh
Run vagrant ssh
to manipulate the shell of the started virtual machine
> vagrant ssh
If you have set port forwarding, you can also operate with ssh connection by connecting to port 2222 (default state). You can log in below
To stop the started virtual machine, run vagrant halt
in the directory containing the Vagrantfile.
> vagrant halt
I have summarized the commands that I often use
command | motion | Note |
---|---|---|
vagrant box add <Box name, URL, or path> | Download Box | |
vagrant box remove |
Delete the downloaded Box | |
vagrant box list | Display a list of downloaded Boxes | |
vagrant init <Box name, URL> | Virtual machine initialization | Vagrantfile is created in the executed directory |
vagrant ssh | Open the ssh shell of the started virtual machine | Run in the directory containing the Vagrantfile |
vagrant up | Start the virtual machine | Run in the directory containing the Vagrantfile |
vagrant halt | Stop the virtual machine | Run in the directory containing the Vagrantfile |
vagrant reload | Reboot the virtual machine | Run in the directory containing the Vagrantfile |
vagrant destroy | Delete virtual machine | Run in the directory containing the Vagrantfile |
vagrant package | Packaging virtual machines(Output in Box format)To do |
tips
Normally, you can delete it with the above vagrant
command, but if you have uninstalled Vagrant, you can open the following location and delete the file.
~/.vagrant.d/boxes
~
is the user's home directory ( C: \ users \ username
on Windows)
~/VirtualBox VMs
If the version of Additions installed in the virtual machine is old and does not work, you can increase the version with the following command.
> vagrant plugin install vagrant-vbguest
Add the following description to the Vagrantfile. If you update Guest Additions by the above procedure, you will have less trouble.
config.vm.synced_folder "./output", "/vagrant/output", type:"virtualbox"
Recommended Posts