Running Raspberry Pi Headless


31 posts   Page 1 of 2   1, 2
by NerdUno » Mon Aug 27, 2012 8:25 pm
It may not always be convenient to plug a monitor into your Raspberry Pi. But you can still access it with a wired or wireless connection as long as you have a network handing out DHCP addresses and you have a Mac with SSH or PC with Putty nearby.

The wrinkle has been deciphering the IP address of your Raspberry Pi when it boots if you don't have access to the router handing out the DHCP addresses. Here's a quick fix.

As long as you remember to carry along a pair of earbuds, you can get your Raspberry Pi to read out its IP address when it boots. Here's how with Debian:
Code: Select all
apt-get install flite
apt-get install alsa-utils
echo "snd_bcm2835" >> /etc/modules
reboot
amixer cset numid=3 1
cp /etc/rc.local /etc/rc.local.bak
sed -i '$ s|exit 0|/usr/bin/flite /etc/hostip\nexit 0|' /etc/rc.local
reboot

Now plug in those earbuds and give a listen. :ugeek:
User avatar
Posts: 63
Joined: Wed Aug 15, 2012 1:35 pm
by Chris Gage » Mon Aug 27, 2012 8:40 pm
You can also just connect to:
raspberrypi.local
Posts: 4
Joined: Fri Aug 10, 2012 4:13 pm
Location: San Jose CA
by alexeames » Mon Aug 27, 2012 8:44 pm
or you can get the pi to email you the ip address
or you can use nmap
or you can use an android app like Fing, which I discovered yesterday, someone wrote about it in another thread.

Someone else even made a little screen module which runs on the GPIO and displays the ip address.

But having the Pi read to you is kind of nice. Good one Nerduno :D
My Pi uses 2 watts - what what? ---- HiRes early production Pi photos RS Front Back | Farnell Front Back
User avatar
Posts: 2018
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
by bredman » Mon Aug 27, 2012 9:35 pm
It looks like NerdUno logs in as root, these commands will not work for the average user.

Therefore, add the following command BEFORE the list of command above...
sudo -s

This will allow you to enter these commands as if you are a root user. Note you will also need to use sudo -s after the first reboot.
Posts: 1413
Joined: Tue Jan 17, 2012 2:38 pm
by brs » Mon Aug 27, 2012 9:51 pm
Very cool! Compared to that, using mDNS zero-conf networking to advertise the IP address seems rather anti-climactic... ;-) For completeness: if not already there, install avahi (sudo apt-get install avahi-daemon), restart and then ping or ssh raspberrypi.local - or whatever the hostname is.
Posts: 64
Joined: Fri Aug 17, 2012 9:27 pm
Location: Zurich
by NerdUno » Mon Aug 27, 2012 11:53 pm
bredman wrote:It looks like NerdUno logs in as root, these commands will not work for the average user.


Sorry. Shedding our CentOS roots is difficult. :oops:
User avatar
Posts: 63
Joined: Wed Aug 15, 2012 1:35 pm
by argief » Tue Aug 28, 2012 8:47 pm
Seeing as this is turning into a round-up of how to get your raspi ip whilst headless, I have two more to add!

1. To get a static IP address for your pi, you can add the following to your cmdline.txt:
Code: Select all
ip=192.168.0.2::192.168.0.1:255.255.255.0

The line above is a standard kernel parameter, the definition of which is:
Code: Select all
ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>

(You can lookup your local kernel documentation for further details.)

2. From another linux machine, type the following at the command line:
Code: Select all
arp -a

This will show you the IP address to MAC address mapping of all devices on your local network. Though it may well take some trial and error, you are bound to find the right ip for your pi!
Posts: 18
Joined: Sat Aug 18, 2012 6:35 pm
by bredman » Tue Aug 28, 2012 9:09 pm
argief wrote:1. To get a static IP address for your pi, you can add the following to your cmdline.txt:
Code: Select all
ip=192.168.0.2::192.168.0.1:255.255.255.0


This is a great idea, but be careful when selecting your address, you must ensure that you use something suitable for your router, normally one of
192.168.0.x
192.168.1.x
10.10.10.x
Also, make sure that you do not use an address within the dynamic range that is configured in your router.
Posts: 1413
Joined: Tue Jan 17, 2012 2:38 pm
by Lob0426 » Wed Aug 29, 2012 7:34 pm
I use my router. I connected the RasPi. I found its MAC and then set it to give that MAC a static I.P..
Of course this only works if you have control of your router. If your router is supplied by your provider, you may not be able to do this. now I always know where to look.

