Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible raise condition on vagrant up #13380

Open
mselseth opened this issue Apr 7, 2024 · 0 comments
Open

possible raise condition on vagrant up #13380

mselseth opened this issue Apr 7, 2024 · 0 comments

Comments

@mselseth
Copy link

mselseth commented Apr 7, 2024

Debug output

default: /vagrant => C:/work/vagrant_tools/1804g

Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=1001,gid=1001,_netdev vagrant /vagrant

The error output from the command was:

: No such device

Expected behavior

==> default: Mounting shared folders...
default: /vagrant => C:/work/vagrant_tools/1804g
==> default: Machine already provisioned. Run vagrant provision or use the --provision
==> default: flag to force provisioning. Provisioners marked to run always will still run.

Actual behavior

VM Linux guest fails to start

Reproduction information

Provision VM as Virtual Box VM, using Ubuntu 18.04 base, while on vpn, from Windows 10 host.
Virtual Box version 7.0.12.
Ubuntu VM 18.04 base has 6.1.32r149290 guest additions installed.
Vagrant scripts are updating the guest additions from 6.1.32 to 7.0.12 at VM provisioning step.

After the failure, started vagrant ssh and manually run the command:
sudo mount -t vboxsf -o uid=1001,gid=1001,_netdev vagrant /vagrant
echo $?
0

At this point the command completes.
So this is why I believe it is a raise condition.

One possible workaround would be to tell vagrant to run a script before vagrant attempts to configure the shared folders.
Don't know how to time that it runs before the step that configures the shared folders.
The script can wait for the vboxsf to be mounted and/or retry before giving up.

Noting that I didn't see it fail outside of the vpn, so it is definitely related to network timing.

Vagrant version

Installed Version: 2.4.0

Host operating system

Windows 10

Guest operating system

Ubuntu 18.04

Steps to reproduce

  1. vagrant up <-- Provision step
  2. power down VM
  3. vagrant up <-- run step (this step fails)

Vagrantfile

# Copy-paste your Vagrantfile here. Remove any sensitive information such as passwords, authentication tokens, or email addresses.

# -*- mode: ruby -*-
# vi: set ft=ruby :

