G9CJR

        -- Can also be ^[\w.]+$, thought that doesn't work everywhere.
        -- ..it works almost everywhere, just differently :)

        http://stackoverflow.com
             /questions/1721602/regex-match-a-z-a-z-0-9-and

Keyboard layout
---------------

Note: Acess via SSH to use host machine keyboard layout.

Note: To change keyboard layout in console mode

  $ sudo loadkeys ee
  $ sudo loadkeys us
  $ sudo loadkeys ru

To change it permanently via the terminal run this:

  http://askubuntu.com/questions/342066
       /how-to-permanently-configure-keyboard

For us (ee, ru):

  L='us' && sudo sed -i 's/XKBLAYOUT=\"\w*"/XKBLAYOUT=\"'$L'\"/g' \
  /etc/default/keyboard

Tested on Ubuntu 16.04 64 bit.


Boot VirtualBox guest from USB
------------------------------

  http://www.howtogeek.com/187721
       /how-to-boot-from-a-usb-drive-in-virtualbox/

Run

  C:\..> VBoxManage internalcommands createrawvmdk -filename \
                    C:\usb.vmdk -rawdisk \\.\PhysicalDrive#

where # can be found in:

  Control Panel ->
      Administrative Tools ->
          Computer Management ->
              Storage ->
                  Disk Management

Now create a machine with C:\usb.vmdk HDD.


Notes on creating SystemRescueCD USB
------------------------------------

A) Recommended USB installation method from Linux using isohybrid

  This will modify the iso in place:

    # apt install syslinux-utils
    $ isohybrid systemrescuecd-x86-4.8.1.iso
    # # sdx is the USB stick, use lsblk
    # dd if=systemrescuecd-x86-4.8.1.iso bs=32768 | pv > /dev/sdx

PXE install
-----------

  http://askubuntu.com/questions/282028
       /best-way-to-mass-install-ubuntu-12-10-over-1000-pc

Install Ubuntu via PXE Boot and take the configuration from a preseed file. https://help.ubuntu.com/lts/installation-guide/i386/preseed-intro.html

You need a TFTP-, DHCP-, NFS- and a Webserver, which can be one machine in your local network. After the full configuration, you will have an unattended install of ubuntu.

If you need further configuration on all the pc you can use puppet to provide the same configuration to all machines. https://help.ubuntu.com/12.04/serverguide/puppet.html

This is a lot of configuration bevor the installation, but it is less work then installing every pc by hand.

Another option is to create an image of your customized Ubuntu an share it via multicast with clonezilla: http://www.corbacho.info/clonezilla/clonezilla.html

Further configurations can be done with puppet again.

--------------------

PXEnial
-------

(Based on F1HF0-UbuntuNetworking.txt)

1. Install Ubuntu from mini.iso (x86_64 Ubuntu 16.04)

  Select and install software: None

  $ dpkg -l | wc -l
    253

2. Make it suit your needs:

  sudo apt install build-essential vim openssh-server \
                   inetutils-inetd tftpd-hpa pxelinux \
                   isc-dhcp-server nfs-kernel-server \
                   iptables ufw unzip apache2 \
                   libapache2-mod-php7.0 php7.0 \
                   elinks syslinux-utils

3. Check NIC's

  root@PXEnial:~# dmesg | grep enp
  [    5.914509] e1000 0000:00:08.0 enp0s8: renamed from eth1
  [    5.937909] e1000 0000:00:03.0 enp0s3: renamed from eth0

Masquerade

  $ sudo vi /etc/ufw/before.rules # before *filter row:

  # NAT table rules: eth0 to NAT network IP 10.0.2.15
  #                  eth1 to INTERNAL network IP 172.16.0.1

  *nat
  :POSTROUTING ACCEPT [0:0]

  # Forward traffic through eth0 - Change to match you out-interface
  -A POSTROUTING -s 172.16.0.0/24 -o eth0 -j MASQUERADE

  # don't delete the 'COMMIT' line or these nat table rules won't
  # be processed
  COMMIT

Start firewall

  service ufw start

Enable forwarding:

  # echo 1 > /proc/sys/net/ipv4/ip_forward

in /etc/sysctl.conf

  # Uncomment the next line to enable packet forwarding for IPv4
  net.ipv4.ip_forward=1

4. DHCP

  # vi /etc/default/isc-dhcp-server

  INTERFACES="enp0s8"

  # vi /etc/dhcp/dhcpd.conf

  option domain-name-servers 192.168.1.254;

  default-lease-time 86400;
  max-lease-time 604800;

  authoritative;

  subnet 172.16.0.0 netmask 255.255.255.0 {
          range 172.16.0.10 172.16.0.49;
          filename "pxelinux.0";
          option subnet-mask 255.255.255.0;
          option broadcast-address 172.16.0.255;
          option routers 172.16.0.1;
          next-server 172.16.0.1;
  }

where next-server is IP of our PXE server.

Start DHCP server

  # service isc-dhcp-server start

Now check on slave (one NIC on ETH0, internal network (intnet)):

  # ifconfig

5. TFTP/BOOTP -- PXEBoot

In /etc/inetd.conf

  ..

  #:BOOT: Tftp service is provided primarily for booting.  Most sites
  # run this only on machines acting as "boot servers."
  # <service_name>\t<sock_type>\t<proto>\t<flags>\t<user>\t<server_path>\t<args>
  tftp\tdgram\tudp\twait\troot\t/usr/sbin/in.tftpd\t/usr/sbin/in.tftpd -s /var/lib/tftpboot

Note: Replace \t with TAB

Then restart

  # /etc/init.d/inetutils-inetd restart

  # netstat -uap
  Active Internet connections (servers and established)
  Proto Recv-Q Send-Q Local Addr.  Foreign Addr.  State  PID/Prog. name
  udp   0      0                                         *:tftp

In /etc/dhcp/dhcpd.conf

  ...
          option routers 172.16.0.1;
          filename "pxelinux.0";
          next-server 172.16.0.1;
  }

where next-server is IP of our PXE server.

Then restart

  # /etc/init.d/isc-dhcp-server restart

Check tftpd is running

  # netstat -uap
  ..
  udp6    0   0    [::]:tftp    [::]:*    7226/in.tftpd
  ..

Contents of the /var/lib/tftpboot

  -rw-r--r--  1 root root     116520 янв.  17 20:40 ldlinux.c32
  -rw-r--r--  1 root root      25372 янв.  17 20:36 memdisk
  -rw-r--r--  1 root root      42960 янв.  17 19:19 pxelinux.0
  -rw-r--r--  1 root root    1474560 нояб. 18  1999 winbanana.ima
  drwxr-xr-x  2 root root       4096 янв.  17 20:36 pxelinux.cfg

where

  winbanana.ima, mini.iso, systemrescuecd.iso can be found on PXEData-32GB.vdi supplemental disk. Try more images from https://www.turnkeylinux.org/

  cp /usr/lib/syslinux/modules/bios/ldlinux.c32 .
  cp /usr/lib/syslinux/memdisk .

  # bootdisk.com
  wget -c http://1gighost.com/ed/jamiephiladelphia/boot95b.exe
  unzip boot95b.exe
  rm boot95b.exe

  output: winb95b.IMA

  cp /usr/lib/PXELINUX/pxelinux.0 .
  mkdir /var/lib/tftpboot/pxelinux.cfg
  cat /var/lib/tftpboot/pxelinux.cfg/default

  output:

  default memdisk initrd=winb95b.IMA

  # ufw allow proto udp from 172.16.0.0/24 to any port 69
  # cat /etc/ufw/user.rules | grep 69

  output:

  ### tuple ### allow udp 69 0.0.0.0/0 any 172.16.0.0/24 in
  -A ufw-user-input -p udp --dport 69 -s 172.16.0.0/24 -j ACCEPT