Forcing the I.P. in command line text is useful as long as you know what the I.P. range is and there is nothing on that I.P. when you connect.

Samba will allow you to look for the RasPi by name within your network.

Listening for your I.P. is interesting solution!
Back-powered 256MB as WordPress Server
Motorola Lapdock with 512MB
Modded Rev 1.0 with pin headers at USB

http://rich1.dyndns.tv/
(RS)Allied ships old stock to reward its Customers for long wait!
User avatar
Posts: 1868
Joined: Fri Aug 05, 2011 4:30 pm
Location: Susanville CA.
by Serac » Wed Aug 29, 2012 9:14 pm
I'm finding ssh access to my Pi to be somewhat slow at times - Press a key, wait 10-30 seconds for a response kinda thing. Running a process in the background to ping the Pi helps to reduce the lag a bit..

Over short distances, I found an RS232 connection to be much faster and reliable with the added bonus of getting to see the kernel boot/crash messages - Valuable information when trying to work out what just blew up with some bleeding [edge] kernel module :lol:
Posts: 124
Joined: Wed Jul 18, 2012 2:49 pm
by Allen » Fri Aug 31, 2012 12:07 pm
argief wrote:2. From another linux machine, type the following at the command line:
Code: Select all
arp -a

This will show you the IP address to MAC address mapping of all devices on your local network. Though it may well take some trial and error, you are bound to find the right ip for your pi!


Err.. this isn't just something that linux has... Windows also allows you to do the same thing.. just fire up a cmd window.
I'm sure you weren't trying to be disingennuous to Windows, but it's always nice to show that Windows does indeed do many things Linux does!
Posts: 3
Joined: Fri Jul 20, 2012 11:44 am
by niftyhacking » Fri Aug 31, 2012 10:39 pm
Serac wrote:I'm finding ssh access to my Pi to be somewhat slow at times - Press a key, wait 10-30 seconds for a response kinda thing. Running a process in the background to ping the Pi helps to reduce the lag a bit..

Over short distances, I found an RS232 connection to be much faster and reliable with the added bonus of getting to see the kernel boot/crash messages - Valuable information when trying to work out what just blew up with some bleeding [edge] kernel module :lol:


The 10-30 second delay is most likely a DNS lookup timing out.
It can be helpful to build local host files (/etc/hosts) that match
names to IP-addresses. ssh does work hard to validate host names
and IP addresses in a number of cases. Timeouts are in seconds
so providing a local host file can speed it up, lots.

IPv6 lookups are quite hit and miss so some will disable IPv6.
Posts: 13
Joined: Thu Jul 19, 2012 8:48 pm
by DominicTurner » Tue Nov 06, 2012 11:39 am
I only had a PC to use and while diagnosing no video output from the pi i was looking at running headless. Some free tools I found useful if you don't have a linux machine to hand.

Scanning Local Network
I found that you can use nmap on a PC and the GUI frontend Zenmap - never used this type of tool before and it was really amazing. Given the subnet to search (e.g. 192.168.0.*) it found all the devices on my local network including the raspberry pi - and showed which ports were there (SSH on the raspberry pi).

nmap for windows: http://nmap.org/download.html#windows

Mounting Raspberry Pi SD Card in Windows
To edit files in the raspberry pi root filesystem you just need to mount the partition - this isn't straightforward in windows but I came across this tool which allows you to do exactly that. This is vital if you want to adjust configuration files to run the raspberry pi headless but don't have a linux box to mount the SD card on.

linux_reader: http://www.diskinternals.com/linux-reader/

In the end, after swapping HDMI cables and monitors, the problem turned out to be something wrong with the SD card image. When I reflashed it with the latest version of raspbian the graphics card started working. Either I broke a vital config file somewhere or the SD card got corrupted, but it reminded me the beauty of a system that is so painless to completely reinstall. I will have to look for a better excuse for buying the rev2 version of the model B. I did learn a lot about nmap and it is handy being use the r-pi filesystem from my laptop.
User avatar
Posts: 2
Joined: Fri Jun 29, 2012 9:28 pm
by stinos » Tue Nov 06, 2012 4:10 pm
Another way to get access to the root fs, or even chroot to it, from a windows machine:
- install VirtualBox and an image of your linux distro of choice
- plug SD card into pc
- run
Code: Select all
wmic diskdrive list
on the command prompt and note which of the \\.PHYSICALDRIVEX entries is the SD card
- still on the command prompt, create a raw vbox disk for it:
Code: Select all
"c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internalcommands createrawvmdk -filename raw.vmdk -rawdisk \\.PHYSICALDRIVEX

