Skip to content

Commit

Permalink
Serial port support (#8)
Browse files Browse the repository at this point in the history
* Add basic support of access via serial console

* Add avanced serial console support

* Fix vagrant push action

* Cleanup of post install action
  • Loading branch information
b00men authored Sep 15, 2018
1 parent e00f401 commit d0e1886
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 14 deletions.
32 changes: 26 additions & 6 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#hashicorp/precise32
$box_name = "ubuntu/xenial64"
###
### Push action requires: socat, screen
###

$box_name_server = "ubuntu/xenial64"
$box_name_client = "q2p/empty"
$server_ip = "192.168.2.2"
$client_socet = '/tmp/pxe_client_vm-socket'
$client_pty = '/tmp/pxe_client_vm-pty'

Vagrant.configure(2) do |config|
config.vm.define "server", autostart: true do |server|
server.vm.box = $box_name
server.vm.box = $box_name_server
server.vm.hostname = "pxe-server"
server.vm.network "private_network", ip: "192.168.2.2", virtualbox__intnet: "pxe_network"
server.vm.network "private_network", ip: $server_ip, virtualbox__intnet: "pxe_network"
server.vm.synced_folder "vagrant-volume/", "/vagrant-volume/"
server.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
Expand All @@ -21,7 +28,7 @@ Vagrant.configure(2) do |config|
client.ssh.insert_key = "false"
client.vm.boot_timeout = 1
client.vm.post_up_message = "Probably machine is unreachable by ssh. It's expected."
client.vm.box = "q2p/empty"
client.vm.box = $box_name_client
client.vm.provider :virtualbox do |vb|
vb.memory = '1024'
vb.cpus = '1'
Expand All @@ -33,8 +40,21 @@ Vagrant.configure(2) do |config|
'--boot1', 'disk',
'--boot2', 'net',
'--boot3', 'none',
'--boot4', 'none'
'--boot4', 'none',
'--uart1', '0x3F8', '4',
'--uartmode1', 'server', $client_socet
]
end
end

config.push.define "local-exec" do |push|
push.inline = <<-SCRIPT
clear
socat UNIX-CONNECT:#{$client_socet} PTY,link=#{$client_pty} &
echo "Ctrl+A Ctrl+D for detach"
sleep 5
screen #{$client_pty}
SCRIPT
end

end
23 changes: 22 additions & 1 deletion post-install.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
#!/bin/bash
echo test > /root/test-post-install
set -x
readonly LOG_FILE="/root/post-install.log"
touch $LOG_FILE
exec 1>$LOG_FILE
exec 2>&1

echo "##### Start post install actions ..."

echo "### Start configure of serial-getty ..."
systemctl enable [email protected]
systemctl start [email protected]
echo "### Finish configure of serial-getty."

echo "### Start configure of serial access on GRUB ..."
sed -i -r 's/^(GRUB_CMDLINE_LINUX_DEFAULT)/#\1/' /etc/default/grub
sed -i -r 's/^(GRUB_CMDLINE_LINUX=).*/\1"console=tty0 console=ttyS0,115200n8"/' /etc/default/grub
sed -i -r 's/^#?(GRUB_TERMINAL=).*/\1"console serial"/' /etc/default/grub
egrep -q "^GRUB_SERIAL_COMMAND=" /etc/default/grub && sed -i -r 's/^(GRUB_SERIAL_COMMAND=).*/\1"serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"/' /etc/default/grub || echo 'GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"' >> /etc/default/grub
update-grub
echo "### Finish configure of serial access on GRUB."

echo "##### Finish post install actions."
6 changes: 4 additions & 2 deletions preseed.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ d-i netcfg/wireless_wep string
#d-i network-console/password-again password r00tme
# Use this instead if you prefer to use key-based authentication
#d-i network-console/authorized_keys_url http://host/authorized_keys
#d-i preseed/early_command string anna-install network-console

### Mirror settings
# If you select ftp, the mirror/country string does not need to be set.
Expand Down Expand Up @@ -443,7 +444,7 @@ d-i grub-installer/with_other_os boolean true
# During installations from serial console, the regular virtual consoles
# (VT1-VT6) are normally disabled in /etc/inittab. Uncomment the next
# line to prevent this.
#d-i finish-install/keep-consoles boolean true
d-i finish-install/keep-consoles boolean true

# Avoid that last message about the install being complete.
d-i finish-install/reboot_in_progress note
Expand All @@ -467,6 +468,7 @@ d-i finish-install/reboot_in_progress note
# debconf-get-selections --installer > file
# debconf-get-selections >> file

d-i debian-installer/add-kernel-opts console=tty0 console=ttyS0,115200n8

