So the year is nearly over, and I still haven't finished my blogs!
Been a busy December, so I have had no time to finish my Raspberry Pi blogs!
New years resolutions is to complete the RPi blogs and to move on to more in depth subject!
Happy New Year to anyone who reads my blog!
M
Garners Guides
Monday, 31 December 2012
Tuesday, 13 November 2012
Transfering an image file to a SD card via Linux CLI
The objective for this blog is very straight forward, and the title should be self-explanatory. In my previous blog (here) I discussed downloading the distribution image file. (we used this one) I also explained how to unzip the image file.
The next step is to copy the image from your PC to your SD card.
Before I describe the process (all one command) it may proof useful to discuss what type of SD card to use.
Personally I don't like have a lump of SD sticking out of the side of my RPi, so one of my personal mod's is to get a Micro SD converter and use a Micro SD card instead.
These aren't that expensive and can be bought from ModMyPi. (I'd also suggest adding heatsinks, whist your in modification mode) ;-)
Now to the class of Micro SD... I have read in several forums that the class of SD make no difference when used with the Raspberry Pi. I tend to disagree. It is true that RPi's will work fine using the cheaper class 4 cards. It is also true that the class speeds listed refer to serial read\write speeds, and not the random nature of a RPi's file system. But with all that said, in my experience, and by only using two RPi's side by side I personally felt that using a class 10 Sandisk Micro SD was noticeably faster than using a cheap ADATA class 4 Micro SD card.(my only benchmarking test was to watch them booting. The hardware is the same, but each time I tried, the Sandisk RPi gave me the log on prompt first!)
This really falls down to personal choice, and I confess to buying several of the class 4 cards as my local Maplin's had them on offer. ;o) Annoyingly, there are now selling 32G class 10 cards for the same price; here.
So back to the image file, you should now have the unzipped image file in the directory your working in.
You can check this with "pwd"
You can also check the file name of your image using the "ls" command.
We are now ready to transfer this image to our SD card (or MicroSD in my case).
First we need to identify the device name given to our card.
To do this, enter the "df" command, but instead of looking at the space being used, look at the volumes mounted. (df is a command to display the free disk space).
Adding the "-h" makes the results human readable.
If you run the command before inserting you SD card, and then again after what ever volumes are new are related to you SD card.
If you look at the second "df -h" you'll notice the highlighted is "/dev/mmcblk0".
This is the device name for your SD card. Sometimes if you have partitions on your SD card you may find it ends with "p0" or "p1". This is how Linux identifies partitions. We are only interested in the volumes device name as we have partitions within our image file.
You will need to unmount this partition before we start the transfer.
If you have multiply partitions, add p0 or p1 or whatever partions you have and unmount each partition.
You can check again with the "df -h" command
Now to the image transfer.
*********************************************************************************************************************************
Warning, you can damage you working PC if you get this command incorrect! be very very careful!
*********************************************************************************************************************************
The "dd" command follows the following format ;
In my example I typed "sudo dd bs=1M if=/home/anon/RaspberryPi/2012-10-28-wheezy-raspbian.img of=/dev/mmcblk0"
If we break that down, it contains the following;
"sudo" This command should be run with root privileges.
"dd" Data Destroyer!! you have been warned! :-p Seriously, I have no idea why dd, probably because cc was already used in C. But for us, this is the command we're executing!
"bs-1M" this is the byte size. you could try 4M, or if you've lots of spare time try reducing the size. With the 4G file we're using, I find 1M chunks works fine, but does take a little while. (gives me time to write this blog) ;-)
"if=/home/anon/RaspberryPi/2012-10-28-wheezy-raspbian.img" is the location of your image file. it is important to get the absolute location. I've included my '/home/username/filedirectory' to make it easier to understand instead of using '~/filedirectory'
"of=/dev/mmcblk0" is the location we're copying our image file to... basically the volumes device name. we identified this earlier using the "df" command.
If you get your "if" and "of" the wrong way around, you will be copying the contents of your SD card onto your harddrive. (great for backing up your RPi, but risky if you get your absolute locations wrong!)
Once this process starts, be patient! transfering 4G in 1M chunks can take a while, so go do some light reading.
I suggest looking here as they do a much better job of explaining this than me.
My next blog will discuss that all important first boot!
The next step is to copy the image from your PC to your SD card.
Before I describe the process (all one command) it may proof useful to discuss what type of SD card to use.
Personally I don't like have a lump of SD sticking out of the side of my RPi, so one of my personal mod's is to get a Micro SD converter and use a Micro SD card instead.
These aren't that expensive and can be bought from ModMyPi. (I'd also suggest adding heatsinks, whist your in modification mode) ;-)
Now to the class of Micro SD... I have read in several forums that the class of SD make no difference when used with the Raspberry Pi. I tend to disagree. It is true that RPi's will work fine using the cheaper class 4 cards. It is also true that the class speeds listed refer to serial read\write speeds, and not the random nature of a RPi's file system. But with all that said, in my experience, and by only using two RPi's side by side I personally felt that using a class 10 Sandisk Micro SD was noticeably faster than using a cheap ADATA class 4 Micro SD card.(my only benchmarking test was to watch them booting. The hardware is the same, but each time I tried, the Sandisk RPi gave me the log on prompt first!)
This really falls down to personal choice, and I confess to buying several of the class 4 cards as my local Maplin's had them on offer. ;o) Annoyingly, there are now selling 32G class 10 cards for the same price; here.
You can check this with "pwd"
You can also check the file name of your image using the "ls" command.
We are now ready to transfer this image to our SD card (or MicroSD in my case).
First we need to identify the device name given to our card.
To do this, enter the "df" command, but instead of looking at the space being used, look at the volumes mounted. (df is a command to display the free disk space).
Adding the "-h" makes the results human readable.
If you run the command before inserting you SD card, and then again after what ever volumes are new are related to you SD card.
If you look at the second "df -h" you'll notice the highlighted is "/dev/mmcblk0".
This is the device name for your SD card. Sometimes if you have partitions on your SD card you may find it ends with "p0" or "p1". This is how Linux identifies partitions. We are only interested in the volumes device name as we have partitions within our image file.
You will need to unmount this partition before we start the transfer.
unmount /dev/mmcblk0
If you have multiply partitions, add p0 or p1 or whatever partions you have and unmount each partition.
You can check again with the "df -h" command
Now to the image transfer.
*********************************************************************************************************************************
Warning, you can damage you working PC if you get this command incorrect! be very very careful!
*********************************************************************************************************************************
The "dd" command follows the following format ;
dd if=<source> of=<target> bs=<byte size>
In my example I typed "sudo dd bs=1M if=/home/anon/RaspberryPi/2012-10-28-wheezy-raspbian.img of=/dev/mmcblk0"
If we break that down, it contains the following;
"sudo" This command should be run with root privileges.
"dd" Data Destroyer!! you have been warned! :-p Seriously, I have no idea why dd, probably because cc was already used in C. But for us, this is the command we're executing!
"bs-1M" this is the byte size. you could try 4M, or if you've lots of spare time try reducing the size. With the 4G file we're using, I find 1M chunks works fine, but does take a little while. (gives me time to write this blog) ;-)
"if=/home/anon/RaspberryPi/2012-10-28-wheezy-raspbian.img" is the location of your image file. it is important to get the absolute location. I've included my '/home/username/filedirectory' to make it easier to understand instead of using '~/filedirectory'
"of=/dev/mmcblk0" is the location we're copying our image file to... basically the volumes device name. we identified this earlier using the "df" command.
If you get your "if" and "of" the wrong way around, you will be copying the contents of your SD card onto your harddrive. (great for backing up your RPi, but risky if you get your absolute locations wrong!)
Once this process starts, be patient! transfering 4G in 1M chunks can take a while, so go do some light reading.
I suggest looking here as they do a much better job of explaining this than me.
My next blog will discuss that all important first boot!
Thursday, 1 November 2012
Raspberry Pi Madness...
When my first Raspberry Pi (RPi)was finally delivered, I decided I wasn't going to blog too much about it. There are plenty of well written, and self explanatory blogs out there which are very helpful and informative.
Since then, I have ordered two more RPi's and tried various distributions.
Whilst playing, I found there were certain tasks which I performed on every build regardless of the distribution.
During a conversation with a friend, the only other RPi owner I know personally (We geeks are a rare breed) I realised that some of the tasks I consider run of the mill may not be that obvious to some people.
So the objective of this blog is to discuss some of the steps I take when I first build a new image on the RPi. To keep things simple, I'm going to use the Rasbian image as an example, but most of these steps are applicable to other distributions. (also on other Linux based machines).
First some ground rules, I have written this blog from my home point of view. Personally I no longer use Windows on any of the machines I own. (my work laptop belongs to my company, so is the exception.) Therefore all my set-up steps are performed on Linux based machines. If you intend to follow this blog as a guide, you will need to use Linux PC. If you don't currently have one, I suggest searching for one of the many LiveCD distributions or create a Linux image on a USB drive.(http://www.pendrivelinux.com/)
If not, refer to one of the many other guides aimed at Windows users.
Also to avoid this turning into a mammoth blog, I'm going to fragment it into sections.
This section will cover downloading your image file. ;-)
So for this you can open your favourite browser and go to the downloads page and select your preferred image.
At the time of writing, this is currently found here;
http://downloads.raspberrypi.org/images/raspbian/2012-10-28-wheezy-raspbian/2012-10-28-wheezy-raspbian.zip
Once you down load the file, it is always a good idea to check you downloaded the file without any errors. You can do this with the following command;
sha1sum ~/2012-10-28-wheezy-raspbian.zip
This will give you a checksum value which you can check against the download directory.
For the supplied image it should be;
SHA-1 3ee33a94079de631dee606aebd655664035756be
This also confirms to important facts, 1) the file was downloaded correctly. 2) the file is the same as the file uploaded by the image provider.
It is possible to skip this step, but it can save time later if you know your image file is not corrupt!
Next, it is VERY important you know where this file is located.
I normally transfer the zipped file to a raspberry directory in my home folder.
My directory path is ~/RaspberryPi/
You will need to know this when we transfer the image to a SD card, but for now we need to unzip the image file. This can be done using the "extract here" option in your file manager (nautilus) but I prefer to do things in CLI as shown below;
For those of you who like to cut + paste the command is;
unzip 2012-10-28-wheezy-raspbian.zip
at this point you should have the 2012-10-28-wheezy-raspbian.img file in you ~/RaspberryPi/ directory.
Now we need to get this image onto a SD card. I'll cover this off in my next blog.
Since then, I have ordered two more RPi's and tried various distributions.
Whilst playing, I found there were certain tasks which I performed on every build regardless of the distribution.
During a conversation with a friend, the only other RPi owner I know personally (We geeks are a rare breed) I realised that some of the tasks I consider run of the mill may not be that obvious to some people.
So the objective of this blog is to discuss some of the steps I take when I first build a new image on the RPi. To keep things simple, I'm going to use the Rasbian image as an example, but most of these steps are applicable to other distributions. (also on other Linux based machines).
First some ground rules, I have written this blog from my home point of view. Personally I no longer use Windows on any of the machines I own. (my work laptop belongs to my company, so is the exception.) Therefore all my set-up steps are performed on Linux based machines. If you intend to follow this blog as a guide, you will need to use Linux PC. If you don't currently have one, I suggest searching for one of the many LiveCD distributions or create a Linux image on a USB drive.(http://www.pendrivelinux.com/)
If not, refer to one of the many other guides aimed at Windows users.
Also to avoid this turning into a mammoth blog, I'm going to fragment it into sections.
This section will cover downloading your image file. ;-)
So for this you can open your favourite browser and go to the downloads page and select your preferred image.
At the time of writing, this is currently found here;
http://downloads.raspberrypi.org/images/raspbian/2012-10-28-wheezy-raspbian/2012-10-28-wheezy-raspbian.zip
Once you down load the file, it is always a good idea to check you downloaded the file without any errors. You can do this with the following command;
sha1sum ~/2012-10-28-wheezy-raspbian.zip
This will give you a checksum value which you can check against the download directory.
For the supplied image it should be;
SHA-1 3ee33a94079de631dee606aebd655664035756be
This also confirms to important facts, 1) the file was downloaded correctly. 2) the file is the same as the file uploaded by the image provider.
It is possible to skip this step, but it can save time later if you know your image file is not corrupt!
Next, it is VERY important you know where this file is located.
I normally transfer the zipped file to a raspberry directory in my home folder.
My directory path is ~/RaspberryPi/
You will need to know this when we transfer the image to a SD card, but for now we need to unzip the image file. This can be done using the "extract here" option in your file manager (nautilus) but I prefer to do things in CLI as shown below;
For those of you who like to cut + paste the command is;
unzip 2012-10-28-wheezy-raspbian.zip
at this point you should have the 2012-10-28-wheezy-raspbian.img file in you ~/RaspberryPi/ directory.
Now we need to get this image onto a SD card. I'll cover this off in my next blog.
Sunday, 7 October 2012
Raspberry Pi Wallpaper
Back in August, I ordered myself a Model B Raspberry Pi. In late September it finally arrived.
I have since spent a large part of my free time playing with it.
I've played with quite a few distributions, I've created PBX's using Asterisk, a media center, a dropbox (not "Dropbox! although I have played with the api's), and even a device running metasploit. (on both my own, and on the pwnpi image).
I've written a few scripts which I may blog about at a later date, but what this blog is about is my personal wallpaper;
I have since spent a large part of my free time playing with it.
I've played with quite a few distributions, I've created PBX's using Asterisk, a media center, a dropbox (not "Dropbox! although I have played with the api's), and even a device running metasploit. (on both my own, and on the pwnpi image).
I've written a few scripts which I may blog about at a later date, but what this blog is about is my personal wallpaper;
This wallpaper is the combination of an existing wallpaper I found on the Raspberry Pi Forum and an older one I've been using for years after finding it on the DeviantArt website.
For those who aren't familiar, it is a reference to the hacker manifesto written by +++The Mentor+++ back in 1986.
Feel free to use this Wallpaper.
p.s. checkout the 1337 time stamp for this post... LOL
Friday, 7 September 2012
Another simple PING script using tcl on a Cisco router
In a previous blog I discussed using tcl to create a simple script to ping multiply IP addresses from a Cisco router. (http://garnersguides.blogspot.co.uk/2012/08/some-clever-ping-tricks.html)
In this blog I have embed a video I created which describes a variation to the original script using a conditional loop.
If you have any questions, please feel free to ask me.
In this blog I have embed a video I created which describes a variation to the original script using a conditional loop.
If you have any questions, please feel free to ask me.
Wednesday, 29 August 2012
Creating multiple Loopback addresses using a Tcl script
In a previous blog, (Some clever PING tricks) I discussed using Tcl to create PING scripts to ping multiple hosts. This got me thinking, what other cool applications can I demonstrate using Tcl.
The first thing to spring to mind was creating multiple Loopback addresses. The aim of this blog is to discuss how to create multiply Loopback addresses on a router using a Tcl script.
"Why would you want to create loads of loopback addresses?" I hear you ask...
When testing routing protocols in a lab environment (Especially BGP) it is good to have plenty of routes in your routing table. Rather than create loads of routers in GNS3, or fill a rack with kit you don't need, it is easier to simulate other networks using Loopback address on a Router and then add them to our routing protocol. That's not the objective of this blog, this blog is to discuss how to create them.
As with the PING script, I will start by saying you could write all your loopbacks in a word document, and then cut them into your router, but doing it this way, only takes one line of code. (although, I may split it up to make it easier to understand).
The last PING script used the for command to create what in programming terms is called a Control Flow Loop.
The correct syntax is;
for init test body
Or if we display this in a Tcl command it would look like this;
for { init } { test } { next } {
Look familiar?
for { set i 1 } {$i <= 9 } {incr i } {
ping 10.0.0.$i re 10 si 1500 so lo0 df-bit
}
This was our last PING script in the last blog.
By changing our variable, and adapting the body we can use this loop to create our loopback addresses.
for { set i 0 } {$i <= 255 } { incr i } {
So what I've done now is "set" "i" (our variable) at 0.
The conditional test is to make sure "i" is less than 255. We can't have an octet in a IP address greater than 255.
We then increment "i" by one each time the loop is run.
Finally we use the "puts" command to send data to the router.
As we are now using configuration commands on our router so we need to use "ios_config" rather than the "exec" we used in our other PING script.
The commands should be self-explanatory;
ip address 10.255.$i.255 255.255.255.255 Is to create the IP address. I have chosen to put our variable in the third octet, but in theory we could place it in different octets, or even in several octets.
We can test our script by looking at our interfaces with the "show ip interface brief" command;
I hope this blog has been of interest, and helped you understand a little more about the power of scripting!
The first thing to spring to mind was creating multiple Loopback addresses. The aim of this blog is to discuss how to create multiply Loopback addresses on a router using a Tcl script.
"Why would you want to create loads of loopback addresses?" I hear you ask...
When testing routing protocols in a lab environment (Especially BGP) it is good to have plenty of routes in your routing table. Rather than create loads of routers in GNS3, or fill a rack with kit you don't need, it is easier to simulate other networks using Loopback address on a Router and then add them to our routing protocol. That's not the objective of this blog, this blog is to discuss how to create them.
As with the PING script, I will start by saying you could write all your loopbacks in a word document, and then cut them into your router, but doing it this way, only takes one line of code. (although, I may split it up to make it easier to understand).
The last PING script used the for command to create what in programming terms is called a Control Flow Loop.
The correct syntax is;
for init test body
Or if we display this in a Tcl command it would look like this;
for { init } { test } { next } {
body
}
Look familiar?
for { set i 1 } {$i <= 9 } {incr i } {
ping 10.0.0.$i re 10 si 1500 so lo0 df-bit
}
This was our last PING script in the last blog.
By changing our variable, and adapting the body we can use this loop to create our loopback addresses.
for { set i 0 } {$i <= 255 } { incr i } {
puts [ ios_config "interface loopback$i" "ip address 10.255.$i.255 255.255.255.255" ]
}
So what I've done now is "set" "i" (our variable) at 0.
The conditional test is to make sure "i" is less than 255. We can't have an octet in a IP address greater than 255.
We then increment "i" by one each time the loop is run.
Finally we use the "puts" command to send data to the router.
As we are now using configuration commands on our router so we need to use "ios_config" rather than the "exec" we used in our other PING script.
The commands should be self-explanatory;
interface loopback$i Is the IOS command to create a loopback interface. We use "$i" our variable to change the loopback each time the script loops.
ip address 10.255.$i.255 255.255.255.255 Is to create the IP address. I have chosen to put our variable in the third octet, but in theory we could place it in different octets, or even in several octets.
(I.E. 10.255.$i.$i)
We can test our script by looking at our interfaces with the "show ip interface brief" command;
No point showing all 255 loopbacks, but just to prove I didn't cheat, here is the end of that show ip interface brief command;
Our script worked and we have just created 255 loopbacks with a single line of Tcl scripting.
I hope this blog has been of interest, and helped you understand a little more about the power of scripting!
Tuesday, 28 August 2012
Tip for remote working on Cisco devices.
It's not uncommon to find yourself working of Cisco devices remotely. Recently I have been working on a project where the Cisco hardware has been all over the planet.
When configuring equipment remotely, you should always make sure you're not going to cut off your remote connection. Even the most experienced Engineer can inadvertently isolate a router or switch.
And sometimes, it can take a while to get some on site assistance.
One method I have employed involves using the reload command.
Before describing the process it is important to understand that this tip should only be employed on hardware which does NOT have live traffic on it. Or if it has, make sure you complete your changes in a correct outage window.
So the tip… use the reload command!
The 'reload' command is self-explanatory, but it can also be used with a timer.
You can set the reload to happen at a predefined date\time as shown below;
The command is "reload at TI:ME Day Month" or "reload at TI:ME Month Day".
You can then add a text message for the reason. In my example I used "*** Scheduled reload by Mike ***".
To cancel you're scheduled use the "reload cancel" command.
Obviously waiting 13hours for our reload is not ideal, so the version I prefer is the "reload in mmm" command shown below;
My first example was to get the router to reload in 15 minutes. "reload in 15 TEXT MESSAGE HERE"
You can check the reload with the "show reload" command.
If you need to extend your reload time, you can simply use the command again with your new time frame. I.E. "reload in 30"
As before, you can cancel it with the "reload cancel" command.
Remember to save your configuration after you've made any changes… and DON'T forget to cancel the reload if it isn't required!
One last tip, don't accidentally type reload and hit return several times… can be a costly mistake!
"From the errors of others, a wise man corrects his own." ~Syrus
When configuring equipment remotely, you should always make sure you're not going to cut off your remote connection. Even the most experienced Engineer can inadvertently isolate a router or switch.
And sometimes, it can take a while to get some on site assistance.
One method I have employed involves using the reload command.
Before describing the process it is important to understand that this tip should only be employed on hardware which does NOT have live traffic on it. Or if it has, make sure you complete your changes in a correct outage window.
So the tip… use the reload command!
The 'reload' command is self-explanatory, but it can also be used with a timer.
You can set the reload to happen at a predefined date\time as shown below;
The command is "reload at TI:ME Day Month" or "reload at TI:ME Month Day".
You can then add a text message for the reason. In my example I used "*** Scheduled reload by Mike ***".
To cancel you're scheduled use the "reload cancel" command.
Obviously waiting 13hours for our reload is not ideal, so the version I prefer is the "reload in mmm" command shown below;
My first example was to get the router to reload in 15 minutes. "reload in 15 TEXT MESSAGE HERE"
You can check the reload with the "show reload" command.
If you need to extend your reload time, you can simply use the command again with your new time frame. I.E. "reload in 30"
As before, you can cancel it with the "reload cancel" command.
Remember to save your configuration after you've made any changes… and DON'T forget to cancel the reload if it isn't required!
One last tip, don't accidentally type reload and hit return several times… can be a costly mistake!
"From the errors of others, a wise man corrects his own." ~Syrus
Subscribe to:
Posts (Atom)