Introduction: Raspberry Pi at Work: Serial Console Server

It is some time passed the last (modern) Millennium. We are now in the age of "Cloud Computing" yet there are still those who staff 24/7 Data Centers...... Where Inevitably"Legacy Systems" Lurk , running some forgotten but critical applications on hardware systems passed their prime.

.
These systems steadily hum along in the dark and dusty remote reaches of Data Centers HAUNTINGoperations staff; because no one truly knows the current status or utilization of such systems and even less is known about who set them up or how to support them in the event of a failure.... as no one gets many calls about them they are out of sight and out of mind..... UNTIL SOMETHING FAILS!!!!!!

.

WHAT HAPPENS IF THEY DO FAIL?

Such systems likely have no "Network Management" or Graphics cards.... in fact, this is in the case with Legacy UNIX systems the "Serial Console" is likely the only way to access or operate them in an emergency.

.

If youfind that you need to get give yourself or someone else (out of band) remote access to a "Legacy System" that has no modern “Network Management” capabilities consider using a Raspberry Pi.

.

Not only is it a neat toy but it may, in fact, fill a need you did not know you had.

.

Something else you may enjoy:

https://www.instructables.com/id/Pi-Power-Remote-Power-Management-with-Pi

Step 1: PARTS

We will use a USB to TTL cable to both power and access the Pi as a headless Linux computer. The following steps will show how to setup “ARCH Linux” as a (Headless) “Pocket Serial Console Server” that can be used to access "Legacy Systems" anywhere in the Data Center.

.

Yes indeed, the Pi can be powered from just about any powered USB source...... so, you can use an (optional) battery pack or a powered USB port from any device or server to run a Pi.

.

ITEM LIST:

-Raspberry Pi

-Raspberry Pi Case

-USB to TTL Cable (Careful, some of these can have counterfeit chip sets and may not work correctly)

-USB to Serial Cable (Careful, some of these can have counterfeit chip sets and may not work correctly)

-SD Card (Careful, not all SD cards, “or revisions of prior working cards”, are Pi compatible.)

-Micro USB Wifi Adapter (Careful, not all adapters work with every Pi operating system; sometimes you need drivers)

-Null-Modem Serial Cable

http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=raspberry+pi&rh=i%3Aaps%2Ck%3Araspberry+pi
http://www.amazon.com/Raspberry-Pi-Case-Enclosure-Black/dp/B00AZL16S4/ref=sr_1_3?s=pc&ie=UTF8&qid=1415975409&sr=1-3&keywords=raspberry+pi+case

http://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias%3Delectronics&field-keywords=usb%20to%20ttl

http://www.amazon.com/s/ref=sr_kk_3?rh=i%3Aaps%2Ck%3Ausb+to+serial&keywords=usb+to+serial&ie=UTF8&qid=1415975655

http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=SanDisk%20Ultra%20UHI-1%20SDXC

http://www.amazon.com/Edimax-EW-7811Un-150Mbps-Raspberry-Supports/dp/B003MTTJOY/ref=sr_1_16?s=electronics&ie=UTF8&qid=1415975511&sr=1-16&keywords=raspberry+pi

http://www.amazon.com/s/ref=nb_sb_ss_i_1_10?url=search-alias%3Daps&field-keywords=null+modem+cable+&rh=i%3Aaps%2Ck%3Anull+modem+cable+


Optional:
-External Smart Phone Battery Pack/Charger

http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=smartphone+batter+pack+&rh=i%3Aaps%2Ck%3Asmartphone+batter+pack+

Step 2: LOAD YOUR OPERATING SYSTEM

Put the SD card in your Linux system; sorry, no instructions for Windows systems at this time.....

.

[[ PREP SD CARD]]

#You will need to be SUPER USER(root) to do this....
sudo -s

.

#ONE LINE FORMAT OF SD CARD (Careful, make sure this is the right device)

fdisk -l

fdisk -l /dev/mmcblk0

echo -e "p\no\np\nn\np\n1\n\n+100M\nt\nc\np\nn\np\n2\n\n\np\nw" | fdisk /dev/mmcblk0 #ONELINE

fdisk -l /dev/mmcblk0

.

## SETUP FILESYSTEMS

##

fdisk -l

fdisk -l /dev/mmcblk0

mkfs.vfat /dev/mmcblk0p1

mkdir -p /tmp/boot

mount /dev/mmcblk0p1 /tmp/boot

df -h

mkfs.ext4 /dev/mmcblk0p2

mkdir -p /tmp/root

mount /dev/mmcblk0p2 /tmp/root

df -h

