Monday, September 23, 2013

Screen Tips for Linux

Using Screen on Linux

These are general notes for using screen on Linux (Ubuntu in my case). For now this will be a working copy and refine as I go!

Why Screen?

Mostly because if you lose your terminal ssh session, you will probably have lost all work you are working on (ie. compile, unsaved file, etc). Screen is a process that runs that hosts your applications running and allows you to re-attach later on. Of course this is a super simplified explanation but one of the most important reasons one would use screen. 

 Installing Screen

For Ubuntu
> sudo apt-get install screen

(For the most part now screen comes with the standard Linux install so you won't need to install it)

Standard Scenario

Local Machine --------- (Network) ------------------ Remote Machine

1. SSH into the remote machine
> ssh <user>@<ip address>

2. Once you have successfully connected start screen
> screen

3. If you are ever disconnected, no worries! Just SSH back to your remote machine and attach to your session

> screen -ls
> screen -r  <session ID>

If you need to force you way back into your session, try the following

> screen -dRR <session ID> 

Using Screen

Starting screen you type in:
> screen

Lists the current open sessions
> screen -ls

Re-attach to a open session
> screen -r <session>

Commands 

Some basic commands below:
Ctrl-A c (create new window)
Ctrl-A n (next window)
Ctrl-A p (previous window)
Ctrl-A d (detach window)
Ctrl-A k (kill window)


Enhancements

You can customize screen using the .screenrc file which you drop into your home folder (ie. /home/<user>)

The links at here provide a good customization of screen that allows you to have "tabs" within your screen session.

If you want to get out see my links below. To get it download it

> wget http://quenenni.domainepublic.net/screenrc.txt

Drop into your home folder and rename to .screenrc

> cd ~
> mv screenrc.txt .screen

Tips

Try not using minicom and screen together. They use common control keys. You can still use it but its annoying sometimes when screen intercepts commands you intended to go to minicom.

Links Used

Good Guide(s) to Screen

Saturday, December 29, 2012

Cross-compile DTN2 for Raspberry Pi

Compiling DTN2 on the Raspberry Pi is fairly straight forward but can take some time. Now you ask yourself can I do better? Well, yes you can!

A cross compiler is essentially the act of compiling a program on a build machine that is not necessarily the same architecture as your target architecture. For example, say you have a super fast x86-based desktop which has oodles of horsepower (ie. RAM, CPU) compared to your $25/35 Raspberry Pi. Compiling programs on your super duper fast machine takes mere minutes where the Raspberry Pi can take considerably longer. What you need is to cross compile your programs on your super fast machine and then copy/transfer them over to your Raspberry Pi and it will run as if it was compiled natively on your Pi. Neat!

You will be required to cross compile a set of libraries before finally cross compiling DTN. Performing a Google search to "Cross compile DTN2" give you lots of hits. This post will give you a consolidated guide on cross compiling DTN2 for the Raspberry PI.


Build a Tool Chain

First build yourself a tool-chain for the arm processsor. Follow this excellent post from Luis Ibanez and Andrew Maclean on building yourself a tool chain for the Raspberry Pi. I won't go into any additions details since they did such a superb job on describing the steps.

http://www.kitware.com/blog/home/post/426


Cross Compile Tcl

Once you have a tool chain which includes the C and C++ compilers proceed with the following.

> wget http://sourceforge.net/projects/tcl/files/Tcl/8.6.0/tcl8.6.0-src.tar.gz
> gunzip < tcl8.6.0-src.tar.gz | tar xvf -
> cd tcl8.6.0/unix
Now, the following will depend on where you installed the tool-chain. On my system, it was installed to /home/pato/x-tools, however your setup might be different. 



Now, you will need to export the following environment variables. Remember that this will only be temporary for the life of your terminal session (ie. when you close your terminal window, you will need to do this again). 
> export LDFLAGS="-L /home/pato/x-tools/arm-unknown-linux-gnueabi/lib"
> export CFLAGS="-I /home/pato/x-tools/arm-unknown-linux-gnueabi/include"
> export CPPFLAGS="-I /home/pato/x-tools/arm-unknown-linux-gnueabi/include"
> export CC=arm-unknown-linux-gnueabi-gcc
> export AR=arm-unknown-linux-gnueabi-ar
> export RANLIB=arm-unknown-linux-gnueabi-ranlib
> export ac_cv_func_strtod=yes
> export tcl_cv_strtod_buggy=1
Whew! Now, run configure, however make sure you modify this according to your build machine. For example, if you are running another architecture you will need to modify the "--build" option for configure.

> uname -m (will list your build machine architecture)

Now, configure and compile!

> ./configure --build i686-linux --host arm-unknown-linux-gnueabi-gcc
> make

Cross Compile Berkley DB

Now, we turn our fingers to Berkley DB. Although not necessary for DTN2 to operate we will cross compile this one anyways since we can.

Open up a new terminal and get the source from Oracle. Note that the old environment variables may mess you up so I recommend starting from scratch on the environment variables.

> http://download.oracle.com/otn/berkeley-db/db-5.3.21.tar.gz

I created an account although I think you may be able to download it without one. By whatever means you get the source, eventually get it to your build machine. I used ssh to copy the source to the build machine.

Set the following environment variables

> export CC="arm-unknown-linux-gnueabi-gcc"
> export AR="arm-unknown-linux-gnueabi-ar"
> export RANLIB="arm-unknown-linux-gnueabi-ranlib"
> export STRIP="arm-unknown-linux-gnueabi-strip"

Now, run configure

> ../dist/configure host=i686-linux --build=arm-unknown-linux-gnueabi-gcc --prefix=/home/pato/DTN/berkley
> make
> make install



Cross Compile DTN2

Coming Soon!

References

The following links where used to make this post.



Tuesday, December 25, 2012

DTN2 on the raspberry pi

What is DTN2

DTN2 is an implmentation of the Bundle Protocol (RFC5050) which describes communication when disruption is the norm and not the exception. I won't go into a whole lot of detail but here is a short YouTube video which provides the basic idea.


Download Source

First, create a directory for everything and called it DTN

> mkdir DTN
> cd DTN

Next, get the source code for DTN and Oasys

> wget http://sourceforge.net/projects/dtn/files/DTN2/dtn-2.9.0/dtn-2.9.0.tgz
> wget http://sourceforge.net/projects/dtn/files/oasys/oasys-1.6.0/oasys-1.6.0.tgz

Next, unzip this two

> gunzip -c oasys-1.6.0.tgz | tar xvf -
> gunzip -c dtn-2.9.0.tgz | tar xvf -

Install Oasys

First, install some pre-requisites. On my system I had to install the following additional pre-requisites. The list of pre-requisites could differ on each system for take this as a guide. If you are missing a pre-requisite, then the configure step will highlight it. 

sudo apt-get install tcl tcl-dev libdb-dev libxerces-c2-dev libxerces-c28 libxerces-c3.1 libxerces2-java tcl-tclreadline

Now configure Oasys

>cd oasys-1.6.0
> sh configure

If there are any missing libraries, then this is the step at which you will see them. Install them one by one until the configure is happy (ie. you should see no errors)

Next compile and install
> make
> sudo make install

Install DTN

Now, go to your dtn-2.9.0 directory and issue the following commands:

> cd dtn-2.9.0
> sh configure -C
> make
> make install

Similarly, the configure step will tell you if anything is missing. Install and missing dependencies until it is happy (ie. no errors).

If everything went OK, then you should see the following applications installed under /usr/bin

pi@raspberrypi /usr/bin $ ls -l | grep dtn
-rwxr-xr-x 1 root root       81255 Dec 25 00:51 dtncat
-rwxr-xr-x 1 root root       70268 Dec 25 00:51 dtncp
-rwxr-xr-x 1 root root       71767 Dec 25 00:51 dtncpd
-rwxr-xr-x 1 root root    20346777 Dec 25 00:51 dtnd
-rwxr-xr-x 1 root root        3368 Dec 25 00:51 dtnd-control
-rwxr-xr-x 1 root root        7567 Dec 25 00:51 dtnhttpproxy
-rwxr-xr-x 1 root root       79028 Dec 25 00:51 dtnpeek
-rwxr-xr-x 1 root root      133488 Dec 25 00:51 dtnperf-client
-rwxr-xr-x 1 root root       83297 Dec 25 00:51 dtnperf-server
-rwxr-xr-x 1 root root       72117 Dec 25 00:51 dtnping
-rwxr-xr-x 1 root root       90454 Dec 25 00:51 dtnpublish
-rwxr-xr-x 1 root root       81048 Dec 25 00:51 dtnrecv
-rwxr-xr-x 1 root root      126657 Dec 25 00:51 dtnsend
-rwxr-xr-x 1 root root       72531 Dec 25 00:51 dtntraceroute
-rwxr-xr-x 1 root root      631425 Dec 25 00:51 dtntunnel




Installing and running "Wheezy" on Raspberry Pi

Downloading the image file

Download the image file from http://www.raspberrypi.org/downloads or you can download using bittorrent. Either way you will get the file in zip format.

Writing Image to SD

Writing the image file to the SD card is fairly simple in Linux with a few simple commands. There is a Windows equivalent but decided to go use 'dd' instead.

Once you have downloaded the image file from the website or through bit-torrent, you will need to un-zip it. Issue the following command

> unzip 2012-10-28-wheezy-raspbian.zip

Then using 'dd' copy the image file over to your SD hard. You will need to alter the command depending on how your SD hard get loaded. There are several ways to determine the device loaded but I would just look for the last loaded device by looking at dmesg

> dmesg | tail 

Once you find your device, issue the following command (with your alterations of course for device name)

> dd if=2012-10-28-wheezy-raspbian.img of=/dev/sdb bs=4M

Note, remember to write to the entire device and not just a single partition (ie. don't use sdb1).

For sanity, run the following command to flush the IO buffers

> sync

Done, remove your media card and put the sucker into your raspberry pi. Hook up the necessary peripherals (ie. monitor, mouse, keyboard) and you are done.


Tuesday, November 20, 2012

Installing an Ubuntu Virtual Machine

Installing a Virtual Machine

The steps to installing a virtual machine can be found anywhere on the web. However, I'm writing on this subject to get my feet wet on the world of blogging and lose my blogging virginity! Well, here goes.... 

Get VMWare

Although there are other virtual machine client software packages out there I will focus on the VMWare product line for this blog. VMWare provides a free player to get virtual machines running. Ensure that you get the latest player version from vmware.com as there are constant updates to be found. The version that I will be using for these instructions will be VMWare Player 5.0.1


BINARY DETAILS
VMware Player for Windows 32-bit and 64-bit
FILE NAME
VMware-player-5.0.1-894247.exe
BUILD NUMBER
894247
RELEASE DATE
2012-11-06
CHECKSUMS
MD5SUM: 4919e442e80044e58e25a8a0706c2aff
SHA1SUM: b6515b282b7f2fbf2e1ce27e6537f234d3198f53

My host operating system will be Windows 7 64-bit machine. Therefore, I downloaded the Windows version of installation package. I had on my machine an older version of the player (3.0.1) which had some major performance problems with the version of Ubuntu that I was installing. Therefore, get the latest players for best results.


The screen shot above shows the player when you first start it. From here you need to tell it what virtual session to open. To create a virtual image file, you will need either a VMWare Workstation version or my preferred method is to go to http://www.easyvmx.com. This site provides a way to create a template .vmx file that is used to install the operating system into the virtual machine. 

Easy VMX

Easy VMX (http://www.easyvmx.com) is quite easy to use and setup but here is a simple explanation of how to create a basic virtual machine template. When you first reach easyvmx.com, you are presented with a few options. I choose the "easyvmx: virtual machine create" option as it provides the basics of what is needed for this setup. 

Once you click on the easyvmx option, you are presented with a form where you customize your virtual machine as you want. I chose the default setting except for the following:

  • I chose a larger hard-drive since I intend to use it to download larger files (i.e programs, video, music, etc). 
  • Bumped up the RAM to 2GB
  • Changed my operating system to be Ubuntu. 
Once you are happy with your customization, click on the "create experimental virtual machine" button. At this point it will re-direct you to another page that provides a link to your virtual machine files compressed (.zip). Download the file and save it to your machine.

Installing Ubuntu

I originally started with Ubuntu 12.10 but decided to go with the more stable 12.04 LTS release since it provided a more stable platform for VMWare. Installation of 12.10 at the time had some well known issues including some pretty limiting performance problems with the use of Unity. In the end, I decided to by-pass all the headaches and just go with 12.04.

Installation is pretty straightforward. VMWare will generally auto-detect the image if on a mounted drive but you can tell it to use an .iso located on your hard-drive.

The Ubuntu installation is not too complicated and asks things like time-zone, username, password, etc. All the usual stuff. If you are unsure about something, just go with the default setting and click on next.

Once you go through the installation process you will have a fully functional Linux OS! Now we proceed to some customization.

Installing VMWare tools

Installing VMWare tools provides performance advantages along with several other features that make it worth the effort for installing. 

First go to Player > Manage > Install VMWare Tools

At this point it will mount an image on your system. Open up a command prompt and open up the package

> tar -xsvf /media/VMWare\ Tools/VMWareTools-<version>.tar.gz

This will extract the archive and uncompress all the files. Now navigate to the location that the files were extracted to and run the perl script

> sudo ./vmware-install.pl

Now, unless you are doing some customization I would safely accept all the default settings. 

dpkg and apt-get

If you are completely new to Ubuntu, you will be wondering how do programs get installed. For user familiar with Windows OS this is a process of downloading an installation package (.exe or .msi) and double clicking on the resulting icon at which point an installation dialog is presented to the user. Ubuntu and similar Linux operating systems have special applications that do this for you, however the workflow that you might be used to is a little different. 

Now, that is not to say that Ubuntu and related OS do not have nice GUI front-ends that provide a more user friendly experience when installing software (i.e Ubuntu Software Center, Synaptic Package Manager, etc) but when working with Linux OS (and any Unix based system for that matter) one should eventually embrace the power of command line processing. Sorry!

dpkg and apt-get are all about getting the right software and all its dependencies to your machine all safe and sound. At the core sits dpkg which allows packages (ie. software) to be installed on your computer. apt-get also does the same but deals well with all the dependencies these packages may have, resolving additional software, fixing broken dependencies, removing obsolete packages, etc. I would say 90% of the time when installing software you will use apt-get so learn how to use it.

The most important commands for apt-get are as follows:

sudo apt-get update (this will update the links within the repository apt-get uses to retrieve software)
sudo apt-get install <package name> (installs a particular package)
sudo apt-get upgrade (updates all packages installed)

There are others of course but as you learn about apt-get you will add to your list of commands. 

Useful Tools 

  • Install Sublime Text Editor (http://www.technoreply.com/how-to-install-sublime-text-2-on-ubuntu-12-04-unity/)