Bug 245051

Summary: Vagrant image for 12.1 can't start shell
Product: Base System Reporter: Ruslan Yakauleu <ruslan.yakauleu>
Component: miscAssignee: Glen Barber <gjb>
Status: In Progress ---    
Severity: Affects Some People CC: emaste, jlduran, jmg
Priority: ---    
Version: 12.1-STABLE   
Hardware: amd64   
OS: Any   
Attachments:
Description Flags
Use bash as shell for the Vagrant user none

Description Ruslan Yakauleu 2020-03-25 12:20:37 UTC
By this doc https://www.freebsd.org/releases/12.1R/announce.html

$ vagrant init freebsd/FreeBSD-12.1-RELEASE
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'freebsd/FreeBSD-12.1-RELEASE' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'freebsd/FreeBSD-12.1-RELEASE'
    default: URL: https://vagrantcloud.com/freebsd/FreeBSD-12.1-RELEASE
==> default: Adding box 'freebsd/FreeBSD-12.1-RELEASE' (v2019.11.01) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/freebsd/boxes/FreeBSD-12.1-RELEASE/versions/2019.11.01/providers/virtualbox.box
    default: Download redirected to host: vagrantcloud-files-production.s3.amazonaws.com
==> default: Successfully added box 'freebsd/FreeBSD-12.1-RELEASE' (v2019.11.01) for 'virtualbox'!
==> default: Importing base box 'freebsd/FreeBSD-12.1-RELEASE'...
==> default: Generating MAC address for NAT networking...
==> default: Checking if box 'freebsd/FreeBSD-12.1-RELEASE' version '2019.11.01' is up to date...
==> default: Setting the name of the VM: vm_default_1585136809769_53470
Vagrant is currently configured to create VirtualBox synced folders with
the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant                                                               
guest is not trusted, you may want to disable this option. For more                                                                  
information on this option, please refer to the VirtualBox manual:                                                                   

  https://www.virtualbox.org/manual/ch04.html#sharedfolders                                                                          

This option can be disabled globally with an environment variable:                                                                   

  VAGRANT_DISABLE_VBOXSYMLINKCREATE=1                                                                                                

or on a per folder basis within the Vagrantfile:                                                                                     

  config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlinksCreate: false
==> 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: 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: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
The configured shell (config.ssh.shell) is invalid and unable
to properly execute commands. The most common cause for this is
using a shell that is unavailable on the system. Please verify
you're using the full path to the shell and that the shell is
executable by the SSH user.

$vagrant --version
Vagrant 2.2.7
Comment 1 John-Mark Gurney freebsd_committer 2020-05-23 22:08:28 UTC
I have been able to reproduce this.  This affects the following versions of FreeBSD 11.3-R, 11.x-STABLE, 12.1-R, 13.0-CURRENT and likely effects all images produced.

I have sent an email to re@ about this, but have not received a reply about this.  Here is the email:
There is an issue where vagrant defaults to using bash to see if a VM
is running.  We do not install bash by default, and so that results in
the following experience:
nmac,ttys006,~/f114b,505$vagrant init freebsd/FreeBSD-11.4-BETA2
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.
nmac,ttys006,~/f114b,506$vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'freebsd/FreeBSD-11.4-BETA2' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'freebsd/FreeBSD-11.4-BETA2'
    default: URL: https://vagrantcloud.com/freebsd/FreeBSD-11.4-BETA2
==> default: Adding box 'freebsd/FreeBSD-11.4-BETA2' (v2020.05.15) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/freebsd/boxes/FreeBSD-11.4-BETA2/versions/2020.05.15/providers/virtualbox.box
    default: Download redirected to host: vagrantcloud-files-production.s3.amazonaws.com
==> default: Successfully added box 'freebsd/FreeBSD-11.4-BETA2' (v2020.05.15) for 'virtualbox'!
==> default: Importing base box 'freebsd/FreeBSD-11.4-BETA2'...
==> default: Generating MAC address for NAT networking...
==> default: Checking if box 'freebsd/FreeBSD-11.4-BETA2' version '2020.05.15' is up to date...
==> default: Setting the name of the VM: f114b_default_1590096819756_45273
==> default: Fixed port collision for 22 => 2222. Now on port 2201.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2201 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2201
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
The configured shell (config.ssh.shell) is invalid and unable
to properly execute commands. The most common cause for this is
using a shell that is unavailable on the system. Please verify
you're using the full path to the shell and that the shell is
executable by the SSH user.

it also causes other things to happen.  I filed a bug w/ vagrant, and
they refused to fix it on their side of things (like doing the correct
posix way of using sh): https://github.com/hashicorp/vagrant/issues/11532

I have finally attempted the fix of providing a default Vagrantfile in
the box with a shell set of sh, and this fixed the error.  The file
contents were just:
Vagrant.configure("2") do |config|
        config.ssh.shell = "/bin/sh"
end

