1

I have script to setup headless machine on remote headless server, connected by ssh. It will create machine, attaches disk and archiso, and launches installation.

Also, I have script to setup configured Arch, which I launch in its prompted shell, previously pulled by scp.

But there are three intermediate steps between them I would like to eliminate. Pressing Enter on x64 install in grub of archiso, waiting for login in root shell, executing scp user@server:~/arch-install . && ./arch-install

All those actions I can do through RDP. But it's irritating, to be able to automate all installation process beside that.

Of course, there is topic Headless linux install. But I would prefer not to repack archiso, as I need to automate only those 3 steps. Maybe VBox supporting something like expect?

migrated from serverfault.com Apr 4 '15 at 17:10

This question came from our site for system and network administrators.

  • What does VirtualBox have to do with this? Are you installing Arch on a headless computer or in a virtual machine? – Gilles Apr 4 '15 at 22:27
0

I had found the way to implement the automatic guest installation of default archiso image, controlling only host machine, however it's somewhat cumbersome. You need to combine VBox native functionality with exposed serial port over ssh.

Enable virtual serial port support for VBox:

VBoxManage modifyvm "$VNM" --uart1 0x3F8 4 --uartmode1 server "$SERIAL"

Launch vbox:

VBoxManage startvm "$VNM"
# Wait for boot menu. WARNING: May be affected by problem with timing!
sleep 8

Send commands into guest to enable serial port on kernel's boot:

# Press <Tab> to edit boot string, add 'console=ttyS0', then <Enter>
VBoxManage controlvm "$VNM" keyboardputscancode 0f 8f 39 b9  # <Tab><Space>
VBoxManage controlvm "$VNM" keyboardputscancode 2e ae 18 98 31 b1 1f 9f 18 98 26 a6 12 92  # 'console'
VBoxManage controlvm "$VNM" keyboardputscancode 0d 8d 14 94 14 94 15 95 36 1f 9f b6 0b 8b  # '=ttyS0'
VBoxManage controlvm "$VNM" keyboardputscancode 1c 9c  # Enter

Login into shell by serial pipe. I used netcat, but either will work. Next commands show how to work with socket locally (but you can redirect to ssh):

sleep 25
printf "root\n" | nc -q 2 -U "$SERIAL"

Send installation script as heredoc over socket. It was simpler than my primary approach with scp. Hovewer you can execute scp over serial too.

printf "\n"'cat - <<-'"'EOFARCHSETUP' > ~/arch-setup\n" | nc -U "$SERIAL"
cat "$SCRIPT_DIR/arch-setup" | nc -U "$SERIAL"  # Send text content of setup file
printf "\nEOFARCHSETUP\n" | nc -U "$SERIAL"     # End of heredoc file

Start installation:

printf "\nchmod u+x ~/arch-setup\n" | nc -U "$SERIAL"      # Make executable
printf "\ncd ~ && ./arch-setup --new\n" | nc -U "$SERIAL"  # Start install

Non-interactive monitoring of installation (safe with Ctrl-C to interrupt monitoring only w/o affecting the installation):

nc -d -U "$SERIAL"  

If there are some unclear moments left, you can see full scripts at Github

  • The actual scancodes can be derived simply by booting a Linux VM into console mode and run showkey -s, start typing and the exact hex codes will be dumped. – metatoaster Jan 23 '18 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.