1

I am attempting to automate installation of Alpine Linux in vm-bhyve under FreeBSD and expect dies shortly after the boot menu times out and launches the Alpine Linux installation.

#!/usr/bin/env expect
spawn vm install -f alpine alpine.iso # shortened for brevity
expect "localhost login:"
send "root\r"
...

This results in the following error:

"while executing
"send "root\r"

I suspect that whenever the screen clears and it starts to boot, that confuses expect to think the program is done? And, as a result, the script dies.

I've never coded expect in this manner before, is it possible to do it with expect?

I also tried setting a global timeout before spawning the vm install cmd which boots and immediately goes into the console for the guest, but that didn't change anything so I excluded it from the script above. Sleep in the same spot didn't help, it just delayed booting (and subsequent failure by the amount I set for sleep).

EDIT: I am trying to launch the installer in the background, sleep 30s, then attach a console. At this point, Expect should work.

Walter
  • 243
  • 2
  • 6
  • I'd recommend using `autoexpect` to record a fully interactive installation. The resulting expect code is very verbose but can be cleaned up if needed. – glenn jackman Jan 07 '22 at 15:27
  • Additionally, while developing an expect script, launch it with `expect -d` to enable verbose debug output: this can pinpoint why your expect patterns are not matching (often there's "hidden" whitespace). – glenn jackman Jan 07 '22 at 15:35
  • Great idea, I didn't know that existed. Unfortunately, this too dies, I *think* it must not like the terminal. It did capture more output like expect . – Walter Jan 07 '22 at 21:56

1 Answers1

0

I have it working in both cases (vm install -f and using vm console to attach to a running VM).

The problem in my case was that I started with a fresh configuration and that fresh configuration had an invalid setting (PCI passthrough). I thought I had booted up without expect and had that working; however, I had already reimaged the machine and my configuration was overwritten.

Using autoexpect allowed me to capture more details that I would have had otherwise and is a great way to prepare expect scripts.

Now, the process for me is to perform a freebsd install followed by booting into the system and upon startup, check if the VMs exist, if not, create them using expect.

Walter
  • 243
  • 2
  • 6