diff --git a/Vagrantfile b/Vagrantfile index 92434da..6a590aa 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -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" @@ -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' @@ -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 diff --git a/post-install.sh b/post-install.sh index 2a8d7ec..f2323a6 100644 --- a/post-install.sh +++ b/post-install.sh @@ -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 serial-getty@ttyS0.service +systemctl start serial-getty@ttyS0.service +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." diff --git a/preseed.txt b/preseed.txt index a3ff9fa..19cfcd3 100644 --- a/preseed.txt +++ b/preseed.txt @@ -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. @@ -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 @@ -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 @@ -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; diff --git a/roles/general/templates/syslinux.cfg.j2 b/roles/general/templates/syslinux.cfg.j2 index fabb819..5656c80 100644 --- a/roles/general/templates/syslinux.cfg.j2 +++ b/roles/general/templates/syslinux.cfg.j2 @@ -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 - diff --git a/roles/nginx/templates/preseed.txt.j2 b/roles/nginx/templates/preseed.txt.j2 index 0f48203..fea0fcf 100644 --- a/roles/nginx/templates/preseed.txt.j2 +++ b/roles/nginx/templates/preseed.txt.j2 @@ -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. @@ -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 @@ -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 @@ -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;