Using vagrant to run virtual machines with desktop

2019-01-20 20:46发布

My company's development environment is based on virtual machines, running on VirtualBox. We would like to move one step further, and use the capabilities of Vagrant to have the description of the machine in a text file and then be able to "raise" that machine based on that text file. Combined to puppet, this would solve us the problem that everyone have different software versions installed in the VM.

However, Vagrant seems very focused to develop on the host, letting the machine in the background. We would need to have our development environment within the machine, so we would need a complete GUI, so when typing "vagrant up" a machine with a complete desktop environment (XFCE, KDE...) should appear.

So far, I've managed to create a "base" box from a Xubuntu distribution. But when I type "vagrant up", although the desktop appears, and I am able to login properly, Vagrant freezes at the message "Waiting for machine to boot. This may take a few minutes...". After a while Vagrant crashes due timeout. So shared folders are not created, nor the package provisioner -puppet- is executed.

How to create a virtual machine with a complete GUI using vagrant?

9条回答
【Aperson】
2楼-- · 2019-01-20 21:28

https://askubuntu.com/questions/300799/does-ubuntu-12-04-lts-32-bit-have-graphic-user-interface/300805#300805

After installing the desktop, you'll also want to install GDM which will let you boot directly into a graphical environment. You'll also want to configure it.

So maybe add this?

Vagrant::Config.run do |config|
    config.vm.provision :shell, :inline => "sudo apt-get install gdm"
    config.vm.provision :shell, :inline => "sudo dpkg-reconfigure gdm"
end
查看更多
一纸荒年 Trace。
3楼-- · 2019-01-20 21:35

I just got this working with basically three steps. The advice from askubuntu.com didn't quite work for me, so try this simplified version:

  1. Get a basic Ubuntu image working. You should be able to boot it and vagrant ssh.
  2. Next, enable the VirtualBox display, which is off by default. Halt the VM and uncomment these lines in Vagrantfile:
    config.vm.provider :virtualbox do |vb|
      vb.gui = true
    end
  3. Boot the VM and observe the new display window. Now you just need to install and start xfce4. Use vagrant ssh and:
    sudo apt-get install xfce4
    sudo startxfce4&
    

That's it, you should be landed in a xfce4 session.

Update: For a better experience, I recommend these improvements:

  1. Don't start the GUI as root. You really want to stay the vagrant user. To do this you need to permit anyone to start the GUI: sudo vim /etc/X11/Xwrapper.config and edit it to allowed_users=anybody.
  2. Next, install the VirtualBox guest tools before starting the GUI. This will give you a healthy screen resolution, integrated mouse, etc.
    $ sudo apt-get install -y xfce4 virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11
    $ sudo VBoxClient-all
  3. Only now should you start the GUI as the vagrant user, with $ startxfce4&.

Update 2: Tried this today and the VBoxClient-all script isn't always installed. If it's missing, you can replace with the equivalent:

sudo VBoxClient --clipboard
sudo VBoxClient --draganddrop
sudo VBoxClient --display
sudo VBoxClient --checkhostversion
sudo VBoxClient --seamless
查看更多
等我变得足够好
4楼-- · 2019-01-20 21:36

My 2 cents

  • Make sure you are running latest vagrant (1.3.3 now) + VirtualBox (4.2.18) to avoid bugs.

  • You can use shell script or inline command to install a desktop environment or a light weight window manager

    For example install LXDE on top of Ubuntu 12.04 Precise base box from vagrantbox.es

Vagrant.configure("2") do |config|
  # ... other configuration

  config.vm.provision "shell" do |s|
    s.inline = "apt-get install lubuntu-desktop -y"
  end
end
  • If you build your own vagrant base boxes, make sure you follow the base box packaging instructions or consider tools like packer (or veewee) to automate the build.
查看更多
登录 后发表回答