Under win7 environment, vagrant, start the virtual machine when the error io.rb: 32: in `encode ': incomplete" \ xC8 "on GBK (Encoding :: InvalidByteSequenceError)

Description :

  These days in the windows environment, the deployment of a vagrant, being given time to start the virtual machine:

[c:\~]$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: Sessions_default_1566958579504_77159
==> default: Destroying VM and associated drives...
D:/tools/HashiCorp/Vagrant/embedded/gems/2.2.5/gems/vagrant-2.2.5/lib/vagrant/util/io.rb:32:in `encode': incomplete "\xC8" on GBK (Encoding::InvalidByteSequenceError)
    from D:/tools/HashiCorp/Vagrant/embedded/gems/2.2.5/gems/vagrant-2.2.5/lib/vagrant/util/io.rb:32:in `read_until_block'
    from D:/tools/HashiCorp/Vagrant/embedded/gems/2.2.5/gems/vagrant-2.2.5/lib/vagrant/util/subprocess.rb:194:in `block in execute'
    from D:/tools/HashiCorp/Vagrant/embedded/gems/2.2.5/gems/vagrant-2.2.5/lib/vagrant/util/subprocess.rb:192:in `each'
    from D:/tools/HashiCorp/Vagrant/embedded/gems/2.2.5/gems/vagrant-2.2.5/lib/vagrant/util/subprocess.rb:192:in `execute'
    from D:/tools/HashiCorp/Vagrant/embedded/gems/2.2.5/gems/vagrant-2.2.5/lib/vagrant/util/subprocess.rb:22:in `execute'

Resolution process :

  For a long time, did not understand that, then we see the solution to the problem on the foreign github.

Reference Address: https://github.com/hashicorp/vagrant/issues/9368

Reference:

My Solution

With the help of a non vagrant-related StackOverflow solution, I solved the issue by changing the line 32 in "Vagrant\embedded\gems\gems\vagrant-2.0.1\lib\vagrant\util" as:

data << io.readpartial(READ_CHUNK_SIZE).encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')

 I.e. modifying the source code, and change it to say:

1. Locate the D: /tools/HashiCorp/Vagrant/embedded/gems/2.2.5/gems/vagrant-2.2.5/lib/vagrant/util/io.rb file, locate the line 32

data << io.readpartial(READ_CHUNK_SIZE).encode("UTF-8", Encoding.default_external)

 

 2. Comment out this line, the following code is added on the reference github

              #data << io.readpartial(READ_CHUNK_SIZE).encode("UTF-8", Encoding.default_external)
              data << io.readpartial(READ_CHUNK_SIZE).encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')

 

 3. After modification, re-execute the command vagrant up

[c:\~]$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: Sessions_default_1566958795239_49467
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: Connection aborted. Retrying...
    default: Warning: Remote connection disconnect. 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: 4.3.30
    default: VirtualBox Version: 6.0
==> default: Mounting shared folders...
    default: /vagrant => C:/Users/Administrator/Documents/NetSarang/Xshell/Sessions

successfully passed!

 

Documentation Created : August 28, 2019 10:44:13

Guess you like

Origin www.cnblogs.com/chuanzhang053/p/11422662.html