- attach this raw.vmdk to the vbox machine, boot, mount, full access
Posts: 21
Joined: Tue Oct 30, 2012 4:57 pm
by argief » Thu Nov 08, 2012 9:01 pm
Allen wrote:
I'm sure you weren't trying to be disingennuous to Windows

Actually I was... I used to be a "Windows only" kind of guy, used to hate linux, because (to be REALLY honest) its just so damn hard to do anything... I was just a n00b at linux and I hated it. I hated the fact that I was a super-user with Windows but turn on linux and I could barely change the background...

Arrogance. I admit it. Maybe I was afraid, maybe I just didn't want to struggle to get something as simple as write access to my all mighty NTFS partition.

But, one day in May, I formatted an old laptop and installed ONLY linux. I was determined. Windows XP was just killing the poor old pentium with 256MB of RAM. I read a book, Introduction to Linux - A Hands on Guide (by Machtelt Garrels) its FREE. It changed my life. It took a while, about 6 months. But I refused to quit. Now I am, I would say, "proficient" in linux. However, you learn pretty quickly that in the linux world you will always be learning. Its not Windows, you wont get to a point when you are bored and looking for a new challenge, there are literally thousands of projects to keep you busy if you want a new challenge. And the stuff out there on the open source market is mind blowing.

Now when I use my work Windows laptop, I feel like I am in a jail. I want to do things far beyond the reach of even Windows command line. I have learned so incredibly much. A presenter from my favorite podcast asked "just how Free is linux?" and you wont understand what that means until you are comfortable behind a linux machine.

Mounting a linux partition (your raspi SD Card) in Windows:
Even after my rant above, if raspi can encourage it's users to embrace linux, I will help however I can, "3 Ways to Access Your Linux Partitions From Windows" is a good start. I have used Ext2Fsd before and it will make your linux partitions look no different then any other native Windows drive.
Posts: 18
Joined: Sat Aug 18, 2012 6:35 pm
by DominicTurner » Sat Nov 10, 2012 9:56 am
@argief Thanks for another tool for mapping the root file system on windows.

I used unix for many years and am still struck by the elegance of it - being able to string together lots of simple command line tools to achieve in minutes what would take me hours to program on a windows machine.

It is easy to get sucked in to a mindset of one OS is superior to another. This is mainly marketing and hype. We have to remember that they are all simply tools suited to different jobs - it is up to us to pick the best one for the task in hand.

Windows has done a lot to popularise computers (if not computing).

So to return the favour - I write a lot of software in the windows environment so I end up with a lot of windows machines at my disposal. However often I just want a unix command line to do a job grep sed awk etc