load 'Vagrantfile.vb_version'
load 'Vagrantfile.personal'

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # Set auto_update to false, don't want to check the correct additions
  # version when booting this machine
  config.vbguest.auto_update = false

  # Tell vagrant to not install virtual box additions; the additions will be
  # installed explicitly by the fix-guest-additions.sh script.
  # The fix-guest-additions.sh script is needed because the vagrant
  # built-in installation doesn't complete and causes failures.
  config.vbguest.no_install = true

  # Do not download the iso file from a webserver
  config.vbguest.no_remote = true

  # All Vagrant configuration is done here. The most common configuration
  # options are documented and commented below. For a complete reference,
  # please see the online documentation at vagrantup.com.

  # Every Vagrant virtual environment requires a box to build off of.
  config.vm.box = BOX_BASE
  config.vm.box_version = BOX_VERSION

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`.
  config.vm.box_check_update = false

  if WINDOWS_VM == 'yes'
    # Additional parameters to communicate with Windows
    config.vm.boot_timeout = 60
    config.vm.communicator = "winrm"
    config.winrm.port = 55985
  end

  # Credit goes to @andyshinn and Nathan for identifying the fix on the Vagrant
  # GitHub (#1673).
  #
  # The issue arises because Ubuntu's default /root/.profile contains a line that
  # prevents messages from being written to root's console by other users.
  # This "mesg n" command fails because it is expecting to be run from an
  # interactive terminal (a tty) and not a script.
  #
  # The code below simply replaces the original line in /root/.profile with one
  # that checks to see if the current terminal is a tty before running the
  # "mesg n" command. It sets the privileged option of the shell provisioner to
  # false so that we don't get the error during this provisioner and uses sudo
  # instead to get appropriate privileges.
  #
  # This provisioner is idempotent (meaning, it can be run over and over) and
  # has no security or stability issues.
  #
  # Of course, if part of your provisioning does actually require a TTY, this
  # doesn't really solve the problem. The one common provisioning step that does
  # involve a TTY is packages that expect a configuration is the installation
  # of Debian packages. For this case, you should use dpkg-preconfigure to
  # provide the necessary information up front.
  #
  # Prevents triggers of stdin: is not a tty when running scripts via
  # config.vm.provision "shell", path: ...
  if WINDOWS_VM == 'no'
    config.vm.provision "fix-no-tty", type: "shell" do |s|
      s.privileged = false
      s.inline = "sudo touch /root/.profile; sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
    end
  end

  # Script common.sh is sourced from the provisioning script provision-vm.sh
  # and few other scripts.
  # Make common.sh script available in VM as a workaroud for this failure:
  #   + . /tmp/common.sh
  #   /tmp/vagrant-shell: 28: .: Can't open /tmp/common.sh
  # Simply copy it to the VM guest before running the provisioning script
  if WINDOWS_VM == 'no'
    config.vm.provision "file",             \
      source: "vagrant-scripts/common.sh" , \
      destination: "/tmp/common.sh"

    config.vm.provision "shell", privileged: false,  \
      path: "vagrant-scripts/provision-vm.sh",       \
      :args => [INSTALL_SHAKOPEE_TOOLS,              \
                VM_IP_ADDRESS,                       \
                GIT_USER_NAME,                       \
                GIT_USER_EMAIL_ADDRESS,              \
                INSTALL_WIND_RIVER_7,                \
                VIRTUAL_BOX_GUEST_ADDITIONS_VERSION, \
                USER_NAME,                           \
                SAMBA_SHARED_DIRECTORY_NAME,         \
                SAMBA_SHARED_DIRECTORY,              \
                NCIPHER_CONFIG]
  end

  # Give the name for the created machine
  config.vm.hostname = VM_HOST_NAME_WRL

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network :forwarded_port, guest: 80, host: 8080, auto_correct: true

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network :private_network, auto_config: false, ip: VM_IP_ADDRESS

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  if VM_IP_ADDRESS == 'dhcp' then
    config.vm.network :public_network, bridge: BRIDGED_NETWORK_ADAPTER_NAME, auto_config: false, use_dhcp_assigned_default_route: true
  else
    config.vm.network :public_network, bridge: BRIDGED_NETWORK_ADAPTER_NAME, auto_config: false, ip: VM_IP_ADDRESS
  end

  # If true, then any SSH connections made will enable agent forwarding.
  # Default value: false
  # config.ssh.forward_agent = true

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  config.vm.synced_folder File.dirname(__FILE__), "/vagrant", disabled: false

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  config.vm.provider :virtualbox do |vb|
    # Tell vagrant booting mode (headless mode or gui)
    vb.gui = USE_THE_GUI

    # Use VBoxManage to customize the VM.
    vb.customize ["modifyvm", :id, "--memory", MEMORY_TO_USE]
    vb.customize ["modifyvm", :id, "--cpus", CPUS_TO_USE]
    vb.customize ["modifyvm", :id, "--name", VM_MACHINE_NAME_WRL]
    vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
    vb.customize ["modifyvm", :id, "--draganddrop", "bidirectional"]
    vb.customize ["modifyvm", :id, "--graphicscontroller", GRAPHICS_CONTROLLER]
    vb.customize ["modifyvm", :id, "--vram", VIDEO_MEMORY]
    # Turn off the remote display
    vb.customize ["modifyvm", :id, "--vrde", "off"]
    vb.customize ["modifyvm", :id, "--accelerate3d", ACCELERATION]
  end

  # All VirtualBox VMs for vagrant should have default vagrant user defined
  config.ssh.username="..."

  # When starting a new VM, vagrant environment expects default credentials
  # vagrant/vagrant, set when Virtual Box base is created

  # config.ssh.username in the line above gets updated from vagrant user to the
  # new user as part of running adduser.sh script

  # After the new VM is rebooted, vagrant user is removed via runMeFirst.sh
  # script.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant