Archive for the ‘Geek’ Category

Bash Brackets

Tuesday, October 28th, 2014

Handy guide to bash brackets, swiped from Stackoverflow.

Brackets

if [ CONDITION ]    Test construct  
if [[ CONDITION ]]  Extended test construct  
Array[1]=element1   Array initialization  
[a-z]               Range of characters within a Regular Expression

Curly Brackets

${variable}                             Parameter substitution  
${!variable}                            Indirect variable reference  
{ command1; command2; . . . commandN; } Block of code  
{string1,string2,string3,...}           Brace expansion  
{a..z}                                  Extended brace expansion  
{}                                      Text replacement, after find and xargs

Parentheses

( command1; command2 )             Command group executed within a subshell  
Array=(element1 element2 element3) Array initialization  
result=$(COMMAND)                  Command substitution, new style  
>(COMMAND)                         Process substitution  
<(COMMAND)                         Process substitution

Double Parentheses

(( var = 78 ))            Integer arithmetic   
var=$(( 20 + 5 ))         Integer arithmetic, with variable assignment   
(( var++ ))               C-style variable increment   
(( var-- ))               C-style variable decrement   
(( var0 = var1<98?9:21 )) C-style trinary operation

This might be a bit of a niche subject, but I’m leaving it here for my own use.

Miscallaneous Wibble

Friday, August 24th, 2012

This post is part of a short series of tutorials for people who are new to using their Raspberry Pi.  It will make more sense if you start at the beginning.

Continued from here.

First page here

12.  Some other useful bits and bobs

Firstly, let me say that Linux is a huge subject and I’m only scratching the surface here.  Also, my knowledge on the subject is not that great; I know enough to get by and Google for everything else.  Secondly, all this huge operating system is contained within the 2GB SD  card plugged into your Pi.  That’s about £30 of hardware to create what used to be called a mainframe computer, and if you aren’t impressed by that, you haven’t understood how much your Pi can do.  Here are some bits and bobs that you might find useful as you learn more.

12.1  Pipe to your grep

Pipes were briefly mentioned earlier, as a way to stop text whooshing off the top of your screen by appending |more to the end of a command.  Here is a brief, incomplete and misleading explanation of how they work.

It’s in the nature of computers that programs take something in, do something and then put something out.  A program with no inputs or outputs doesn’t do much, after all.  You might think that command line programs take their data in from the keyboard and put it out to the screen but they actually talk to the streams, stdin and stdout – which you can think of as being like a plug and socket, one at each end of the program, through which data is poured.  It is the shell (Raspbian uses “bash” by default) that acts as an interface between you and the computer, linking the keyboard to the stdin stream and the screen to the stdout stream.  Thanks to the standardised way data is pumped in and out of programs, you can join them together so the output of one program becomes the input of another.  This is done with a “pipe” – | which is simply placed between the programs so that the data flows from left to right.  Examples will probably make more sense than words.

grep” is a program which searches for words through whatever text is put into it.  There are many ways to use it; like searching through files for a word – let’s find lines containing the word “transmission” in the log file for dpkg (which is used by Apt):

naich@raspberrypi ~ $ grep transmission /var/log/dpkg.log
2012-08-06 12:39:49 install transmission-common:all <none> 2.52-3
2012-08-06 12:39:49 status half-installed transmission-common:all 2.52-3
2012-08-06 12:39:49 status half-installed transmission-common:all 2.52-3
... and so on ...

grep can also take its input from stdin (it automatically does this if you leave the filename off the end of the command), with a pipe.  In this example, “cat filename” prints the contents of the file “filename” which is then piped to grep which prints lines containing “transmission”:

naich@raspberrypi ~ $ cat /var/log/dpkg.log | grep transmission
2012-08-06 12:39:49 install transmission-common:all <none> 2.52-3
2012-08-06 12:39:49 status half-installed transmission-common:all 2.52-3
2012-08-06 12:39:49 status half-installed transmission-common:all 2.52-3
... the same stuff as above ...

But it’s still whooshing off the screen, so let’s take the output of “grep” and pipe it to “more” (no filename after the “more” command makes it read from stdin), which paginates it:

naich@raspberrypi ~ $ cat /var/log/dpkg.log | grep transmission | more
2012-08-06 12:39:49 install transmission-common:all <none> 2.52-3
2012-08-06 12:39:49 status half-installed transmission-common:all 2.52-3
...
2012-08-06 12:40:01 status unpacked transmission-daemon:armhf 2.52-3
--More--

Or we could use “wc” to count the number of times it appears.  As with “grep” and “more”, leaving off a filename makes wc read text from stdin rather than a file.  “wc -l” counts the number of lines stuffed into its stdin:

naich@raspberrypi ~ $ cat /var/log/dpkg.log | grep transmission | wc -l
31
naich@raspberrypi ~ $

All these programs have man page help, by the way.  grep is probably the most useful tool in the Linux toolbox so it’s worth finding out about it.  Also read up about redirection, which is a related subject.

12.2  Processes, and how to kill them

All programs that run on the Pi (known as “processes”) – autonomous daemons, interactive programs and even the program that boots it, have two things – a unique ID number (process ID or “pid”) and a user who owns it (user ID or “uid”).  Well, obviously they have more than two things, but these two are the most important.

The pid is a unique number between 1 and 32768.  Each process gets a pid when it starts which is one more than the previous one assigned, unless it’s already taken, in which case the next higher one is assigned.  The numbers wrap round to 2 (1 is always used by the “init” process) when they hit 32768.

The process also has a user ID (uid), the same as one of the users on the system, as if the user had started the process himself.  The process inherits the identity of the user, writing files in his name for example, and has the same permissions to read, write and execute files as that user.  So a process running as “root”, with a uid of 0 can do anything.  Processes that don’t need to run as root tend to run as their own user, in order to sand box them into their own little world.  You can see this, for example with Transmission, which runs under the uid of 106 – debian-transmission.

You can get a list of processes currently running on your Pi with the “ps” command:

naich@raspberrypi ~ $ ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Aug20 ?        00:00:14 init [2]
root         2     0  0 Aug20 ?        00:00:00 [kthreadd]
root         3     2  0 Aug20 ?        00:00:09 [ksoftirqd/0]
... lots of processes ...
106       2382     1  0 Aug21 ?        00:22:56 /usr/bin/transmission-daemon --c
107       3527     1  0 Aug23 ?        00:13:52 /usr/bin/mediatomb -c /etc/media
root      3860  1949  0 11:35 ?        00:00:00 sshd: naich [priv]
naich     3867  3860  0 11:35 ?        00:00:00 sshd: naich@pts/0
naich     3868  3867  0 11:35 pts/0    00:00:01 -bash
naich     3941  3868  0 12:27 pts/0    00:00:00 ps -ef
naich@raspberrypi ~ $

This shows the user ID (UID), process ID (PID) the process ID of the process which started it (PPID), the start time (STIME), the amount of CPU time it has taken up (TIME) and the command that started it (CMD).  Another, more interactive way to show processes is with the “top” command:

naich@raspberrypi ~ $ top
top - 12:41:13 up 3 days, 16:25,  1 user,  load average: 0.00, 0.01, 0.05
Tasks:  57 total,   1 running,  56 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.3 us,  1.6 sy,  0.0 ni, 95.4 id,  0.0 wa,  0.0 hi,  1.6 si,  0.0 st
KiB Mem:    220592 total,   209612 used,    10980 free,     7192 buffers
KiB Swap:   102396 total,      568 used,   101828 free,   163588 cached

  PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND
 2382 debian-t  20   0 43732  11m  896 S   1.0  5.1  23:02.69 transmission-da
 3945 naich     20   0  4616 1348 1028 R   1.0  0.6   0:00.22 top
 3527 mediatom  20   0  152m 9.9m  800 S   0.3  4.6  13:53.06 mediatomb
 3867 naich     20   0 10524 1768 1056 S   0.3  0.8   0:01.54 sshd
... and so on ...

The “%CPU” and “%MEM” show the amount of CPU time and system memory each process is using at this moment and is useful in catching processes that are running out of control.  Press “H” to see the help page or “Q” to quit.  If you need to stop a process running and can’t find a way to do it nicely (with “service process stop”, for example), then you can kill it with kill.  Let’s make a process and kill it.

naich@raspberrypi ~ $ sleep 600 &
[1] 3984
naich@raspberrypi ~ $ ps -fu naich
UID        PID  PPID  C STIME TTY          TIME CMD
naich     3867  3860  0 11:35 ?        00:00:01 sshd: naich@pts/0
naich     3868  3867  0 11:35 pts/0    00:00:01 -bash
naich     3984  3868  0 12:47 pts/0    00:00:00 sleep 600
naich     3986  3868  0 12:47 pts/0    00:00:00 ps -fu naich

“sleep” is a program that does nothing for the number of seconds you tell it.  The “&” at the end means run it in the background, like a daemon, rather than interactively.  Here you tell it to do nothing for 10 minutes and then then you get a list of the processes you are running.  See the one with PID 3984 (your pid will be different)?  That’s the sleeping one we are going to creep up on and kill.  Brutal.

naich@raspberrypi ~ $ kill 3984
[1]+  Terminated              sleep 600
naich@raspberrypi ~ $ ps -fu naich
UID        PID  PPID  C STIME TTY          TIME CMD
naich     3867  3860  0 11:35 ?        00:00:01 sshd: naich@pts/0
naich     3868  3867  0 11:35 pts/0    00:00:02 -bash
naich     3985  3868  0 12:51 pts/0    00:00:00 ps -fu naich
naich@raspberrypi ~ $

RIP 3984.  Poor thing never knew what hit it.  If you are killing it because it has locked up, then you might need to use a bit more force.  If politely asking it to die with kill doesn’t work, use kill -9 to guarantee you’ll finish it off.

12.3  Symbolic links

Symbolic links allow more than one filename to point to the same file or directory.  Similar to (and naturally predating) the Windows “shortcut”, they allow you to use a filename to point to another file or directory in a different place.  They come in two types – hard links and soft links.  A hard link creates a filename that refers to the physical location of the data.  It will appear as a normal file but shares the same data as the file it is linked to.  The more common type is a soft link, which appears as “linkname -> original_file” in long listings.  Example:

naich@raspberrypi ~ $ mkdir wibble
naich@raspberrypi ~ $ echo hello >wibble/linktest.txt
naich@raspberrypi ~ $ ln -s wibble/linktest.txt softlink
naich@raspberrypi ~ $ ls -l
total 4
lrwxrwxrwx 1 naich naich   19 Aug 24 14:22 softlink -> wibble/linktest.txt
drwxr-xr-x 2 naich naich 4096 Aug 24 14:21 wibble
naich@raspberrypi ~ $ cat softlink
hello
naich@raspberrypi ~ $ rm softlink
naich@raspberrypi ~ $ ls -l wibble/
total 4
-rw-r--r-- 1 naich naich 6 Aug 24 14:21 linktest.txt
naich@raspberrypi ~ $

First we make a directory called “wibble”, then create a file in it (linktest.txt) with some text in it.  ln -s wibble/linktest.txt softlink creates a soft link to “wibble/linktest.txt” called “softlink”.  We demonstrate that “softlink” can be used as a real file by outputting the contents with cat softlink.  Then we remove the softlink with rm softlink and show that the original file remains.

Softlinks to directories can cause all sorts of hilarious confusion if you get a bit lost:

naich@raspberrypi ~ $ ln -s / subdirectory
naich@raspberrypi ~ $ cd subdirectory/home/naich/subdirectory/home/naich
naich@raspberrypi ~/subdirectory/home/naich/subdirectory/home/naich $ pwd
/home/naich/subdirectory/home/naich/subdirectory/home/naich
naich@raspberrypi ~/subdirectory/home/naich/subdirectory/home/naich $

Eek!

 12.4  Everything else

Some other other useful things to know about.

There is no on switch or reset button on the Pi, so we use the “shutdown” command to reboot or halt.  Options are “-r” to reboot or “-h” to halt before turning it off.  You also specify a time to do it at, or “now” to do it immediately.

naich@raspberrypi ~ $ sudo shutdown -r now

Broadcast message from root@raspberrypi (pts/1) (Fri Aug 24 14:02:39 2012):
The system is going down for reboot NOW!
naich@raspberrypi ~ $

You can also use the commands halt to halt and reboot to wipe the SD card clean.  Nah, just kidding.  It reboots the Pi.

For file manipulation (stop sniggering at the back), the commands are mv (move), cp (copy), rm (remove), mkdir (make directory), rmdir (remove directory).  This page explains them in english.

Get information about the filesystem with the commands df and du.  df shows how full the filesystems are:

naich@raspberrypi ~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          3.6G  1.4G  2.1G  41% /
/dev/root       3.6G  1.4G  2.1G  41% /
tmpfs            22M  208K   22M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            44M     0   44M   0% /tmp
tmpfs            10M     0   10M   0% /dev
tmpfs            44M     0   44M   0% /run/shm
/dev/mmcblk0p1   56M   34M   23M  61% /boot
/dev/sda1       7.5G  2.0G  5.6G  27% /mnt/downloads

du shows the amount of hard disk space used in a directory and all those under it:

naich@raspberrypi ~ $ du -h /etc
132K    /etc/console-setup
8.0K    /etc/rc4.d
8.0K    /etc/dpkg/origins
... and on and on ...
24K     /etc/gconf
3.8M    /etc
naich@raspberrypi ~ $

Finally, for the moment, check out uptime.  This shows how long it has been since the last reboot.  This is the geek equivalent of comparing penis size, so make sure you have at least a month’s worth of uptime before even mentioning it to anyone, let alone bragging about it.

naich@raspberrypi ~ $ uptime
 15:24:09 up  1:21,  2 users,  load average: 0.00, 0.01, 0.05
naich@raspberrypi ~ $

Yeah, an hour and 21 minutes is not going to impress the ladies.  In my defense, I did have to reboot to get a screenshot earlier.  And it’s very cold in here.

12.4  Further reading

A streaming pile of Pi

Thursday, August 23rd, 2012

Continued from here.

First page here.

11. Setting up your uPNP media server

A uPNP media server allows you to stream videos from your Pi to any device that can talk to it.  A lot of tellies do this these days, along with PS3s, XBoxs, iPads, tablets and your PC.  With a server on your Pi, you can watch what you have downloaded on any compatible device in your house without the hassle of moving files or memory sticks about.  Let’s rock.

You could try doing an apt-cache search for “upnp server” if you want the practice in finding suitable packages, or I could tell you that the one you want is Mediatomb.  So sudo apt-get install mediatomb

naich@raspberrypi ~ $ sudo apt-get install mediatomb
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following package was automatically installed and is no longer required:
 mtools
Use 'apt-get autoremove' to remove it.
The following extra packages will be installed:
 javascript-common libavcodec53 libavformat53 libavutil51 libdirac-encoder0
 libexif12 libffmpegthumbnailer4 libgsm1 libjs-prototype libmozjs185-1.0
 libmp3lame0 libmysqlclient16 libnspr4 libnspr4-0d libschroedinger-1.0-0
 libspeex1 libswscale2 libtag1-vanilla libtag1c2a libtheora0 libva1 libvpx1
 libx264-123 libxvidcore4 mediatomb-common mediatomb-daemon mysql-common
 wwwconfig-common
Suggested packages:
 apache2 httpd speex mysql-client postgresql-client
The following NEW packages will be installed:
 javascript-common libavcodec53 libavformat53 libavutil51 libdirac-encoder0
 libexif12 libffmpegthumbnailer4 libgsm1 libjs-prototype libmozjs185-1.0
 libmp3lame0 libmysqlclient16 libnspr4 libnspr4-0d libschroedinger-1.0-0
 libspeex1 libswscale2 libtag1-vanilla libtag1c2a libtheora0 libva1 libvpx1
 libx264-123 libxvidcore4 mediatomb mediatomb-common mediatomb-daemon
 mysql-common wwwconfig-common
0 upgraded, 29 newly installed, 0 to remove and 0 not upgraded.
Need to get 11.4 MB of archives.
After this operation, 25.2 MB of additional disk space will be used.
Do you want to continue [Y/n]?

It’s the same as when you installed Transmission.  Apt tells you what it is going to install and you say Yes.  It nips off, installs everything and sets it up.  It doesn’t need much configuring either.  It’ll work straight away but we’ll make a little adjustment or two.  Or three if you own a Samsung TV.  Our Samsung TV could connect to the server OK but wouldn’t play the videos.  If you have the same problem, the fix for it is here.  Read what it says and add the lines to the config file after you have made the following changes:

The configuration file for Mediatomb is /etc/mediatomb/config.xml (note that it’s in /etc, as usual) and is a bit unusual in that it’s an XML file.  Let’s not pussyfoot around here.  XML is a horrible way to present data and to use it in a configuration file is a crime against humanity.  I could rant on for a while but I will spare you that – you have enough problems, being faced with a configuration file in XML format.  So, open it up with sudo nano /etc/mediatomb/config.xml and let’s get started.  As you can see, it’s nice and easy to read – if you are a robot…

<?xml version="1.0" encoding="UTF-8"?>
<config version="2" xmlns="http://mediatomb.cc/config/2" xmlns:xsi="http://www.$
     Read /usr/share/doc/mediatomb-common/README.gz section 6 for more
     information on creating and using config.xml configration files.
    -->
  <server>
    <ui enabled="yes" show-tooltips="yes">
      <accounts enabled="yes" session-timeout="30">
        <account user="mediatomb" password="mediatomb"/>
      </accounts>
    </ui>
    <name>MediaTomb</name>
... and so on ...

Straight away, you should see something that needs changing.  The user interface web page has a default username and password, which is bad.  Change that user=”mediatomb” password=”mediatomb” to something else.  Or, if you are feeling brave, you can change “accounts enabled” to “no” and you won’t have to log on at all. This is a bad idea if you want to access it from outside your home network.

On the line after “<server>” add <port>49152</port> this forces it to use that port rather than pick one of its own choosing.  Done that?  CTRL-X, [Y]es you want to save, return to save it over the top of the original.

I’ve set up a download of a config.xml file with all those changes applied to it.  Feel free to replace yours with it.  The username is “mediatomb”, password is “wibble”.  Please change them on your system.

A quick sudo service mediatomb restart and you are done with the setting up.  To use the web interface, point your browser at http://your_pi_ip:49152 , log in (if you have to) and you should see this:

or something like that anyway.  To get it to index your media, click on the “Filesystem” tab (next to “Database”), then the cross next to “mnt” (to expand that branch) and “downloads” to highlight it.  Over on the right, there will appear a swirly cross which says “Add as autoscan dir” when you hover over it.  Click on it to select that directory as one you want Mediatomb to scan.  Choose “Inotify” for Scan mode, “Basic” for Initial scan and check “Recursive”.  Click on “Set”, it will perform a basic scan and then when you click on the “Database” tab on the left, all your stuff should appear under the “Video” branch.  Documentation for the user interface is available for those who want to tinker.

And that’s it.  Your Pi should appear  as  a media server when your TV/PS3/whatever does a scan.  Any new downloads should appear automatically but be aware that if you swap the external storage, it might not be rescanned when you plug it back in, so you will have get Mediatomb to do it manually.

Put the kettle on, make a cup of tea and enjoy your videos.  That’s pretty much it for now.  There’s one more chapter of useful things to know about Linux.

Continued here.

Memory sticks and torrents

Tuesday, August 21st, 2012

Continued from here.

First page here.

9. Thanks for the memories

For this chapter you’ll need a memory stick or a pre-formatted external hard drive with a USB connection.  As we are going to be putting videos on it, the larger the better.  Got one?  Good.  Stuff it up your Pi’s USB port.  There should be whirrings and flashings (subject to lights or motors being present) as something happens. If we were using Windows, the external storage would appear as a drive letter.  Linux, however, lets you choose where to make it appear.  Linux has a single directory tree under which external storage and internal storage is placed, or “mounted” in Linux terminology.  Remember when I said to change the “Download to: ” directory setting in Transmission to /mnt/downloads”?  That’s where we will be mounting your external storage.  You might have questions at this point, but let’s get your external storage mounted before we come to them. A while ago I was blethering on about how bad it was to be root and how it was a good idea that you couldn’t log in as root.  Yes, well, I was probably slightly exaggerating to reinforce a point.  Sometimes you have to do lots of stuff as root and all that sudoing starts getting boring.  You can make yourself root until you exit, by doing sudo -s.  Try it:

naich@raspberrypi ~ $ sudo -s
root@raspberrypi:/home/naich#

Notice a few things here – the “$” has changed to “‘#” to indicate you are now root, the “~” has changed to “/home/your_name because it is no longer your home directory and you are now “root@raspberrypi”.  You now have absolute power over the entire operating system.  Let it go to your head for a while, cackle like Emperor Palpatine and let the hate flow through you. I like to do this occasionally when I become root and I find it best get it out of my system before I do anything else.  Back to normal again?  Good. First we need to create the directory to mount the external storage on.  The mount location has to already exist in order to mount something on it.  Type in the commands in bold:

root@raspberrypi:/home/naich# cd /mnt
root@raspberrypi:/mnt# ls -l
total 0
root@raspberrypi:/mnt# mkdir downloads
root@raspberrypi:/mnt# ls -l
total 4
drwxr-xr-x 2 root root 4096 Aug 21 13:24 downloads
root@raspberrypi:/mnt#

You change your working directory to /mnt (this is traditionally where you mount things), see what is already there (nothing), create a directory called “downloads” with “mkdir” and then you list it. Quick aside here – see that “drwxr-xr-x” bit?  That shows you what sort of file it is (“d” means directory) and the permissions for it, showing who is allowed to do what to it.  Read the this page up to and including section 2.1.1to understand permissions or try and battle through my very short explanation here:

There are 3 lots of “rwx”s, the first for the owner of the file, the second for the specified group (it is the second “root” in the illustration above, shown here in italics) and the third is for “others”, i.e. everyone else who is not the owner or a member of the group.  In each “rwx”, “r” means “read”, “w” means “write” and “x” means “execute” if it is a program or “enter” if it is a directory.  A dash (“-“) means a lack of permission for that function, so in the above example, the first 3 letters after “d” (“rwx”) mean the owner (root) can “r”ead, “w”rite and “x”enter the directory.  A member of the “root” group (the next 3 letters) can “r”ead and “x”enter the directory but not “w”rite any files to it, as the “w” is missing.  The same “r-x” permissions apply to everyone else, as shown in the last 3 letters.

Now we need to find the external storage.  The Linux kernal (the core of the operating system) will have interrogated your external storage to find out what it was when you plugged it in, and then set it up as a block device, making it available in the /dev directory as if it were a file.  As it is, it is an interface that you can read and write to it but not in any way that is useful to you.  It is now up to you to mount that block device on the filesystem so you can treat it as a branch on the directory tree.  Have a look in /dev and you’ll see a whole load of files that are interfaces to devices.  One of those files is your external storage, but which one?  There are a few ways to find it, but the easiest is with the command fdisk -l:

root@raspberrypi:/mnt# fdisk -l

Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes
4 heads, 16 sectors/track, 121008 cylinders, total 7744512 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000714e9

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880     7744511     3810816   83  Linux

Disk /dev/sda: 8019 MB, 8019509248 bytes
20 heads, 16 sectors/track, 48947 cylinders, total 15663104 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x665e2cdf

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          80    15663103     7831512    b  W95 FAT32
root@raspberrypi:/mnt#

There’s a lot of information there, but the important bits are where it says “Disk /dev/…”, showing the size of the hardware and the column under “Device” which shows the names of the block devices each partition has been assigned. “Disk /dev/mmcblk0” is the SD card – see how it is split into two partitions, one large (3810816 blocks, each block being 1K making it about 3.8GB) and one small (57344 blocks)?  The other “Disk” (it will probably be “/dev/sda”) is your external storage, with its single partition appearing as “/dev/sda<number>”.  In my case it’s “sda1 “and 8019 MB big – it’s an 8GB memory stick with its partition having 7831512 1K blocks.  Yours might have a different number – “sda4”, for example, in which case use that rather than “sda1”.  Now let’s mount the /dev/sda1 device to /mnt/downloads with mount /dev/sda1 /mnt/downloads:

root@raspberrypi:/mnt# mount /dev/sda1 /mnt/downloads
root@raspberrypi:/mnt# ls -l downloads
total 188
drwxr-xr-x 3 root root   4096 Jul 12 17:07 Acad Course
-rwxr-xr-x 1 root root 181574 Jul 12 16:44 Chamber Assembly.wmv
drwxr-xr-x 2 root root   4096 Aug 15 19:31 vids
root@raspberrypi:/mnt#

The contents of the memory stick may vary.  Note how the owner and group are “root”?  That is because it was root who mounted the device.  Now we know it works, we can make it so the drive is automatically mounted at boot time, writeable by the user “debian-transmission”, who runs the transmission-daemon program. We need to find out his user ID and group ID though – type id -u debian-transmission and make a note of the user ID:

root@raspberrypi:/mnt# id -u debian-transmission
106
root@raspberrypi:/mnt#

It’s 106 for me.  Then do the same for the group ID with id -g debian-transmission and make a note of that number – 109 for me. We need to unmount it before we remount it for real.  This is the equivalent of safely removing it – unwritten data will be flushed and no more can be sent to it.  The command is umount /mnt/downloads – that’s umount, not unmount.  If you are doing this as a normal user later on, remember to sudo the command.

root@raspberrypi:/mnt# umount /mnt/downloads/
root@raspberrypi:/mnt# ls -l downloads/
total 0
root@raspberrypi:/mnt#

Never remove a storage device without unmounting it first.  If you do, a boxing glove on a spring will shoot out of the top of your Pi and punch you in the nose.  Well, it should.  You can lose data and corrupt the file system by yanking it out without unmounting.  You might also be wondering what would happen to anything that was already in the /mnt/downloads directory when your device was mounted.  The contents are preserved but are not accessible while the device is mounted over the top of them.

Now let’s automate the mounting of the external storage.  At boot time the file /etc/fstab is read to see what needs to be mounted.  Edit that file now with nano /etc/fstab and you will see this:

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       0
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       0
# a swapfile is not a swap partition, so no using swapon|off from here on, use $

Any line starting with “#” is a comment for the benefit of humans and ignored by the computer.  This goes for most configuration files.  Have a guess at what the first two columns are.  If you are really keen, try reading the man page for fstab with man fstab. The first is the block device name, the second is where it is mounted, the third is what sort of filesystem it is and the fourth is options.   The other two are used for maintenance and can be left out or set to 0.  You will want to add this line at the end in order to automatically mount your external storage:

/dev/sda1       /mnt/downloads  auto    defaults,uid=106,gid=109  0       0

Replace the “uid=106” and “gid=109” with the numbers you found earlier for user ID and group ID.  Save and exit with CTRL-X and then answering “Y” and hit return to save it with the same file name. Now mount the drive with mount -a. This mounts all the devices in /etc/fstab in the same manner as if it was booting up. Finally, check everything is hunky-dory:

root@raspberrypi:/mnt# mount -a
root@raspberrypi:/mnt# ls -l total 4
drwxr-xr-x 4 debian-transmission debian-transmission 4096 Jan  1  1970 downloads

Smashing.  I should also point out that Linux distributions like Ubuntu do all this automatically, popping up a file manager window showing the contents of the memory stick as soon as it is plugged in.  But we are operating at a lower level than that.

Now stop being root by tying exit:

root@raspberrypi:/mnt# exit
exit
naich@raspberrypi ~ $

Now we are back to normal.  You can stop cackling.  Your Pi is set up to mount the memory stick whenever it boots, so you don’t need to do anything else other than remember to sudo umount /mnt/downloads if you take the stick out and sudo mount -a when you put it back in.

10. Torrent something!

Now open up the Transmission web interface by pointing your browser at http://your_pi_ip_address:9091 and click on the “Open” icon.  Put this URL for a perfectly legal video torent in it:

http://www.frostclick.com/torrents/video/animation/Big_Buck_Bunny_1080p_surround_frostclick.com_frostwire.com.torrent

Put it in the “URL” box and click open.  Magnet links also work in this box. If you have found a Magnet link from a perfectly respectable web site, right click and choose “copy link location” and paste it into the “URL” box in Transmission.  If you have downloaded the .torrent file, upload it to Transmission.

You can check on the status of the torrent by clicking on it and then clicking the “i” icon for more info on it.  I got a “unregistered torrent” error, but DHT found enough peers to get it all.

Sometimes, with a popular torrent with lots of fast peers, the poor little Pi can get a bit overwhelmed with all the traffic hammering its ports.  It’s like a DOS attack and can bring down the Pi if it is bad enough.  So I like to limit the number of connections by going to the web panel, opening up settings by clicking on the spanner, going to the “Peers” tab and setting a limit of 20 peers per torrent and 100 peers overall.  I also set speed limits of 400kB/s for up and downloads in the “Speed” tab.

If you are having trouble connecting to any peers, make sure that “Use port forwarding from my router” is checked in “Network” tab of the settings.  This page gives some more info about setting up your router.  If your internet connection is fast you should have a high definition video file on your memory stick before you know it.  I’ll leave you to find out more about how Transmission works by the age-old method of clicking things to see what happens.

Most tellies these days have USB ports on them which you can lob a stick into.  If yours does, unmount and lob your stick.  Our telly also has an ethernet port on it, for streaming video from a uPNP media server.  Wouldn’t it be good to have a uPNP video server on the Pi?  I think we could probably manage that in the next chapter.

Continued here…

Torrents of Pi

Thursday, August 16th, 2012

Continued from here

First page here

8.  Installing a Bittorrent Client

I don’t know about you, but I want to install a Bittorrent client on your Pi, and I’ll tell you why.  If your PC uses a wireless router and you use Bittorrent, you will probably find that the Bittorrent traffic over your network utterly clobbers your PC’s connection, making the internet virtually unusable.  You also have to leave your PC on overnight when downloading large files, like Linux distributions or the many legal video torrents that exist.  Furthermore, once your torrent has finished, you have to leave the bandwidth-hogging Bittorrent program running in order to get any sort of honourable ratio.

Running a Bittorrent client on your Pi, plugged directly into the router, solves all these problems.  In fact, the whole setup is so unobtrusive that I’ve occasionally forgotten I’ve been seeding something and discovered I’ve worked up an enormous ratio.  Fnar fnar.  Sorry.  It also allows something else – you can log into your bittorrent client from any PC, even from outside your home network.  Say you are at work, browsing around at lunchtime, when you remember there is a perfectly legal film you want to watch this evening.  Logging in from your work’s PC, you can tell your Pi to start downloading it and by the time you get home, your film will be waiting for you.

So let’s find a Bittorrent client to install.  Shall we fire up Google?  No.  We don’t need to do that.  We can search the repository for Bittorrent clients using the “apt-cache” command like this: apt-cache search bittorrent client.  Note that you don’t need to sudo it because you aren’t installing anything yet.  The “apt-cache search” bit searches for whatever you put after it.

naich@raspberrypi ~ $ apt-cache search bittorrent client
apt-transport-debtorrent - an APT transport for communicating with DebTorrent
aria2 - High speed download utility
azureus - BitTorrent client
... loads and loads and loads ...
transmission - lightweight BitTorrent client
transmission-cli - lightweight BitTorrent client (command line programs)
transmission-common - lightweight BitTorrent client (common files)
transmission-daemon - lightweight BitTorrent client (daemon)
transmission-dbg - lightweight BitTorrent client (debug symbols)
transmission-gtk - lightweight BitTorrent client (GTK interface)
transmission-qt - lightweight BitTorrent client (Qt interface)
unworkable - efficient, simple and secure bittorrent client
vuze - Multimedia BitTorrent client
naich@raspberrypi ~ $

Spoiled for choice, aren’t we?  What we want is one that will happily do its own thing without any input from a human and doesn’t need a GUI.  In Linux, a program that runs in the background without requiring human interaction is called a “daemon”.  If you take a look at the list, two packages fit the bill – “deluged” and “transmission-daemon”.  We’ll use the latter.  Let’s download it, install it, set it up, and run it with 4 words: sudo apt-get install transmission-daemon.

naich@raspberrypi ~ $ sudo apt-get install transmission-daemon
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following extra packages will be installed:
 libcurl3-gnutls libminiupnpc5 libnatpmp1 minissdpd transmission-cli
 transmission-common
Suggested packages:
 natpmp-utils transmission-gtk
The following NEW packages will be installed:
 libcurl3-gnutls libminiupnpc5 libnatpmp1 minissdpd transmission-cli
 transmission-common transmission-daemon
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,905 kB of archives.
After this operation, 4,173 kB of additional disk space will be used.
Do you want to continue [Y/n]?

Do you see all those dependencies that will be installed as well?  Apt is also suggesting other packages that aren’t needed but might be useful.  You want to continue.  Things going up the screen…  Done yet?  Did you notice this line?

[ ok ] Starting bittorrent daemon: transmission-daemon.

You are now running your bittorrent client.  It will automatically start up every time your Pi starts, so you don’t even have to remember to restart it when you reboot.  Isn’t that nice?  Come on – that is pretty cool isn’t it?

So let’s use it.  Transmission comes with a built in web server to use as an interface.  You use it by putting this into your browser: “http://your_pi’s_ip_address:9091″  – that’s a colon and 9091 after the address, no slashes.  You should see this:

403: Forbidden

Unauthorized IP Address.
Either disable the IP address whitelist or add your address to it.
If you’re editing settings.json, see the ‘rpc-whitelist’ and ‘rpc-whitelist-enabled’ entries.
If you’re still using ACLs, use a whitelist instead. See the transmission-daemon manpage for details.

This is correct.  As a general rule, installed packages will be set up in a safe way, so that nasty people (including you) can’t use it.  You will need to edit the configuration file to relax its security enough that you can use it.  Full instructions on how to do it are here: https://trac.transmissionbt.com/wiki/EditConfigFiles  but let’s just get it going quickly for now.  Transmission is a bit unusual in that it overwrites its configuration files when it exits.  This isn’t normal and caused me much confusion for a while because I’d edit the configuration, restart Transmission and it wouldn’t work because all my changes were overwritten.  So let’s stop Transmission before we edit the file with sudo service transmission-daemon stop:

naich@raspberrypi ~ $ sudo service transmission-daemon stop
[ ok ] Stopping bittorrent daemon: transmission-daemon.
naich@raspberrypi ~ $

You can probably work out what is going on there.  Now edit the configuration file.  It’s in the “/etc” directory, (along with all the other configuration files), in its own directory.  If you want to find a configuration file for a daemon, look in “/etc” – it’ll be there, either in its own directory or as a file.  Type sudo nano /etc/transmission-daemon/settings.json:

naich@raspberrypi ~ $ sudo nano /etc/transmission-daemon/settings.json

Now, move the cursor down until you find this part (without the numbers):

1 "rpc-authentication-required": true,
  "rpc-bind-address": "0.0.0.0",
  "rpc-enabled": true,
2 "rpc-password": "{1669ab9b7fdadc2a8a910abf75a60f6c584365e6oRs3weiW",
  "rpc-port": 9091,
  "rpc-url": "/transmission/",
3 "rpc-username": "transmission",
4 "rpc-whitelist": "127.0.0.1",
5 "rpc-whitelist-enabled": true,

“rpc” means “Remote Procedure Call” and refers to the web server.  Seems a bit odd to call it this as RPCs are generally from computers rather than humans, but what do I know?   When you make changes, make sure you preserve the punctuation: the quotes, colons and commas all need to be in their correct places.  Going through the numbers, leave the unmarked lines alone and change these ones to suit your preferred method of access:

  1. If this is “true” (note that there are no quotes round the word in the config file) then you will be asked for a username and password before you can use the web pages.
  2. This is the password you log in with if 1. is set to “true”.  The default is an impossible-to-guess huge random string.
  3. The username you log in with if 1. is set to “true”.  Default is “transmission” and you should change it if you plan to use a username/password – default usernames are bad.
  4. The comma-separated list of IP addresses that are allowed to use the web page.  A “*” means any number.  If your home network has addresses that all start “192.168…” then you could make this string “127.0.0.1,192.168.*.*” to make sure that only people in your home network can log in.  Leave the “127.0.0.1” in there, as this refers to the Pi itself.
  5. If you set this to “false” then 4 is ignored and anyone can connect from any PC.