Now in Oracle VM VirtualBox Manager (for slave machine).

   System -> Boot Order
   [v] Network

  NB! Use PCnet-FAST III (Am 79C973) as NIC2 (172.16.0.1)
  *******************************************************

Boot.

  Notes mini.iso                       succeeded
  ----- systemrescuecd-x86-4.8.1.iso   succeeded after isohybrid

6. SSH hole in UFW

  sudo ufw allow ssh

Now from slave machine (virtualbox internal network)

  ssh -l virtu 172.16.0.1

7. UTF-8 with signature: \0357\0273\0277
   cat utf8 index.html > u.html
   http://localhost:8080/u.html
   cat phptest.php
   <html>
     <head>
       <title>PHP Test</title>
     </head>
     <body>
       <?php phpinfo(); ?>
     </body>
   </html>


Links
-----

0. Troubleshooting TFTP

    http://www.ing.iac.es/~docs/external/realport/ps-xxxx-tsht-tftp.html

1. Buffalo tftp boot image recovery software

    http://forums.buffalotech.com/index.php?topic=10185.0

2. Setting Up NFS HowTo

    https://help.ubuntu.com/community/SettingUpNFSHowTo

3. https://www.digitalocean.com/community/tutorials
         /how-to-install-puppet-to-manage-your-server-infrastructure

4. http://www.thegeekstuff.com/2015/07/puppet-configuration-examples/


Annex A. Troubleshooting TFTP
-----------------------------

  http://www.ing.iac.es/~docs/external/realport/ps-xxxx-tsht-tftp.html

Use this procedure to verify that TFTP is working correctly on your UNIX host. This procedure is only valid on a UNIX system.

Procedure

  1. Access a root prompt on the UNIX host.

  2. Make sure that you are not in the /tftpboot directory.

    Enter this command (where ipaddress is the IP address of the UNIX host. A TFTP prompt should appear):

      tftp ipaddress

  3. Enter this command at the TFTP prompt (where tftp_file_name is the name of the PortServer boot image in the /tftpboot directory):

      tftp > get tftp_file_name

  + This message appears: received [number] bytes in [number] seconds / Continue to step 6 of this procedure.

  + An error message appears / Skip to step 7 of this procedure.

  5. Enter this command at the TFTP prompt to exit TFTP:

      tftp> quit

  6. Compare the size of the original file against the transferred file using this command:

    ls -l tftp_file_name /tftpboot/tftp_file_name

  + The file sizes match / TFTP is working correctly. Exit this procedure and continue troubleshooting.

  + The file sizes do not match. / Continue to the next step in this procedure.

  7. Verify that the /tftpboot directory exists and has read, write and execute (777) permissions with this command:

      ls -l /tftpboot

  + If necessary, use this command to create the directory:

      mkdir /tftpboot

  + If necessary, use this command to change permissions of the directory to read, write and execute:

      chmod 777 /tftpboot

  8. Verify that the file /tftpboot/ftp_file_name exists and has read and execute permissions with this command (where ftp_file_name is the name of the firmware boot image specified by the PortServer):

      ls -l /tftpboot/ftp_file_name

  + If necessary, use this command to change permissions of the file to read and execute:

      chmod 666 /tftpboot/ftp_file_name

  9. Verify that the inetd.conf file is properly configured for tftp by displaying the file /etc/inetd.conf.

  + An entry similar to this should be uncommented (where something will vary with each operating system):

      tftp dgram udp something

  + For controlled TFTP access, make sure that the file /etc/tftpaccess.ctl exists and verify that it only allows access to public directories. If this file is not present, tftp will allow full access. A sample file is located in the directory /usr/lpp/tcpip/samples.

  10. Restart the inetd process with these two commands:

       ps -ef | grep inetd

     This will report back the inetd process number (Where inetd_PID is the process number for the inetd process reported by the previous command)

       kill -1 inetd_PID

  11. Test TFTP by repeating steps 1-7.

  12. If successful, reboot the PortServer.

  13. Choose Back to return to and continue with the Master Troubleshooting Process.