#### Advanced options
### Running custom commands during the installation
Expand All @@ -491,6 +493,6 @@ d-i finish-install/reboot_in_progress note
# packages and run commands in the target system.
#d-i preseed/late_command string apt-install zsh; in-target chsh -s /bin/zsh
d-i preseed/late_command string \
in-target wget https://raw.githubusercontent.com/q2p-us/pxe/master/post-install.sh -O/root/post-install.sh; \
in-target wget https://raw.githubusercontent.com/q2p-us/pxe/master/post-install.sh -O/root/post-install.sh 2>&1; \
in-target chmod a+rx /root/post-install.sh; \
in-target /root/post-install.sh;
14 changes: 11 additions & 3 deletions roles/general/templates/syslinux.cfg.j2
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# D-I config version 2.0
# search path for the c32 support libraries (libcom32, libutil etc.)
serial 0 9600
path ubuntu-installer/amd64/boot-screens/
default ubuntu-installer/amd64/boot-screens/vesamenu.c32
prompt 0
timeout 5
timeout 150
#default Ubuntu16

label Ubuntu16
label Ubuntu16serial
menu default
menu LABEL Ubuntu16serial
kernel ubuntu-installer/amd64/linux
append initrd=ubuntu-installer/amd64/initrd.gz domain={{ domain }} hostname={{ hostname }} preseed/url={{ pxe_proto }}://{{ pxe_path_preseed }}/preseed.txt mirror/http/hostname={{ pxe_mirror }} mirror/protocol=http debian-installer/allow_unauthenticated_ssl=true locale=en_US.UTF-8 debian/priority=critical vga=normal debian-installer/keymap=us console-keymaps-at/keymap=us console-setup/layoutcode=en_US netcfg/choose_interface=auto localechooser/translation/warn-light=true localechooser/translation/warn-severe=true console=tty0 console=ttyS0,115200n8 console-setup/ask_detect=false FRONTEND_BACKGROUND=noninteractive -


label Ubuntu16
menu LABEL Ubuntu16
kernel ubuntu-installer/amd64/linux
append initrd=ubuntu-installer/amd64/initrd.gz domain={{ domain }} hostname={{ hostname }} preseed/url={{ pxe_proto }}://{{ pxe_path_preseed }}/preseed.txt mirror/http/hostname={{ pxe_mirror }} mirror/protocol=http debian-installer/allow_unauthenticated_ssl=true locale=en_US.UTF-8 debian/priority=critical vga=normal debian-installer/keymap=us console-keymaps-at/keymap=us console-setup/layoutcode=en_US netcfg/choose_interface=auto localechooser/translation/warn-light=true localechooser/translation/warn-severe=true console-setup/ask_detect=false FRONTEND_BACKGROUND=original -
append initrd=ubuntu-installer/amd64/initrd.gz domain={{ domain }} hostname={{ hostname }} preseed/url={{ pxe_proto }}://{{ pxe_path_preseed }}/preseed.txt mirror/http/hostname={{ pxe_mirror }} mirror/protocol=http debian-installer/allow_unauthenticated_ssl=true locale=en_US.UTF-8 debian/priority=critical vga=normal debian-installer/keymap=us console-keymaps-at/keymap=us console-setup/layoutcode=en_US netcfg/choose_interface=auto localechooser/translation/warn-light=true localechooser/translation/warn-severe=true console=ttyS0,115200n8 console=tty0 console-setup/ask_detect=false FRONTEND_BACKGROUND=noninteractive -
6 changes: 4 additions & 2 deletions roles/nginx/templates/preseed.txt.j2
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ d-i netcfg/wireless_wep string
#d-i network-console/password-again password r00tme
# Use this instead if you prefer to use key-based authentication
#d-i network-console/authorized_keys_url http://host/authorized_keys
#d-i preseed/early_command string anna-install network-console

### Mirror settings
# If you select ftp, the mirror/country string does not need to be set.
Expand Down Expand Up @@ -442,7 +443,7 @@ d-i grub-installer/with_other_os boolean true
# During installations from serial console, the regular virtual consoles
# (VT1-VT6) are normally disabled in /etc/inittab. Uncomment the next
# line to prevent this.
#d-i finish-install/keep-consoles boolean true
d-i finish-install/keep-consoles boolean true

# Avoid that last message about the install being complete.
d-i finish-install/reboot_in_progress note
Expand All @@ -466,6 +467,7 @@ d-i finish-install/reboot_in_progress note
# debconf-get-selections --installer > file
# debconf-get-selections >> file

d-i debian-installer/add-kernel-opts console=tty0 console=ttyS0,115200n8

#### Advanced options
### Running custom commands during the installation
Expand All @@ -490,6 +492,6 @@ d-i finish-install/reboot_in_progress note
# packages and run commands in the target system.
#d-i preseed/late_command string apt-install zsh; in-target chsh -s /bin/zsh
d-i preseed/late_command string \
in-target wget {{ pxe_proto }}://{{ pxe_path_post_install }}/post-install.sh -O/root/post-install.sh; \
in-target wget {{ pxe_proto }}://{{ pxe_path_post_install }}/post-install.sh -O/root/post-install.sh 2>&1; \
in-target chmod a+rx /root/post-install.sh; \
in-target /root/post-install.sh;

0 comments on commit d0e1886

Please sign in to comment.