I’d recommend either:

  • Set 1 to “false”, 5 to “true” and make sure that any PC you will access it from is included in the list at 4 or
  • Set 1 to “true”, set the name/password in 2/3 and set 5. to “false”

The first one doesn’t require a password, but you will be restricted to logging in from only the PCs whose IP numbers are specifically set in 4.  The second allows you to access it from any PC in the world (make sure you set your router’s port forwarding so connections to port 9091 are sent to your Pi’s IP), but you need to have a username/password to stop any Tom, Richard or Harry using it.

Then start it up again with  sudo service transmission-daemon start:

naich@raspberrypi ~ $ sudo service transmission-daemon start
[ ok ] Starting bittorrent daemon: transmission-daemon.
naich@raspberrypi ~ $

Point your web browser at http://your_pi’s_address:9091 and you should see something like this:

But probably not as squished.  I wanted to get all the icons in the screenshot.  But let’s not wander away from the point that you now have a working Bittorrent client on your Pi.  Give yourself a pat on the back and put the kettle on for a celebratory cup of tea.

But there is a slight problem.  Click on the spanner and look at “Download to:” to see where your torrents will be put.  It’s something like “/var/lib/transmission-daemon/download/buried/so/deep/youll/never/find/it/again/”.  Wouldn’t it be better to have it somewhere a bit more memorable, maybe even on a memory stick so you could take it out of your Pi and take it with you?  We can do both.  Change the “Download to: ” location to /mnt/downloads and continue to the next chapter, where we’ll be setting it all up…

Continued here.

Keeping it up to date (given up with the Pi puns)

Thursday, August 9th, 2012

Continuing from here

First page here

7.  Updating your system

We’ve just got a spot of housekeeping to do before installing some stuff to turn your pi into something useful.  We are going to do a system update to make sure we are running the latest version of everything.  And I mean everything.  The update will not only update the operating system, but all your installed software.  All your Pi’s software comes from a “repository” on the internet of pre-compiled software packages, created by the people who made the Raspbian distribution – over 35,000 packages in total, covering pretty much anything you might want your Pi to do: web server, media server, media streamer, torrent client, DNS, web browser (yes, a text only web browser) and so on.  Each package contains software, configuration files, manual pages, and scripts needed to set the software up after install.  You can install packages from outside the repository or compile your own software, but that is a bit more advanced and everything we need is included in the Raspbian repository.

Software is maintained on a your Pi’s Debian-based Linux system, Raspbian, with a set of utilities called Apt, which is short for “Advanced Package Tool”.  It keeps a track of all the installed software packages, what version they are, if they need updating, and other packages required by each package.  That last one is important.  Most packages will rely on other packages being installed on your Pi in order to work.  From a programmer’s point of view, there is no point in re-inventing the wheel if you want a feature in your program (let’s call your program “Program A”) that has already been created by someone else in Program B.  The programmer can tell program A to call up Program B when this feature is needed.  Then, when the repository maintainer creates Program A’s package for the Raspbian repository, the maintainer adds a specification to the package that tells Apt to check that the package containing Program B is already installed on the Pi.  If it is then that’s fine and dandy, but if it’s not, Apt will nip off and download Program B’s package too.  Of course, it then has to check if the Program B’s package needs any other packages to be installed on the Pi, download them if they aren’t installed, check those ones…, and so on until all the packages are happy.  Keeping track of all these interlinking packages, each depending on the other (package B is called a “dependency” of package A), would be a nightmare to do yourself, so thank goodness for Apt, which does it all for you.

You might think that it sounds a bit complicated, but it’s not.  You will soon see how easy it all is to use.  Then you might start feeling sorry for Windows users and the pain they have to go through – finding the software, downloading it (Windows downloads are usually bigger as they don’t have Linux’s dependency system), going through the install procedure and then finding that the installer just splatted a load of crapware all over their PC.  Do not pity them though.  They have chosen their path.  It’s quite similar (and predates by many years) the “App” system used by Apple, Android etc., except it is far more flexible and doesn’t restrict you to one source of packages.

But back to the updating… Let’s start off by getting a list of software that needs updating.  Type sudo apt-get update and you should see something like this:

naich@raspberrypi ~ $ sudo apt-get update 
Get:1 http://mirrordirector.raspbian.org wheezy InRelease [12.5 kB] 
Get:2 http://archive.raspberrypi.org wheezy InRelease [7,698 B] 
Get:3 http://mirrordirector.raspbian.org wheezy/main armhf Packages [7,296 kB] 
... and so on for a bit... 
Ign http://mirrordirector.raspbian.org wheezy/rpi Translation-en 
Fetched 7,388 kB in 48s (151 kB/s) 
Reading package lists... Done 
naich@raspberrypi ~ $

Lovely jubbly.  It’s got a list of all the latest packages.  Let’s process all the packages that need upgrading to a later version.  Type sudo apt-get upgrade:

naich@raspberrypi ~ $ sudo apt-get upgrade 
Reading package lists... Done 
Building dependency tree Reading state information... Done 

The following packages will be upgraded: 
bash dictionaries-common file idle3 krb5-locales libgssapi-krb5-2 
libk5crypto3 libkrb5-3 libkrb5support0 liblapack3 liblapack3gf 
libmagic1 libpulse0 libsystemd-login0 libtiff4 libxapian-dev libxapian22 
libxml2 libxml2-dev libxslt1-dev libxslt1.1 nfs-common omxplayer 
python3 python3-minimal tasksel tasksel-data udisks vim-common vim-tiny 
xserver-common xserver-xorg-core 

32 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 
Need to get 23.0 MB of archives. 
After this operation, 1,183 kB of additional disk space will be used. 
Do you want to continue [Y/n]?

Do you want to continue?  You do.  And away it goes, upgrading it’s little silicon heart out.  Very rarely, you might see something like this:

Configuration file `/etc/skel/.bashrc'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
 What would you like to do about it ? Your options are:
 Y or I : install the package maintainer's version
 N or O : keep your currently-installed version
 D : show the differences between the versions
 Z : start a shell to examine the situation
 The default action is to keep your current version.
*** .bashrc (Y/I/N/O/D/Z) [default=N] ?

This means that Apt has found a configuration file that been changed since the package was installed.  Unless you have made the change yourself, it’s safest to choose “Y” to install the new version which will be compatible with the updated software. A backup of the old config file will be saved in case the new one doesn’t work so you can examine them later to see the differences and fix them if necessary.

Warnings can generally be ignored.  Things like this probably don’t mean much to you:

insserv: warning: current start runlevel(s) (empty) of script `nfs-common' overwrites defaults (2 3 4 5 S).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6 S) of script `nfs-common' overwrites defaults (0 1 6).

And to be honest it doesn’t mean that much to me either.  It looks like it’s saying that the nfs server isn’t automatically started on runlevels 2-5 any more.  Possibly.  We aren’t using nfs so we don’t care; we’ll cross that bridge if we come to it.  My Pi seemed to work OK after those warnings, so I didn’t worry about them.  Make a note of warnings, just in case you need to find a problem later, but don’t worry about them unduly.  “warning: ” means something unexpected has happened but Apt can keep going.  Errors, however, can’t be ignored.  “error: ” means something so bad has happened that Apt can’t continue.  If you ever see an error, the best thing to do is to copy and paste it into Google to find someone else who has had the same problem and has hopefully fixed it.

You want to go through this procedure (“apt-get update” followed by “apt-get upgrade”) every now and again to make sure your system is up to date.  Most updates are due to bugs regarding security and are closing avenues of attack for hackers, so you want to install them.  I do it about once a week.

There is also another type of upgrade – apt-get dist-upgrade. This upgrades your system to the latest stable release.  This means that it won’t just upgrade your packages for bug fixes and security patches, it will upgrade all your software to the version included in the current stable release of your distribution, as if you downloaded and installed it from scratch.  This is a more serious upgrade and should only be undertaken if you’ve got a bit of spare time to fix anything that might get broken.  You are likely to see those messages about the configuration files and might have to edit upgraded ones to get things working again.  If you start seeing messages during your “apt-get upgrade” that packages have been “held back”, it means that you should probably start thinking about doing a “dist-upgrade”.

Continued here…

Another pi pun

Monday, July 30th, 2012

Continued from here

First page here.

6.  Creating a user

Now you are starting to get to know your Pi, you’ll want to start making it feel more like home.  Unless your name is “Pi” you will want to add yourself as a user.  Type this:

adduser naich

Do I really need to explain that you should replace “naich” with your name?  If you’ve already guessed that and typed it in with your name, you will probably be slightly worried at this point because it will have replied “adduser: Only root may add a user or group to the system.”

