2

This is driving me crazy. I am trying to build a Debian image from an ISO using Packer and the VirtualBox builder (on macOS, if that matters). This process involves the VM downloading a Debian preseed file from a HTTP server provided by Packer.

The problem is, when I do not touch the network configuration of the VM created by Packer, it gets its configuration via DHCP and is on the 10.0.2.0 NAT network, but it cannot download the preseed file. Debugging the install process using the preseed/interactive=true boot argument and entering a shell just before the preseed download, this is reproducible: network is up, and everything else is reachable, but 10.0.2.2 (this is the IP of the host where Packager's HTTP server is running) is not reachable: ping and wget are simply stuck and time out. However, another Debian guest running in VirtualBox on the same network, is perfectly capable of downloading the preseed from Packer's server!

I can fix the preseed download by modifying the Packer JSON to set another the network to natnetwork for the VM like so:

"vboxmanage": [
    [ "modifyvm", "{{.Name}}", "--nic1", "natnetwork" ]
]

Now when running Packer the host is reachable from the guest, the preseed file get's downloaded, and the Debian installation proceeds. However, after the installation completes, the guest is not reachable from the host, and Packer is unable to establish an SSH connection to continue provisioning. The Packer log says:

2023/03/22 11:33:17 packer-plugin-virtualbox_v1.0.4_x5.0_darwin_amd64 plugin: 2023/03/22 11:33:17 [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4430: connect: connection refused

So basically, to make this run, I'd have to switch networks right in the middle of the Packer run. This is no doubt related to my limited understanding of VirtualBox and networking. Perhaps someone can come up with an idea?

fpbhb
  • 121

2 Answers2

1

This is roughly the time line of when I encountered the same bug. Your troubleshooting is correct I believe this is pointing at the NAT networking in VirtualBox 7.

The reference to the potential bug/solution is found on the Packer GitHub Issue Tracker #12118

By adjusting the nat network setting via the vboxmanage line in your Packer Build template this fix should resolve your NAT reachability issue.

# Change to --nat-localhostreachable1 forced by 
vboxmanage = [["modifyvm", "{{.Name}}", "--nat-localhostreachable1", "on"]]
0

I have faced a similar dilemma in the last few weeks. This may be baseless speculation: https://github.com/artificialwisdomai/origin/pull/45#discussion_r1244125648.