.

.

[[ ARCHlinux: Raspberry Pi (Install OS) ]]

.

#You will need to be SUPER USER(root) to do this....

sudo -s

.

## GET ARCH LINUX OS FOR YOUR PI

##

mkdir -p ~/ARCHlinux

cd ~/ARCHlinux

wget http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz

.

## COPY OS TO SD CARD

cd ~/ARCHlinux

gzip -dc ArchLinuxARM-rpi-latest.tar.gz | (cd /tmp/root; tar -xvf - )

df -h

(ls -al /tmp/root/boot; cp /tmp/root/boot/* /tmp/boot; rm -rf /tmp/root/boot/*; ls -al /tmp/root/boot) #ONELINE

ls -al /tmp/boot

df -h

umount /tmp/boot

umount /tmp/root

df -h

Step 3: THE CASE

This is the Pi case.

Step 4: LOAD THE CARD

Let's add the SD card with the OS.

Step 5: PLUGIN THE USB TO TTL

This is the proper pin out for connecting my "USB to TTL" cable to the Pi...... Beware, as the wrong connections here could destroy something.


NOTE: The "colors" and functions for your cable may vary from mine; so, please refer to the documentation for your "USB to TTL" cable.... or risk it.... it's what I did. .....but as results will vary; perhaps, it is best use a multimeter to check for such things as power. Of course, my multimeter battery was dead at the time so I just went for it. ;)

http://elinux.org/File:GPIOs.png

Step 6: MAKE SOME HOLES

I drilled a hole in the back of the case; because, I thought it looked nice and it was near the GPIO pins..... tied the inside and use electrical tape on the outside to make it look nice..... and it stops the wire from sliding in or being ripped out.

Step 7: CLOSE

Closed it up.

Step 8: HEADLESS

OMG, It's headless!!!

Once we close up our Pi, we can both power and access it via the USB end of the USB to TTL cable..... let's hope we wired it correctly!

.

#BOOT IT
Insert the SD card into the Raspberry Pi and use the serial console from the USB to TTL while plugged in to your LINUX system. The default root password is 'root'.

.

[[ SERIAL CONSOLE (to Pi) ]]

use your favourite serialterminal command while your have your Pi plugged into you Linux System via USB.

http://www.computerhope.com/unix/ucu.htm

http://www.gnu.org/software/screen/manual/screen.html

[root@localhost ]# dmesg | grep -i tty

[ 0.000000] console [tty0] enabled

[ 19.385214] Bluetooth: RFCOMM TTY layer initialized

[37694.944976] usb 2-1.2: pl2303 converter now attached to ttyUSB0

[root@localhost ]#

.

#ATTACH TO (Pi) SERIAL CONSOLE FROM LINUX

dmesg | grep -i tty

sudo cu -l /dev/ttyUSB0 -s 115200

sudo screen /dev/ttyUSB0 115200

.

#NOTE: RECORD MAC ADDRESS (we are going to need this later)

ifconfig -a

poweroff

.

[root@alarmpi ~]# ifconfig -a | grep -i ether
eth0: flags=4099 mtu 1500 ether c8:27:cb:b0:76:89 txqueuelen 1000 (Ethernet)

wlan0: flags=4098 mtu 1500 ether 00:28:2f:38:9c:88 txqueuelen 1000 (Ethernet)

[root@alarmpi ~]#

.

#NOTE: Yes the Mac Address can also sometimes be found printed on the device.... such as on the USB Wifi Adapter..... it was just as easy to do it from here as we had to "test" boot it.

Step 9: Wait, Can I Get to the "Serial Console" of My Pi From Windows?

Yes you can, you only need to install something like "Putty" and add the correct drivers for the chip set in your "USB to TTL" cable......

.

#As I plug in the USB end of the "USB to TTL" cable into my Linux system and run a few commands it turns out my adapter is using a "Prolific Technology, Inc. PL2303 Chip".

[oem@localhost ]$ dmesg | grep -i detec

[68930.101474] pl2303 2-1.2:1.0: pl2303 converter detected

[oem@localhost ]$

[oem@localhost ]$ lsusb

Bus 002 Device 004: ID 0a5c:5800 Broadcom Corp. BCM5880 Secure Applications Processor

Bus 002 Device 003: ID 8087:07da Intel Corp.

Bus 002 Device 014: ID 045e:0745 Microsoft Corp. Nano Transceiver v1.0 for Bluetooth

Bus 002 Device 015: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 001 Device 004: ID 1bcf:2804 Sunplus Innovation Technology Inc.

Bus 001 Device 003: ID 413c:8187 Dell Computer Corp. DW375 Bluetooth Module

Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

[oem@localhost ]$

.

#DOWNLOAD AND INSTALL THE DRIVERS FOR THE WINDOWS SYSTEM

http://www.prolific.com.tw/us/showproduct.aspx?p_id=225&pcid=41

.

#DOWNLAND AND INSTALL PUTTY FOR THE WINDOWS SYSTEM

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

.

#FIND THE COM PORT ON THE WINDOWS

You can click around in the "Device Manager".....

mmc devmgmt.msc

.......or just use the command line querying the "Windows Registry".

reg query HKLM\HARDWARE\DEVICEMAP\SERIALCOMM | find "REG"

.

#USE PUTTY TO OPEN A SERIAL CONNECTION TO THE PI
C:\>reg query HKLM\HARDWARE\DEVICEMAP\SERIALCOMM | find "REG"

\Device\ProlificSerial0 REG_SZ COM4

C:\>

putty -serial com4 -sercfg 115200,8,n,1,n

.

#NOTE: It is basically the same as with the "cu" command on Linux.

http://linux.die.net/man/1/putty

Step 10: GOT DRIVERS?

NO DRIVERS?

As it turns out the ARCH Linux install did not (by default) have the drivers needed for the Micro USB WIFI Adapter I have. (Edimax EW-7811Un) ...but it turned out to be a popular Realtek chip set so I install the drivers by using the wired (Ethernet) connection on the Pi while attaching it to my wired network...... This time I used the optional USB battery pack...

#NOTE: It was online for over 3 hours as played around shortly after I got the wireless network setup and it seemed to only have used 3/4 of the battery; not bad. ;)

.

[root@alarmpi ~]# lsusb
Bus 001 Device 004: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]

Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter

Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. SMC9512/9514 USB Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

[root@alarmpi ~]#

Step 11: WIRE IT UP

If your wireless router has a powered USB port (as seen here) the Pi can run on your network just as it is intended to do in the Data Center attached to a server's USB port..... perhaps I will leave a Pi on the network as a small server....... (I did so) perhaps more on this some other time. ;)

Step 12: (DUDE) WHERE'S MY Pi?

After you get it connected to the network you need to access it and if your home router is working correctly it will give the Pi an IP address and add the default host name "alarmpi" to DNS.

.

You can simply access it from your Linux system via the name:

ssh root@alarmpi

.

If not, no worries, as we can use the Mac Address to find the IP on the network using "ping" and "arp"; this works if you are on a computer that shares the same broadcast domain as the Pi.... most at home wireless routers should allow this.

http://en.wikipedia.org/wiki/Broadcast_domain

.

[[ FIND PI ON NETWORK ]]
Remember that Mac Address info we saved; we are going to need it now....

.

##FROM YOUR LINUX SYSTEM YOU CAN RUN THIS TO LOCATE THE PI VIA THE MACADDR

##

FIRST_3_OCTS = IP: 8 bits (octet) [[ #1. #2 . #3 . #4]]

YOUR_NIC = Your "Network Interface" in the same network as the Pi

MACADDR = the "Mac Address" of your Pi

.

for i in $(seq 254); do ping -c 1 {FIRST_3_OCTS}.$i -W 2 -I {YOUR_NIC} > /dev/null 2>&1; arp -a | grep -i "{MACADDR}" && break; done #ONELINE

#NOTE: Adjust wait time (-W 2) higher if you do not find your PI.

.

#EXAMPLE
for i in $(seq 254); do ping -c 1 192.168.0.$i -W 2 -I wlp2s0 > /dev/null 2>&1; arp -a | grep -i "00:28:2f:38:9c:88" && break; done #ONELINE

#NOTE: You can watch the progression in another terminal; else, grab a snack.
while :; do sleep 2; ps -ef | grep -i ping; done

.

Depending on how slow your network connection is, you will soon have the IP address for your Pi displayed when the command completes.

alarmpi (192.168.0.141) at 00:28:2f:38:9c:88 [ether] on wlp2s0

.

You can now use the IP address to login to your Pi:

ssh root@192.168.0.141

Step 13: PACMAN?

Now that we have access to the Pi we need to initialize the ARCH Linux package manager......

https://wiki.archlinux.org/index.php/pacman-key


[[ SETUP PACMAN / UPDATE THE PI]]

#Initializing the keyring

nohup pacman-key --init &
time while (ps -ef | grep -iv grep | grep -iw pacman-key); do echo LOOP; (ls -R / > /dev/null 2>&1 &); sleep 5; done #ONELINE

jobs

.

#UPDATE Pi, reboot

(echo y; echo y) | pacman -Syu && reboot

.

After reboot we should have complete access to the ARCH Linux package repository; thus, we can find a install our drivers.

Step 14: ARCH LINUX?

It many seem like a lot of work but ARCH Linux is a nice Linux Distro for the Pi as you install it only once and never need to do any upgrades.

.

Arch Linux uses a "rolling release" system which allows one-time installation and perpetual software upgrades. It is not generally necessary to reinstall or upgrade your Arch Linux system from one "version" to the next. By issuing one command, an Arch system is kept up-to-date and on the bleeding edge.

https://www.archlinux.org/about/

.

Besides this, it is very well documented and supported by an active community.

https://wiki.archlinux.org/

Step 15: Pi WIFI (WPA/WPA-EAP)

Now let us get the WiFi setup so we can access our Pi on over the air.

.

[[ ARCH Linux WIFI (EdiMAX) / Raspberry Pi ]]

## INSTALL NIC DRIVER/WIFI SOFTWARE

##

#Update the OS and reboot if we have not already done so

echo y | pacman -Syu

reboot

.

#INSTALL THE DRIVER AND WFI TOOLS

echo y | pacman -Sy wireless_tools

echo y | pacman -Sy iw

echo y | pacman -Sy wpa_supplicant

echo y | pacman -Sy wpa_actiond

(echo; echo y) | pacman -Sy dkms-8192cu

.

## TEST DRIVER
##

lsusb

dmesg | grep -i driver

dmesg | grep -i interface

dmesg | grep firmware

dmesg | grep iwlwifi

lsmod

modprobe 8192cu

lsmod

.

## TEST DEVICE
##

ip link

ip link set wlan0 up

#OR

ip link set dev wlan0 up

#OR

ifconfig -a

ifconfig wlan0 up

#now

iwlist wlan0 scan

#Here you should see some broadcasting SSID(s) around you..

.

## MAKE HASH FOR WPA
##

wpa_passphrase HOME-SSID
#TYPE PASSWORD IN BLANK SCREEN (STIN)

#OUTPUT

network={

ssid="HOME-SSID"

#psk="fjfjdifjdf"

psk=5049231d192d9273cadb686299dabed1481ee984dcf28a3cb3679659476cdaf4

}

#SAVE THE PSK

psk=5049231d192d9273cadb686299dabed1481ee984dcf28a3cb3679659476cdaf4

.

## MAKE HASH FOR WPA-EAP
##

echo y | pacman -Sy openssl

pkgfile -s iconv

echo y | pacman -Sy glibc

echo -n YOUR_DOMAIN_PASSWORD | iconv -t utf16le | openssl md4

#OUTPUT

(stdin)= a949b4053abaf36398f442fb2286e426

password=hash:ADD_YOUR_HASH_HERE

#SAVE LIKE SO

password=hash:a949b4053abaf36398f442fb2286e426

.

## SETUP WPA
##

.

#Make a test WPA supplicant file.

vi wpa.conf

fast_reauth=0

ap_scan=1

network={

id_str="HOME"

proto=RSN

scan_ssid=1

key_mgmt=WPA-PSK

pairwise=CCMP TKIP

group=CCMP TKIP

ssid="HOME-SSID"

psk=a0b1cd4fe9c7be0c633535dec0b50305381a985458dc0fa9b53f3946ca988c78

}

network={

id_str="WORK"

ssid="CORP-SSID"

scan_ssid=1

key_mgmt=WPA-EAP

eap=PEAP

pairwise=CCMP TKIP

group=CCMP TKIP

# authentification info

identity="YOUR-DOMAIN-ID"

password=hash:a949b4053abaf36398f442fb2286e426

phase1="peaplabel=0"

phase1="auth=MSCHAPV2"

}

#EOF

.

## TEST_CONFIG
##

ifconfig wlan0 up

wpa_supplicant -Dwext -i wlan0 -c wpa.conf

.

#[GOOD OUTPUT]

wlan0: Trying to associate with 35:c8:04:b1:2g:10 (SSID='HOME-SSID' freq=2412 MHz)

wlan0: Association request to the driver failed

wlan0: Associated with 35:c8:04:[ 1209.286850] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

wlan0: WPA: Key negotiation completed with 35:c8:04:b1:2g:10 [PTK=CCMP GTK=TKIP]

wlan0: CTRL-EVENT-CONNECTED - Connection to 35:c8:04:b1:2g:10 completed [id=0 id_str=]

# TYPE "ctrl-C"

.

## MANUAL RUN
##

#We now copy the working config over to the correct location....

cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf-org

cp wpa.conf /etc/wpa_supplicant/wpa_supplicant.conf

.

#As we have a tested WPA config we can skip the test below....

ip link set dev wlan0 up

wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf

iwconfig

ifconfig

dhcpcd wlan0

ifconfig

nslookup cnn.com

telnet google.com 80

get /

.

#Run Updates

(echo y; echo y) | pacman -Syyu

.

## AUTO RUN WIFI(WPA) AT BOOT [systemctl]

##

#In ARCH Linux the Wifi Service is not setup be default we will need to do that now.

vi /etc/systemd/system/network-wireless@.service

[Unit]

Description=Wireless network connectivity (%i)

Wants=network.target

Before=network.target

BindsTo=sys-subsystem-net-devices-%i.device

After=sys-subsystem-net-devices-%i.device

[Service]

Type=oneshot

RemainAfterExit=yes

ExecStart=/usr/bin/ip link set dev wlan0 up

ExecStart=/usr/bin/wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf

ExecStart=/usr/bin/dhcpcd wlan0

ExecStop=/usr/bin/ip link set dev wlan0 down

[Install]

WantedBy=multi-user.target

#EOF

.

## INIT SERVICE (AFTER EVERY EDIT)

##

systemctl enable network-wireless@wlan0.service

systemctl start network-wireless@wlan0.service

.

[[ DONE WITH THE OS/WIFI SETUP! ]]

As we are done with the wifi setup... we can remove the Ethernet cable and use the wifi from now on....

Step 16: SERIAL CONNECTION

We now have a working headless Pi available over the wifi network; so, we can just plug it in and use it anywhere. Now we can add the USB to serial adapter and a Null Modem cable so we can use this Pi as a Serial Console Server.

.

[[ ADD SERIAL CONNECTION SOFTWARE TO THE Pi ]]

#We will need to add the serial control software, like so:

echo -y | pacman -Sy pkgfile
pacman -Sy pkgfile

pkgfile --update

pkgfile -s cu

echo y | pacman -Sy uucp

#ONELINE

dmesg | grep tty

ls -l /dev/ttyUSB0

.

[[ THE CONNECTION ]]

Remotely Accessing the PI with the business end of the NULL-Modem attached to a server's serial console and you've got yourself a Pocket Sized Serial Console server that you can take with you anywhere or ship out to remote sites.


## USE SERIAL CONSOLE

cu -l /dev/ttyUSB0 -s 19200

.

#QUIT Serial session: ~.

.

#Bit rates commonly supported include 75, 110, 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600 and 115200

cu -l /dev/ttyUSB0 -s 9600

cu -l /dev/ttyUSB0 -s 19200

cu -l /dev/ttyUSB0 -s 115200

#One of these bit rate will likely for for you; you just need to type "~." to stop the serial session.

http://en.wikipedia.org/wiki/Serial_port

http://linux.die.net/man/1/cu

Step 17: REFERENCE CONFIGURATIONS

These are some examples of "Serial Null Modem" configurations using adapters provided by various manufactures; while it is best to use a true Null-Modem cable sometimes you will find that a combination of (Rj45 to DB9/DB25) adapters also works.

Step 18: IN THE DATA CENTER

Example of a serial connection to a server's serial console in the Data Center...

Step 19: Windows Control Via Serial

Did you know that control via Serial Console Connections are not just limited to UNIX/LINUX? A serial control connection can also be use on Windows Servers as well.......


Someone only needs to set the Windows "Boot Parameters" to "Enable EMS Redirection" and windows will respond to a serial connection.

Yes, those "Legacy Windows Servers" without Network Management Consoles can also talk to the Pi Serial Console Server.;)

.

The following Bootcfg command enables EMS console redirection on the first boot entry in the list. It sets the port for COM2 and sets the transmission rate to 115,200 kilobits per second (Kbps). So you can also use the Pi for out-of-band administration windows servers via the serial port.

bootcfg /ems ON /port COM2 /baud 115200 /id 1

http://en.wikipedia.org/wiki/Emergency_Management_Services


Step 20: CREDITS

[[ Intro Image Info ]]

I modified an image I found that claimed to be "Attribution-NonCommercial-ShareAlike 2.0 Generic
(CC BY-NC-SA 2.0)" Licence...


Data centre panorama by: ~Bob~West~

http://www.photoree.com/photos/permalink/9993530-38176485@N08

http://creativecommons.org/licenses/by-nc-sa/2.0/

http://en.wikipedia.org/wiki/File:Raspberry_Pi_Logo.svg