“Root” is the name of the account that has full access to the Linux system.  There are many things that only Root can do, and it’s just as well really; one of the things that only root can do is permanently delete the entire filesystem with one command that doesn’t even bring up an “Are you sure?” type question.  As an ordinary user, you can only screw up your own stuff that you put on there, but as root you are a god that can break everything for everyone forever.  This is why we try to avoid being root as much as possible.  Luckily the root password does not actually exist, so you can never log on as root!  Problem solved, except that sometimes we do want to be able to do rooty stuff, like add users.  There is a way to temporarily become root and that way is sudo.  You might remember typing it in earlier.  Sudo executes a command with root privileges and you simply add “sudo” in front of the command you want to run like this: sudo adduser naich:

naich@raspberrypi ~ $ sudo adduser naich
Adding user `naich' ...
Adding new group `naich' (1000) ...
Adding new user `naich' (1000) with group `naich' ...
Creating home directory `/home/naich' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:

Choose a good password for your username but one you will remember.  Write it down if you have to.  Fill in the rest of the details or leave them blank if you want.  You also need to add your new user to the list of people who can use sudo, so type sudo visudo and you should see this:

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:$
... and so on ...

“visudo” is the command that allows you to modify the list, “sudo” means you are temporarily granted root’s super powers in order to do so.  What visudo actually does is load a text file into an editor called “nano”.  Once nano has loaded the sudoers list, move the cursor down to where it says

pi  ALL=ALL(ALL) NOPASSWD: ALL

and change “pi” to your new username.  This means “pi” will no longer be able to sudo, but that doesn’t matter because we are going to delete him soon anyway.  To save the changes and exit nano, press CTRL-X.  If you want to exit without saving your changes press N at the prompt, otherwise press Y and then hit return to save it with the suggested name.  You’ll be using nano a bit, as most configuration is done with plain text files.

Once you have got back to the “pi@raspberrypi:~$” prompt, type exit to log out and log back in again as you.

6.1 A Windows diversion

Windows users: this is the part where we sort out the static IP stuff.  Linux users can skip this bit and go to section 6.2.

You now need to edit two files – the /etc/network/interfaces file that you couldn’t edit earlier, and the /boot/cmdline.txt file to take out the stuff you put in earlier.  Type sudo nano /etc/network/interfaces and use the text editor (in the same manner as you did to edit the sudoers file) to edit the file as described in section 3 (click to open in a new window/tab).  Save it with CTRL-X, [Y]es, Enter and then type sudo nano /boot/cmdline.txt and remove all the text after “rootwait” that you put in earlier.  Make sure the text is still all on one line and that there is still a newline at the end of the line.  Save the file.  Your Pi is now properly configured with a static IP.

6.2 Back to our scheduled programming

Now let’s kill off “pi”.  If you add users with the command “adduser”, you might think you delete them with “deluser”, right?  Nope, it’s userdel.  No idea why.  As a general rule, if you don’t know what command to use, a good place to start is Google – “linux delete user”, returns 205 million pages telling you how to do it.  Anyway, have a go at deleting pi.  I’m not going to tell you how to do it.  See if you can guess.

Done it?  It was sudo userdel pi, by the way.  Do you like the way it didn’t ask if you really wanted to do that?  Linux assumes you know what you are doing and doesn’t treat you like an idiot by asking you if you really want to do something.  Successful operations for simple things (like copying, moving and deleting files, for example), generally won’t produce any output unless you tell them to.

If you don’t know how to navigate the Linux filesystem, now is the time to check out Appendix B and learn all about it.  Got it?  Go to the home directory – cd /home  and have a look – ls :

naich@raspberrypi ~ $ cd /home
naich@raspberrypi /home $ ls
naich  pi
naich@raspberrypi /home $

As well as your new user’s directory, there is also one called “pi”.  Although you deleted the user pi you didn’t delete his stuff.  You don’t need or want it, so get rid of it.  Type sudo rm -r pi (“rm is short for “remove”),… and it’s gone.  As before, there are no prompts, no “are you sure?”s; it’s gone forever.  If this doesn’t make you a little uneasy, then you might not have grasped how devastating a mistake could be and will probably discover this the hard way at some point!

Before you go any further, please consider expanding your knowledge about commands  a bit by reading appendix C.  You don’t have to but it might help you understand what’s going on a bit more.  See if you can find out what the “-r” does when you types sudo rm -r pi earlier.

Continued here…

Appendixes

Tuesday, July 17th, 2012

These are appendixes from the set of posts about setting up and using a Raspberry Pi.

Appendix A: Selecting an IP Address

As part of the boot process, your Pi used DHCP to get an IP address from the router. The problem with this is that it is an automated process which is invisible to you unless you log onto your router’s admin page to discover it.  If only the Pi and your router know what its IP address is, you don’t know where to log on to your Pi.  The easiest thing to do is change the IP settings on the Pi’s card to a static address, assigned by you.  That way you know what it is and you know it won’t change.  You don’t need to let the router know which address you have chosen, as the magic IPixies in the Pi sprinkle the router with their Ipixie Dust to let it know automatically.  Well, they do for all I know; I’ve no idea how the router finds out, but it does.

You need to pick an address for your Pi – something like 192.168.1.16, but you want to pick one that is not in the range of addresses your router assigns for DHCP requests.  If the address you choose is within the router’s DHCP address range there is a possibility that you will end up with two devices using the same address.

I’m going to leave it to you to find out what range of addresses your router assigns for DHCP and which ones are suitable for static IP addresses.  The settings will be available somewhere in your router’s admin pages.  If fiddling around with your router is out of the question, as a quick bodge you could try finding the IP address of your PC in order to guess a safe non-DHCP range address for your Pi.  Copy the first 3 sets of numbers of your PC’s address and change the last number to a low one if it’s not low or a high one (maximum 254) if it is low.  e.g.

  • Your PC’s IP is 192.168.1.3 so you pick 192.168.1.250 for your Pi
  • Your PC’s IP is 192.168.1.101 so you pick 192.168.1.3 for your Pi

You also need to know the gateway (the router’s IP address on the LAN) and subnet mask (which will probably be 255.255.255.0 – it usually is for home networks).

Go back

Appendix B: The Linux Filesystem

Here’s a quick and dirty note about the way the Linux filesystem is arranged.  For a better description try this or this.

You might be used to Windows, with its lame C: drives, D: drives, random assignation of drive letters for plug-in devices, and its pathetic attempts to hide this lameness with My Documents, libraries and other rubbish.  Linux has one hierarchical tree of files, with everything hanging off the root “/” directory.  There are no drive letters or special places; everything – programs, user data, log files, temporary files and even devices, is placed on the same directory tree.  There is a convention as to where different types of file are stored, but let’s have a little wander around and see for ourselves.

Take a look at the command prompt – “naich@raspberrypi ~ $”  It contains 4 pieces of information; your name and the name of the computer you are on (with an “@” between them), the working directory (~) and the effective user ID ($).  The “$” changes to a “#” if you are currently root – that’s all that does, but it is important to know if your powers are currently elevated to those of the godly root.  The working directory is where you currently are in the directory tree, i.e. it is the directory that a command will take action in if you don’t actually specify which directory you want the command to do its stuff in.  Get it?  No?  An example will demonstrate better than that convoluted jumble of words; type ls:

naich@raspberrypi: ~ $ ls
naich@raspberrypi: ~ $

See anything?  Nope.  ls means list all the files in a directory.  As you did not specify a directory it lists the files in the working directory, which is “~”, and is currently empty.  If you tell it to list files in a different directory it will use that one instead of the working one; type ls /:

naich@raspberrypi ~ $ ls /
bin   dev  home  lost+found  mnt  proc  run   selinux  sys  usr
boot  etc  lib   media       opt  root  sbin  srv      tmp  var
naich@raspberrypi ~ $

These are all the files and directories in the root directory “/”.  Try ls /bin – see what is happening there?  You are listing all the files in the “/bin” directory.  This rule also goes for file names.  If you want to access a file but only write a file name, the command or program will look for that file in the working directory.  If you include the directory that the file is in, it will look there instead. This goes for any type of file – data, programs or devices.  Think of your terminal window as psychically sitting on a branch of the directory tree, with everything you type in acting on that branch unless you explicitly specify otherwise.  The location of that branch is the working directory.

Handy hint – Stuff shooting off the top your screen before you can read it?  Add “ | more” to the end of your command, (e.g. ls /bin | more) to show one page of output at a time.  Scroll to the next page with the space bar or press “Q” to quit.  This works with all commands.  Don’t try to understand how it works for the moment, just consider it magic.

You can move your terminal around the directory tree with the cd (change directory) command.  Type cd / to move your working directory to the root directory and type ls again.  Now your working directory is “/”, it lists the files there when you don’t explicitly say otherwise.  Try moving to “/bin” and looking at the files there.  Try moving to other places and have a good old poke around.  Even with a basic install there are tens of thousands of files on your Pi, so there’s plenty to look at.  When you are done, move back to your home directory by simply typing cd ~.

As well as looking at the the prompt, another way to find out the working directory is to type pwd:

naich@raspberrypi ~ $ pwd
/home/naich
naich@raspberrypi ~ $

Eh?  I thought we were in “~”?  Well, we are.  “~” means “my home directory”, which is “/home/your_username”.  Your home directory is where you put all your stuff and is probably the only directory you can write to.  If you are going to start drawing Windows analogies, it is a bit like “My Documents”.  The “~” provides a reference to where all your stuff is, so using “~/README.txt” refers to README.txt which resides in your home directory, rather than any other README.txt which might be in whatever working directory you happen to be in.

It’s all relative though.  When you specify a directory to move to, look in, or to find a file in, the location you give is relative to where you currently are – i.e. your working directory.  If you start the directory location off with a “/” or “~/” it doesn’t matter where you are, as the location you are specifying starts at the root or home directory.  These are fixed absolute points on the tree, but miss off the “/” or “~/” from the start of the directory or file and it becomes relative to your working directory.  Type cd /usr to move your working directory to the “/usr” directory.  Do a ls to see the contents.  See that directory called “bin”?  It’s not the one you looked at earlier; that was a directory for general system bin(ary) programs, this one is for user-orientated bin(ary) programs.  Type ls bin.  The files listed are not the ones you saw earlier in “/bin” but are the ones in “/usr/bin”.  Because the “/” is missing from the front of “bin”, the “bin” it is showing you is the one relative to your working directory, which is currently “/usr”.  You can still see the contents of “/bin” (with the slash) by typing ls /bin (with the slash).

If you understand the concept that everything is relative to the working directory unless you say so, you are ready to know about dots – “..”, “.” and dots at the start of files.

A double dot is shorthand for “the parent directory”, i.e. the next directory down on the way to the root.  If your working directory is “/home/naich” then typing cd .. will change your working directory to “/home”.  Typing ls .. will list the contents of “/home” and so on.  You can string double dots together as if they were real directories. cd ../.. will move you two directories towards root – from “/home/naich” to “/”.  You can do daft things like cd /home/naich/../../home/naich to end up in “/home/naich”, the first “/home/naich” having been rendered pointless by the two sets of double dots moving you back down to “/” again.

A single dot means “this directory”, i.e. the current working directory.  That might not sounds useful, seeing as how, by it’s very nature, you are already working in the working directory but it does have its uses.  I’m not going to go in to them here, but you should know about it in case you see it later on.

Finally, there are hidden files.  These are hidden for convenience not security and are simply files that you don’t care about in the normal scheme of things.  Files like configuration files or log files.  You can hide a file or directory by starting its name with a dot, e.g. “.config_file”.  You have some in your home directory but didn’t see them earlier.  Go home (cd ~) and have a closer look – type ls -a.

naich@raspberrypi ~ $ ls -a
.  ..  .bash_history  .bash_logout  .bashrc  .profile
naich@raspberrypi ~ $

The “-a” bit is an “option” that tells the “ls” command to show hidden files.  Those hidden files are configuration files that are automatically generated when you create a user and control parameters about the way your terminal works.  Most of the time you don’t need to see them, so they are hidden.  You can also see the “.” and “..”, which show up as directories in their own right.

Go back

Appendix C: Commands

The basic format for doing things from the command line has 3 sections separated by spaces:

command [-options] [the_thing_you_are_doing_it_to]

An “option” is a way to modify what the command does.  For example, the default thing for the ls command to do is show the files as a horizontal list, so to list all the files in the root “/” directory:

naich@raspberrypi ~ $ ls /
bin   dev  home  lost+found  mnt  proc  run   selinux  sys  usr
boot  etc  lib   media       opt  root  sbin  srv      tmp  var
naich@raspberrypi / $

but if you add the option “-l” (minus lower case L) to the “ls” command it does this:

naich@raspberrypi ~ $ ls -l /
total 84
drwxr-xr-x  2 root root  4096 Aug  6 12:35 bin
drwxr-xr-x  2 root root 16384 Jan  1  1970 boot
... skip a few ...
drwxr-xr-x 10 root root  4096 Jul 15 19:57 usr
drwxr-xr-x 11 root root  4096 Jul 15 20:42 var
naich@raspberrypi / $

The “-l” means print it in “long” format, i.e. with more information about what sort of file or directory it is (the “d” in “drwxr-xr-x” means directory, don’t worry about the rest for now), who owns it (“root”), the group they are in (root), the size of the file, date it was last modified and its name.  You can have more than one option.  Try ls -lh /.  The “h” means put the file sizes in human readable units.

naich@raspberrypi ~ $ ls -lh /
total 84K
drwxr-xr-x  2 root root 4.0K Aug  6 12:35 bin
drwxr-xr-x  2 root root  16K Jan  1  1970 boot
... and so on

You could make it show you hidden files (“-a”), in date order (“-t”), but reversed so the latest is at the bottom (“-r”) by using ls -lhatr /

naich@raspberrypi ~ $ ls -lahtr /
total 92K
drwxr-xr-x  2 root root  16K Jan  1  1970 boot
dr-xr-xr-x 68 root root    0 Jan  1  1970 proc
drwxr-xr-x 12 root root    0 Jan  1  1970 sys
drwxr-xr-x  2 root root 4.0K Jun  2 10:25 mnt
... etc. ...

Note that the “Jan 1 1970” comes from boot time, when the Pi doesn’t know what time it is (no real time clock), so it defaults to the earliest time a Unix timestamp can have.

It would be pretty unreasonable to expect everyone to remember what all the options are, so most commands have help built in, accessible by using either “-h” or “–help” (that’s two dashes there, compared to the one for single letter options).  With ls, “-h” is used for specifying human-readable units, so –help (with the two dashes) is the option to use for help.

naich@raspberrypi ~ $ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
... blah blah etc. ...

Options with two dashes and a word are called “long options”, one dash, one letter ones are “short” options.  Obviously you can’t lump long options together behind the same dashes, so you have to use them seperately, i.e. ls --all --human-readable /.  You can also mix them if you want, i.e. ls -la --human-readable /.

A huge amount of help is also available from the manual pages residing on your Pi, which contain more verbose instructions.  You use these by typing “man command”, e.g. man ls or man adduser or even man man.  While they are very detailed and available for pretty much every command you’ll use, a) you need to already know what command you want, and b) they aren’t always written in the clearest manner for a beginner.  Don’t be afraid to google for information too – for example, putting “how do i add a user in linux” into google’s search box gives you exactly what you need to know.  You aren’t born with knowledge of how Linux works so you need to find it somewhere.  Start off with the manual pages but if you only understand a few of the words on them, have a google for it.

Go back

Pi Eyed

Tuesday, June 26th, 2012

Continued from here.

Your Pi is now sitting in the corner of the room, blinking its lights at you and presumably working.  Shall we see if we can do something with it?

3.  Setting up the interweb

Your Pi is working and sitting on the network, waiting for you.  But where is it?  You need to know its address on your network in order to log in, but it will have booted using DHCP, so its address is known only to the Pi and the router.  You need to set up your Pi with a permanent, static IP address of your choosing, as well as a gateway address (the address of the router on the LAN side) and subnet mask.  If you are a bit unsure how to select these, Appendix A might help.

We need to edit a configuration file on the SD card in order to change the settings.  Put your SD card back into your card reader.  What you do next depends on what sort of computer you are using.

If you use Linux on your PC then it’s easy enough – go into the “/etc/network” directory  in the larger partition and edit a file called “interfaces”, as shown below, with a text editor like gedit.  Do not use a word processor such as OpenOffice or LibreOffice.

The /etc/network/interfaces file looks like this:

# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.
auto lo

iface lo inet loopback
iface eth0 inet dhcp

Leave the lines up to “iface eth0…” alone, change that line and add 3 new ones like this:

iface eth0 inet static
address 192.168.1.5
gateway 192.168.1.254
netmask 255.255.255.0

With “address” being the IP address you want to assign your Pi,  “gateway” your gateway and the “netmask” for your home network.  Once you have changed the text and saved the file over the top of the original, safely remove the card, put it in your Pi and reboot.

Unfortunately it’s not that easy for Windows users.  Windows can’t read the Ext3 partition the “interfaces” config file resides in.  This means we have to temporarily force the Pi to use a static IP and then edit the config file on the Pi itself.  Look in the list of files on the card (the 59MB partition) for a file called “cmdline.txt”  Open it up with a text editor – Wordpad is best, do NOT use Word or any sort of word processor.  You will see this:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

Make sure that line wrapping is turned off (View->Word wrap->No wrap for Wordpad) and add the text in bold at the end of the line after “rootwait” (with a space between “rootwait” and “ip=192…”:

... rootwait ip=192.168.1.5::192.168.1.254:255.255.255.0::eth0:none

That’s your desired IP for your Pi, two colons, the gateway address, one colon, the netmask, two colons, “eth0”, colon, “none”.  Make sure that the text is all on one line with a newline at the end, and save the file over the original.  Safely remove the card, put it in your Pi and start it up.  Keep following the tutorial for now.  We’ll sort your Pi out permanently once you’ve logged on and used the text editor a bit.

4.  Logging in

Like any sane computer, the Pi uses SSH to provide an external terminal (or “shell”) in which to do your work.  It is secure because it is encrypted from log in onwards – no one can sniff your password, username or anything you type during your session.  If you use Linux on your home PC then you’ve already got a SSH client, but if you are unlucky enough to be using Windows, you’ll need to download PuTTY from here.  Start PuTTY up and enter the IP address you picked where it says “Host name (or IP address)” and click “Open”.  Linux users, start a shell and type ssh -l pi 192.168.1.5 (replace the 192… with your Pi’s IP address).  The username is “pi” and the password for it is “raspberry”.  You should see this:

Linux raspberrypi 3.1.9+ #168 PREEMPT Sat Jul 14 18:56:31 BST 2012 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

Type 'startx' to launch a graphical session

NOTICE: the software on this Raspberry Pi has not been fully configured. Please run 'sudo raspi-config'

pi@raspberrypi:~$

Hooray!  You are logged in and the world is your lobster.  From now on we’ll be typing commands to do things.  Whenever you see the line that says “pi@raspberrypi:~$” (or a variant of it), it means the Pi is waiting for you to type something in.

5.  Initial configuring

You see that bit where it says “NOTICE: the software on this Raspberry Pi has not been fully configured. Please run ‘sudo raspi-config'”?  That’s sound advice.  Type sudo raspi-config or copy and paste the words from the login text.

ââââââââââ⤠Raspberry Pi Software Configuration Tool (raspi-config) ââââââââââââ Setup Options                                                                â
â                                                                              â
â    1 Expand Filesystem              Ensures that all of the SD card s        â
â    2 Change User Password           Change password for the default u        â
â    3 Enable Boot to Desktop         Choose whether to boot into a des        â
â    4 Internationalisation Options   Set up language and regional sett        â
â    5 Enable Camera                  Enable this Pi to work with the R        â
â    6 Add to Rastrack                Add this Pi to the online Raspber        â
â    7 Overclock                      Configure overclocking for your P        â
â    8 Advanced Options               Configure advanced settings              â
â    9 About raspi-config             Information about this configurat        â
â                                                                              â
â                                                                              â
â                     <Select>                     <Finish>                    â
â                                                                              â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ

You will see a menu pop up with loads of options.  Move the highlighted line with the up/down arrow keys and hit return to select an option.  The options in “<>”s are selectable with the tab button, so tabbing twice would take you to the “Finish” option, where you hit return to do it.

  • If your SD card is larger than 2GB then choose option 1 – “Expand Filesystem”.  This will allow you to use all the card’s memory rather than just 2GB of it.
  • Don’t bother with 2 – “Change user password”.  We’ll be getting rid of the user in a minute anyway.
  • Don’t do 3 – “Boot to desktop” either.  We are being macho and using the command line only.
  • Select 4 – “Internationalisation Options” to go to the options page to set the timezone and “locale” (which sets various preferences like number format, date-time format) to your country.  “Timezone” is fairly straightforward, but “locale” is less so.  It offers you a list of baffling lines of text, which is comprised of  language_territory.codeset with abbreviations for “language” and “territory”.  If you are in the UK then “en_GB.UTF-8 UTF-8” is the one you want.  When you find the one you want, hit the space bar to star it and then tab a couple of times to the “OK” button.
  • 7 – Overclock: This setting allows you to speed up your pi by tweaking the clock speed and voltage of the CPU.  Higher values mean your Pi runs faster, but too high a value could make it unstable.  Experiment a bit with it and if you find you have problems, lower the settings until it’s happy.

There are a couple of things in 8 – “Advanced options” that we need to do, so select it and choose:

  • A3 – “Memory Split”: RAM on the Pi is split between the CPU and graphics chip (GPU).  As it’s not plugged into the TV you don’t need graphics.  Choose this option and enter a number for how much memory the GPU should have.  The number to use is 16, which is the minimum memory you can assign for the GPU.
  • A4 – “SSH”: Make sure that this is set to “Enable”.  Otherwise you won’t be able to log in again.

Once you’ve finished with the config program, press Tab twice to highlight “Finish” and hit return.  You can reboot your Pi when prompted or drop back to the command line (“pi@raspberrypi ~ $”) and type sudo reboot to do it manually.  Leave it for a couple of minutes and then log in again (pi/raspberry).  As a quick check to see if your Pi is now using the whole SD card, type df -h

naich@raspberrypi ~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          3.6G  3.4G   72M  98% /
/dev/root       3.6G  3.4G   72M  98% /
tmpfs            22M  208K   22M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            44M     0   44M   0% /tmp
tmpfs            10M     0   10M   0% /dev
tmpfs            44M     0   44M   0% /run/shm
/dev/mmcblk0p1   56M   34M   23M  61% /boot
naich@raspberrypi ~ $

Look at the line that starts “rootfs”.  The “Size” column should report something close to the size of your card – in this case it’s a 4GB card.  If it still says it’s under 2GB then the resizing didn’t work.  You could try resizing it with the configuration program again (sudo raspi-config) or use this tutorial.

If you are familiar with Linux on the command line you can stop reading my wibblings now.  You have, for all intents and purposes, installed Debian Wheezy on your Pi.  Go forth and do with it what you will.  The rest of you can read on while we do some basic maintenance and then add some USB storage, install a Bittorrent client to download your perfectly legal torrents and a uPNP Media Server to watch them on your TV, PS3 or whatever.

Continued here…

Yummy Pi – what to do with a Raspberry Pi

Thursday, June 21st, 2012

So you’ve got your Raspberry Pi and it’s sitting there, staring at you PCB-ily while you are wondering why you ordered it in the first place.  If you don’t know what to do with your Raspberry Pi, don’t bother plugging it into your TV, booting it up and clicking despondently at a few things before chucking it in the loft.  Use it for something useful and learn a bit about Linux at the same time.  Don’t tie up the TV with your Pi, use it on your home network as your faithful assistant – always on and connected to the internet, ready to do whatever you want at any time.  Use it headless (no monitor, keyboard or mouse) and install a whole load of useful stuff on it: a Bittorrent client, media streamer, network-attached-storage or any of these ideas.  You have a PC that is more powerful than the best computer you could buy 10 years ago and it uses less power than a low power light bulb.  It would be a crime not to use it for something.

A Raspberry Pi in a snazzy Lego case

These series of posts are aimed at someone who knows a bit about computers (above the level of randomly clicking at things in a blind panic, but below reprogramming the BIOS with a 9 volt battery and a hair clip) but not much (or indeed anything at all) about Linux.  You will learn to use your Pi at a fairly intimate level, gently stroking its settings by typing in commands and editing files.  This is not pointing and clicking, as you do with Windows, Macs or Linux distributions like Ubuntu, but typing stuff in is not difficult and it makes you feel like a hardcore hacker.  Embrace your inner geek and learn to love your Pi.

1.  Plugging it in

If you want to, you can plug your Raspberry Pi into your TV, stuff a mouse and keyboard up its USB ports and use its (quite slow by all accounts) GUI, but I don’t do these sorts of shenanigans.  I have a simpler setup where it’s just plugged into the network and accessed remotely, with no keyboard, mouse or anything.  To run it this way, you need three things: a power supply, an SD memory card and a bog standard CAT5 network cable.  Don’t panic if you are running your home network wirelessly – your router will have sockets on it for plugging in network cables.  You won’t need physical access to your Pi after the initial set up, so you can leave it next to your router – in the cupboard, under the sofa, or wherever your router lives.

To power it up, you need a 5V power supply that can provide at least 700mA with a mini-USB connector on the lead.  Have a look in that collection of phone chargers you’ve got rattling around in your crap drawer.  Jen’s Samsung charger worked a treat.  Failing that you can buy one for less than a fiver from Amazon – something like a Nokia AC-10x charger..

2.  Booting it up

You need a SD card of at least 2GB, but 4GB is better if you want to install anything.  There isn’t really an upper limit, so 16, 32 or 64GB cards should work, with faster (class 10) cards giving you a faster system overall.  It used to be the case that some cards worked better than others but later firmware versions fixed the problems that some Pis had with faster cards.  If you find that your Pi is not booting, it is worth trying a different type of card just in case.

There is no software built into the Pi, so it boots and runs off the SD card as if it were a hard drive.  That means you need to install all the software it needs on the card before you plug it into the Pi.  This page shows you how to do it. using a disk image that you copy onto the card using a card reader and software on your PC.  Here is where you download the image fileto copy to the card.  Download Raspbian “wheezy”, which is basically Debian optimised for the Pi.

If you have just finished installing the image, unplug the card from the reader now.  Plug the card back into your card reader and a window with a 59MB partition in it should pop up on your PC.  This contains the files that boot the Pi. If you are using Linux, you will also see a 1.9GB partition in another window – this contains the the rest of the files for the Raspbian system.  Because Windows can’t recognise the type of filesystem (EXT3),  Windows users can’t see this partition, but don’t worry about that.  You might be wondering what has happened to the rest of your SD card – you can only see about 2GB of it.  The file system can be adjusted to use the rest of the card’s memory once the Pi is up and running.

Now safely remove the card, lob it in your Pi, plug it into your router with the CAT5 cable and plug in the power supply.  If it’s all OK, the red LED should come on for a few seconds followed by the other ones, with the green one flashing occasionally.  The LEDs are stupidly bright.  Congratulations!  Your Raspberry Pi is now ready for use.  If only the red light is on then something is wrong.  If you have followed all the instructions and have the correct partitions and files on it, then it is probably the card itself which is the problem.  Try a different card and see if that fixes it.

Continued here…