본문 바로가기
DevOps/DockerKubernetes

(Windows) Vagrant로 Linux(ubuntu) VM 단번에 생성하기

by 계영수 2022. 9. 3.
728x90

윈도우 환경에서 리눅스 VM을 빠르게 구축하는 방법은 Vagrant를 이용하는 방법이다. 본 포스팅에서는 윈도우 환경에서 Vagrant로 빠르게 Linux(Ubuntu) VM을 생성하는 방법을 설명한다. 

 

C:\HashiCorp\ubuntu>dir
 C 드라이브의 볼륨에는 이름이 없습니다.
 볼륨 일련 번호: D032-8A69

 C:\HashiCorp\ubuntu 디렉터리

2022-09-03  오후 09:25    <DIR>          .
2022-09-03  오후 09:25    <DIR>          ..
               0개 파일                   0 바이트
               2개 디렉터리  264,241,287,168 바이트 남음

C:\HashiCorp\ubuntu>

Vagrant가 설치되었으면 C 드라이브에 HashiCorp 라는 폴더가 생성되어 있다. 디렉토리 아래에 ubuntu라는 디렉토리를 생성한다.

C:\HashiCorp\ubuntu>vagrant init ubuntu/focal64
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.

C:\HashiCorp\ubuntu>
C:\HashiCorp\ubuntu>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/focal64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/focal64' version '20220901.0.0' is up to date...
==> default: A newer version of the box 'ubuntu/focal64' for provider 'virtualbox' is
==> default: available! You currently have version '20220901.0.0'. The latest is version
==> default: '20220902.0.0'. Run `vagrant box update` to update.
==> default: Setting the name of the VM: ubuntu_default_1662208399211_31014
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => C:/HashiCorp/ubuntu

C:\HashiCorp\ubuntu>

생성된 VM으로 SSH 접속을 위한 정보를 확인한다.

C:\HashiCorp\ubuntu>vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile C:/HashiCorp/ubuntu/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL


C:\HashiCorp\ubuntu>

Private Key의 위치를 확인하여 터미널 접속시 해당 키를 연동하여 로그인한다.

SSH로 접속하면 아래와 같이 나온다.

Welcome to Ubuntu 20.04.5 LTS (GNU/Linux 5.4.0-125-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sat Sep  3 12:38:57 UTC 2022

  System load:  0.0               Processes:               116
  Usage of /:   3.5% of 38.70GB   Users logged in:         0
  Memory usage: 20%               IPv4 address for enp0s3: 10.0.2.15
  Swap usage:   0%


0 updates can be applied immediately.

New release '22.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.


vagrant@ubuntu-focal:~$
728x90