Score:1

Using expect to automate Alpine Linux installation in FreeBSD in Bhyve

mx flag

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.

fo flag
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.
fo flag
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).
mx flag
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 <GRUB MENU>.
Score:0
mx flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.