Headless Pi
This is detailed 'recipe' (with bad puns!) for getting a Raspberry Pi 3 displaying, out-of-the-box, via PuTTY and Xming on Windows. The method described is headless (the Pi needs no keyboard, mouse or TV/monitor connected to perform it) but it's not compulsory to be so . This is just a convenient method to make some simple file changes (that I use) with only a network cable and micro USB power connected to the Pi.The method uses a Linux computer for setting the Raspbian image on the microSD card (Raspbian changes shown here could just be deferred on a headed Pi). You need the Pi, not yet powered-up, connected to your network plus a SD card + USB adapter; the latter just for interfacing the SD card to the Linux computer if it has no SD card slot.
Note: for this example method the network (192.168.0.0) has connected: a Windows computer (with PuTTY and Xming installed), raspberrypi (will be set to 192.168.0.6) and an internet gateway machine/firewall/router (192.168.0.15). A Linux computer is also needed, but it does not have to be on the 192.168.0.0 network. You will have to adapt things to suit your configuration.
Some of the window captures below may not exactly match what you now see with the latest Raspbian "jessie" (with PIXEL) image.
Pi&bash
Download, copy to microSD memory and customise the Raspbian "jessie" image.Note: commands shown ($ 'command') in this section are for the Linux computer.
- Download Raspbian "jessie" 2017-04-10-raspbian-jessie.zip to, for example, a Linux computer directory /scratch (the zip is a 1.45GB download and the extracted image, for the microSD card, is 4.18GB). Note: the microSD card needs to be 8GB or larger and not partitioned.
$ cd /scratch $ sha1sum 2017-04-10-raspbian-jessie.zip 6d7b11bb3d64524203edf6c80c499456fb5fef53 2017-04-10-raspbian-jessie.zip $ unzip 2017-04-10-raspbian-jessie.zip Archive: 2017-04-10-raspbian-jessie.zip inflating: 2017-04-10-raspbian-jessie.img
- Plug your microSD/adapter into the Linux computer (best to reformat the SD card first). Find the device that is your SD card
$ fdisk -l ... Device Boot Start End Blocks Id System /dev/sdc1 8192 62333951 31162880 c W95 FAT32 (LBA)
shows a /dev/sdc1 partition, for me, and a 32GB card (but check really carefully you get the right device + the SD card is about to be imaged and all its original contents lost!)$ umount /dev/sdc1 umount: /dev/sdc1: not mounted
just in case it is mounted and copy the image to the SD card (takes a while, go and put the kettle on)$ dd bs=4M if=2017-04-10-raspbian-jessie.img of=/dev/sdc 1021+1 records in 1021+1 records out 4285005824 bytes (4.3 GB) copied, 322.809 s, 13.3 MB/s
Note: use of device: /dev/sdc, not the first partition on the device: /dev/sdc1.
$ sync
to flush system buffers before removing the SD/adapter.
- You can see the Raspbian partitions on the SD card
$ parted -l ... Model: TS-RDF5 SD Transcend (scsi) Disk /dev/sdc: 31.9GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 4194kB 47.2MB 43.0MB primary fat32 lba 2 47.2MB 4285MB 4238MB primary ext4
Note: you now have two partitions, the first '/boot' and the second '/', for the Raspbian file system.
- Unplug the SD/adapter and plug it back in again. The new partition will not mount if you don't do this.
- Mount partition /dev/sdc2 and go to the location of the files to be changed
$ mkdir /media/external if the directory /media/external does not exist $ mount -t ext4 /dev/sdc2 /media/external $ cd /media/external/etc
I'm going to set the interface on the Pi to be static address: 192.168.0.6, and the internet gateway: 192.168.0.15. First edit file 'dhcpcd.conf' (file changes are show in unified format: 'diff -u')$ diff -u save_dhcpcd.conf dhcpcd.conf --- save_dhcpcd.conf 2015-10-17 01:22:18.000000000 +0100 +++ dhcpcd.conf 2017-04-30 15:07:14.898336724 +0100 @@ -39,3 +39,9 @@ # A hook script is provided to lookup the hostname if not set by the DHCP # server, but it should not be run by default. nohook lookup-hostname + +# My additions to end of file +interface eth0 +static ip_address=192.168.0.6/24 +static routers=192.168.0.15 +static domain_name_servers=192.168.0.15
Correct the host address in file 'hosts'$ diff -u save_hosts hosts --- save_hosts 2017-04-10 10:17:22.408000000 +0100 +++ hosts 2017-04-30 13:58:12.148570828 +0100 @@ -3,4 +3,4 @@ ff02::1 ip6-allnodes ff02::2 ip6-allrouters -127.0.1.1 raspberrypi +192.168.0.6 raspberrypi
Get out of the mounted partition and dismount it$ cd $ umount /media/external
- Enable the ssh server (it's disabled by default) by mounting the '/boot' partition and creating an empty file 'ssh'.
$ mount -t vfat -o umask=000 /dev/sdc1 /media/external $ cd /media/external
check that '/boot' partition is mounted e.g. use 'ls' to view files$ touch ssh
Note: file 'ssh' will not persist after the Pi boots.Get out of the mounted partition and dismount it
$ cd $ umount /media/external
Eureka
Transfer the SD card to the Pi and power it up. It should boot and be able to respond to ping and service SSH requests.
$ ping 192.168.0.6Ping should respond on the Pi itself and elsewhere on the network (and where named to: raspberrypi).
Raspberry blown?
If you have a problem, or get one later, you can move the SD card back to the Linux computer, mount partition 2 again and examine the logs in directory /media/external/var/logI clean SD cards with the official SD Association formatter, before reusing them, as it removes any partitions automatically.
PiSSH
Use PuTTY to login to the Pi remotely via SSH, configure and update Raspbian OS, and prepare for use with XDMCP and X-Forwarding.Note: commands shown ($ 'command') in this section are for your Pi via PuTTY on Windows.
- Run PuTTY.exe on your Windows computer.
Enter the address of raspberrypi (192.168.0.6 in this case), set/check the remote character set is UTF-8 and click 'Open'.
Click 'Yes' to the PuTTY Security Alert...we do trust this host!
- At the PuTTY terminal prompt respond pi to 'login as:'
and raspberry to 'pi@192.168.0.6's password:'
You should now have a command line terminal for pi@raspberrypi:~
Enter: sudo raspi-configSecurity note: you really should change the default password for the 'pi' user if you are using a public network.
You need to '1 Change User Password, set '3 Boot Options' ('B1 Desktop / CLI' and 'B1 Console'), check/set '4 Localisation Options', run '7 Advanced Options' ('A1 Expand Filesystem') and run '8 Update'. Note: the default locale is for the UK. Re-run raspi-config again anytime you want to change these options and, if asked, allow the Pi to reboot.
- You should be on the internet (via your gateway) so do a full upgrade
$ sudo apt-get update $ sudo apt-get dist-upgrade
Go make coffee...upgrade may take some time!You don't want all that login spam again (you don't get it anyway with user 'root'!) and a reboot is now needed
$ touch .hushlogin $ sudo shutdown -r now
Your PuTTY terminal will disconnect, so close it, wait a while and reconnect with PuTTY when the Pi has booted (use ping to check it's up).
- Log back in to the PuTTY terminal for user pi.
Give root a password and remember it (optional...it's your Pi...you can reload the image yourself if you destroy it...plus you don't want to keep typing sudo to do useful work!)$ sudo passwd root
But I suggest you add (or enable) some aliases in ~/.bashrc for both user pi and root to protect yourself a little.--- save_.bashrc 2017-04-10 10:17:21.792000000 +0100 +++ .bashrc 2017-05-01 14:37:31.623067949 +0100 @@ -92,6 +92,10 @@ #alias la='ls -A' #alias l='ls -CF' +alias rm='rm -i' +alias cp='cp -i' +alias mv='mv -i' + # Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly.
Note: root has slightly different contents, in .bashrc, to that above.
- Become super user root
$ su -
login and install package xdm$ apt-get install xdm
this runsdpkg-reconfigure xdm
as part of the install and displays
choose xdm as the default display manager.
- In /etc/X11/xdm change two files to allow remote access (so please be careful who can 'sniff' traffic on your network)
--- save_xdm-config 2012-04-29 22:19:04.000000000 +0100 +++ xdm-config 2017-05-01 16:40:01.692633915 +0100 @@ -33,4 +33,4 @@ ! SECURITY: do not listen for XDMCP or Chooser requests ! Comment out this line if you want to manage X terminals with xdm -DisplayManager.requestPort: 0 +! DisplayManager.requestPort: 0
and--- save_Xaccess 2012-04-29 22:19:04.000000000 +0100 +++ Xaccess 2017-05-01 16:42:12.422633865 +0100 @@ -43,7 +43,7 @@ # right hand sides can match. # -#* #any host can get a login window +* #any host can get a login window # # To hardwire a specific terminal to a specific host, you can
- Start xdm and install packages x11-apps and midori (both installs are optional, I just use them for testing and midori is not the best browser for a Pi!)
$ service xdm start $ apt-get install x11-apps $ apt-get install midori
Create a ~/.Xdefaults file for users pi and root, containing one line (to display x11-apps in colour)*customization:-color
Add the following to file /etc/pam.d/su to forward xauth keys between userssession optional pam_xauth.so
Make sure XDMCP is listening on port 177/udp$ netstat -ulnp | grep 177 udp6 0 0 :::177 :::* 1577/xdm
i.e. if you see udp, 177 and xdm you're good.
PiXming
Xming in now able to interact with the Pi in a number of ways.- XDMCP mode
On your Windows computer runXming :1 -query 192.168.0.6
or why not try out some of Xming's options?Xming :1 -query raspberrypi -clipboard -wgl -once -screen 0 1280x720+100+100@1
Logging in via Debian jessie's xdm greater
this 'Welcome to raspberrypi' login also appears when headed
The desktop displaying some of the X11-apps you installed earlier.
Logout the LXDE (Lightweight X11 Desktop Environment) session properly from the Task Bar (LXPanel) when finished.
- X-Forwarding
Start an Xming multiwindow mode serverXming -multiwindow -clipboard
You have used PuTTY above: time to add settings for SSH X11 forwardingNow click Open and login as 'pi' as before. At the PuTTY terminal type
$ midori or the command to run another graphical application
The Midori browser will display (if it is installed), and interact with the user, on the Windows desktop
- Finally: I recommend you don't use startlxde or lxsession via PuTTY as you can't Logout cleanly and the Pi's resources may be left in unknown states (e.g. processes and files not gracefully flushed, stopped or closed).
Table of contents
The Xming website, documentation and images are licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales License.
Copyright © 2005-2024 Colin Harrison All Rights Reserved