Install Cygwin on your windows machines it's Linux within the windows shell.
User avatar
Posts: 2
Joined: Fri Jun 29, 2012 9:28 pm
by cave » Sat Nov 10, 2012 6:37 pm
http://cavebeat.blogspot.co.at
User avatar
Posts: 161
Joined: Fri Aug 03, 2012 6:26 am
Location: europe/austria
by argief » Sun Nov 11, 2012 7:04 am
DominicTurner wrote:
We have to remember that they [Windows/*nix] are all simply tools suited to different jobs

I agree completely. I do realize that Windows has its own "special" corner (albeit dark and secluded, and shrinking by the day :lol: ) in the world of software. However, given the educational aim of the raspberry pi, the advocacy of linux on these forums should be key. I have also occasionally resorted to cygwin, but I think you will agree that it is not akin to native *nix. But as stated above, in the advancement of linux for educational purposes, it is a great start for anybody who doesnt want to "dive" into linux completely.

Kudos for dropping names like grep and sed! Lets get all the linux n00b's curious and exited about the never-ending world of GNU/Linux!
Posts: 18
Joined: Sat Aug 18, 2012 6:35 pm
by truehl » Sun Nov 11, 2012 8:43 am
Looks great so far, but my /etc/hostip is empty, so the ip cannot be read from the file?! :o
truehl
http://www.squeezeplug.de
User avatar
Posts: 609
Joined: Sun Mar 04, 2012 6:47 pm
by meltwater » Tue Nov 27, 2012 2:30 pm
truehl wrote:Looks great so far, but my /etc/hostip is empty, so the ip cannot be read from the file?! :o

I have the same problem, and appears to be like that for a fresh image I think.

simple solution is:
Code: Select all
hostname -I > ~/ip.txt
sudo flite ~/ip.txt


Hope that helps! Probably a simpler commandline than that but it works.
______________
http://www.themagpi.com/
A Magazine for Raspberry Pi Users
Read Online or Download for Free.

My new book: goo.gl/dmVtsc

Meltwater's Pi Hardware - pihardware.com

Like the MagPi? @TheMagP1 @TheMagPiTeam
User avatar
Posts: 981
Joined: Tue Oct 18, 2011 11:38 am
by sparky300 » Wed Nov 28, 2012 12:17 am
why not just tell your Pi what IP address it should always use. there is no need to have it assign a new one every time. even internally, providing there is no conflict. my wifi dongle always used the same internal ip, i just power up and ssh in.


# allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet static
address 192.168.1.15
netmask 255.255.255.0
Posts: 40
Joined: Wed Nov 14, 2012 6:51 pm
by meltwater » Wed Nov 28, 2012 9:10 am
sparky300 wrote:why not just tell your Pi what IP address it should always use. there is no need to have it assign a new one every time. even internally, providing there is no conflict. my wifi dongle always used the same internal ip, i just power up and ssh in.


# allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet static
address 192.168.1.15
netmask 255.255.255.0


I assign the IP from my router, but my Pi gets moved to different networks, so it isn't as easy as that (or I would!).
Probably good solution for those on a fixed network though.
______________
http://www.themagpi.com/
A Magazine for Raspberry Pi Users
Read Online or Download for Free.

My new book: goo.gl/dmVtsc

Meltwater's Pi Hardware - pihardware.com

Like the MagPi? @TheMagP1 @TheMagPiTeam
User avatar
Posts: 981
Joined: Tue Oct 18, 2011 11:38 am
by sparky300 » Wed Nov 28, 2012 10:52 am
O I see, yes thats a bit more tricky.
LCD screen off ebay £3.99 you can setup to display the IP, maybe? another good idea :) :D

Or if your really, really geeky, some soft of secret code i.e. a flashing LED, flash, stop = 1, flash x 9 stop = 9. Sad right! Not practical, but fun to brush up on your Python skills!
Posts: 40
Joined: Wed Nov 14, 2012 6:51 pm
by meltwater » Wed Nov 28, 2012 11:10 am
sparky300 wrote:O I see, yes thats a bit more tricky.
LCD screen off ebay £3.99 you can setup to display the IP, maybe? another good idea :) :D

Or if your really, really geeky, some soft of secret code i.e. a flashing LED, flash, stop = 1, flash x 9 stop = 9. Sad right! Not practical, but fun to brush up on your Python skills!

I've been using a startup script to provide a menu of quick commands on startup (it also times out if I'm headless) so I may include that as part of a LCD display and buttons to provide a headless solution too.
Such a solution would allow lots of useful scripts to be selected and run without even plugging in a monitor.

IF things work out with it (i.e. it works nicely) I'll be sure to share it in the magpi.

Still love the pure simple idea of speaking the ip, genius!
______________
http://www.themagpi.com/
A Magazine for Raspberry Pi Users
Read Online or Download for Free.

My new book: goo.gl/dmVtsc

Meltwater's Pi Hardware - pihardware.com

Like the MagPi? @TheMagP1 @TheMagPiTeam
User avatar
Posts: 981
Joined: Tue Oct 18, 2011 11:38 am
by alexeames » Wed Nov 28, 2012 12:00 pm
There is yet another alternative headless login method you can use without even having a network...

http://raspi.tv/2012/how-to-run-raspberry-pi-with-no-monitor-or-network

USB to serial RS232 adaptor in case you can't be bothered to click the link. :lol:
Image
My Pi uses 2 watts - what what? ---- HiRes early production Pi photos RS Front Back | Farnell Front Back
User avatar
Posts: 2018
Joined: Sat Mar 03, 2012 11:57 am
Location: UK