and the only requirements was that the file be located in the same
directory:
nmac,ttys006,~/f114b,545$tar -tzf shellfix.box
Vagrantfile
box.ovf
metadata.json
vagrant.vmdk

Otherwise everything else was the same.

and with that fix applied:
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2201
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    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: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 5.2.34
    default: VirtualBox Version: 6.0
==> default: Mounting shared folders...
    default: /vagrant => /Users/jmg/f114b
Vagrant is not able to mount VirtualBox shared folders on BSD-based
guests. BSD-based guests do not support the VirtualBox filesystem at
this time.

To change the type of the default synced folder, specify the type as
rsync or nfs:

    config.vm.synced_folder ".", "/vagrant", type: "nfs" # or "rsync"

Alternatively, if you do not need to mount the default synced folder,
you can also disable it entirely:

    config.vm.synced_folder ".", "/vagrant", disabled: true

You can read more about Vagrant's synced folder types and the various
configuration options on the Vagrant website.

This is not a bug in Vagrant.


I have not dug into why it cannot mount /vagrant, but I do have some
work on getting this working on 13.0-CURRENT.

I do not have a good way to run through the release process to generate
a patch that would work, but I'm more than willing to test any box that
is created..  They can either be pushed to the vagrant cloud, or provide
me w/ a url, or even a location on the freebsd cluster that I scp down,
and I will quickly confirm if the fix works.

This affects all releases, not just 11.x, but 12.x and the 13.0
snapshots as well.
Comment 2 commit-hook freebsd_committer 2020-05-28 18:48:57 UTC
A commit references this bug:

Author: gjb
Date: Thu May 28 18:48:31 UTC 2020
New revision: 361591
URL: https://svnweb.freebsd.org/changeset/base/361591

Log:
  Include the shells/bash port on Vagrant images, which prevents
  a shell issue during startup.

  PR:		245051
  MFC after:	1 minute (if approved by re@)
  X-MFC-for:	11.4-RC2
  Sponsored by:	Rubicon Communications, LLC (netgate.com)

Changes:
  head/release/tools/vagrant.conf
Comment 3 commit-hook freebsd_committer 2020-05-28 18:58:01 UTC
A commit references this bug:

Author: gjb
Date: Thu May 28 18:57:08 UTC 2020
New revision: 361592
URL: https://svnweb.freebsd.org/changeset/base/361592

Log:
  Include the shells/bash port on Vagrant images, which prevents
  a shell issue during startup.

  Approved by:	re (kib, insta-MFC)
  PR:		245051
  Sponsored by:	Rubicon Communications, LLC (netgate.com)

Changes:
_U  stable/11/
  stable/11/release/tools/vagrant.conf
Comment 4 commit-hook freebsd_committer 2020-05-28 18:58:03 UTC
A commit references this bug:

Author: gjb
Date: Thu May 28 18:57:56 UTC 2020
New revision: 361593
URL: https://svnweb.freebsd.org/changeset/base/361593

Log:
  Include the shells/bash port on Vagrant images, which prevents
  a shell issue during startup.

  Approved by:	re (kib, insta-MFC)
  PR:		245051
  Sponsored by:	Rubicon Communications, LLC (netgate.com)

Changes:
_U  stable/12/
  stable/12/release/tools/vagrant.conf
Comment 5 commit-hook freebsd_committer 2020-05-28 19:15:07 UTC
A commit references this bug:

Author: gjb
Date: Thu May 28 19:14:44 UTC 2020
New revision: 361594
URL: https://svnweb.freebsd.org/changeset/base/361594

Log:
  MFS11 r361592:
   MFH r361591:
   Include the shells/bash port on Vagrant images, which prevents
   a shell issue during startup.

  PR:		245051
  Approved by:	re (kib, insta-MFC for inclusion in RC2)
  Sponsored by:	Rubicon Communications, LLC (netgate.com)

Changes:
_U  releng/11.4/
  releng/11.4/release/tools/vagrant.conf
Comment 6 Jose Luis Duran 2020-05-28 19:48:07 UTC
Created attachment 214988 [details]
Use bash as shell for the Vagrant user

Now that bash is included, assign it as the default shell for vagrant.
Comment 7 Glen Barber freebsd_committer 2020-05-28 20:00:30 UTC
(In reply to Jose Luis Duran from comment #6)
I disagree with this change.  The addition of bash resolves the issue with the initial startup of the VM, but it is not needed as the default shell (and more importantly, deviates from historic defaults).
Comment 8 Jose Luis Duran 2020-05-28 20:07:49 UTC
(In reply to Glen Barber from comment #7)

While I agree that it is not needed and that it is has not been the default, Vagrant _assumes_ that bash is the default shell for the user (and for its scripts):

https://www.vagrantup.com/docs/vagrantfile/ssh_settings.html#config-ssh-shell
https://www.vagrantup.com/docs/triggers/configuration.html#run

However, I am not going to argue with @re.