Tag Archives: linux

Ubiquiti EdgeRouter Firmware Upgrade

EdgeOS firmware can be downloaded from the Ubiquity download page. First we need to see the installed version.

admin@ubnt:~$ show version
Version:      v1.2.0
Build ID:     4574253
Build on:     06/26/13 12:48
Copyright:    2012-2013 Ubiquiti Networks, Inc.
HW model:     EdgeRouter Lite 3-Port
HW S/N:       -------------
Uptime:       14:53:51 up  4:00,  2 users,  load average: 0.00, 0.02, 0.00

I like EdgeOS because you can pull the image directly into the router via HTTP. Alternatively you can download the image into a local webserver(like I did) and install from there. After the download is complete installation will begin.

admin@ubnt:~$ add system image
Trying to get upgrade file from
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 68.9M  100 68.9M    0     0  7837k      0  0:00:09  0:00:09 --:--:-- 6334k
Download suceeded
Checking upgrade image... Done
Preparing to upgrade... Done
Copying upgrade image... Done
Removing old image... Done
Checking upgrade image... Done
Finishing upgrade... Done
Upgrade completed

The image has been installed but its not running yet, we need to reboot the router for the new image to become the default.

admin@ubnt:~$ show system image
The system currently has the following image(s) installed:

v1.5.0.4677648.140620.1301     (default boot)
v1.2.0.4574253.130626.1248     (running image)

A reboot is needed to boot default image

Simply reboot and the new image will become the default boot.

admin@ubnt:~$ reboot
Proceed with reboot? [confirm]

Verify the router is running the recently installed image.

admin@ubnt:~$ show version
Version:      v1.5.0
Build ID:     4677648
Build on:     06/20/14 13:01
Copyright:    2012-2014 Ubiquiti Networks, Inc.
HW model:     EdgeRouter Lite 3-Port
HW S/N:       -------------
Uptime:       15:01:36 up 1 min,  1 user,  load average: 0.78, 0.30, 0.11

Optional commands

EdgeOS can store two images in the event you need to revert to a previous version.

admin@ubnt:~$ show system image
The system currently has the following image(s) installed:

v1.5.0.4677648.140620.1301     (running image) (default boot)

You can also delete one of the image.

delete system image

Automatically Mount A USB Drive In Ubuntu Server

USB drives can be easily and automatically mounted on Ubuntu Server with the help of USBmount which is available from the Ubuntu and Debian repositories. Fortunately, USBmount requires little configuration in order to work. The following was tested in Debian 7 Wheezy and Ubuntu 13.04.

Installation and Configuration

Make sure you run apt-get update/upgrade before starting the tutorial.

sudo apt-get update
sudo apt-get upgrade

Now install USBmount from the repositories.

sudo apt-get install usbmount

USBmount mounts all USB drives in /media/usb*.

Now plug a USB drive and wait for it to be detected and mounted. As long as the host OS supports the File System it should be mounted.

To verify whether the USB drive was mounted correctly you can use df -h to view all available drives and their respective mount points. My 4GB USB drive is accessible from the /media/usb0 mount point.

user@debian:~$ df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                   49G   18G   29G  38% /
udev                                                     10M     0   10M   0% /dev
tmpfs                                                   100M  432K  100M   1% /run
/dev/disk/by-uuid/af874479-b4ee-4d83-a3da-d2fdb48511ea   49G   18G   29G  38% /
tmpfs                                                   5.0M     0  5.0M   0% /run/lock
tmpfs                                                   404M     0  404M   0% /run/shm
/dev/sdb1                                               138G   14G  118G  11% /media/hdd1
/dev/sdc1                                               3.8G  6.6M  3.8G   1% /media/usb0

To un-mount a drive you can use umount.

sudo umount /media/usb0


USBmount is quite handy for mounting USB drives with no effort.

Mount A USB Drive In Ubuntu Server

Before we can mount a USB drive we need to gather some information about it. With the help of fdisk we can see that my 4GB USB drive was recognized as /deb/sdc1 and is formatted with FAT32.

sudo fdisk -l

Disk /dev/sdc: 4049 MB, 4049600512 bytes
255 heads, 63 sectors/track, 492 cylinders, total 7909376 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: 0x04c91666

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     7909375     3953664    b  W95 FAT32

Now create a mount point where the USB drive will be mounted. Only one drive per mount point.

sudo mkdir /media/usb

There is a good change your USB drive will be formatted with FAT16/32 therefore using the parameter -t vfat will suffice, otherwise you can use -t ntfs or -t ext3 depending on the file system.

sudo mount -t vfat /dev/sdb1 /media/usb

Make sure drive was mounted with the help of df -h. The 4GB USB drive is mounted and accessible from the /media/usb mount point.

user@debian:~$ df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                   49G   18G   29G  38% /
udev                                                     10M     0   10M   0% /dev
tmpfs                                                   100M  432K  100M   1% /run
/dev/disk/by-uuid/af874479-b4ee-4d83-a3da-d2fdb48511ea   49G   18G   29G  38% /
tmpfs                                                   5.0M     0  5.0M   0% /run/lock
tmpfs                                                   404M     0  404M   0% /run/shm
/dev/sdb1                                               3.8G  6.6M  3.8G   1% /media/usb

To un-mount the drive you can simply use the umount command folowed the mount point.

sudo umount /media/usb

SSH Permission Denied (publickey)

Had a peculiar problem last week where the computer at home I use to pull backups from a remote VPS could not longer SSH into the remote system.

user@deb7h:~$ ./vps-01-backup-www.sh
Permission denied (publickey).
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(605) [Receiver=3.0.9]

After looking at directory permissions on both systems and user credentials as the possible source of the problem I came across this post where it recommends that permission for the private key file be set to 600.

chmod 600 ~/.ssh/id_rsa

The change in permission worked, perhaps the file had too high of a permission number which in not allowed.

As to how this happen I have no idea, but I probably must have carelessly changed the permission at some point. This happen in a Debian Wheezy system.

How to Split Files with the Split command in Linux

Split is a useful Linux command used to split files into chunks of various sizes. The Split command is a straight forward utility all you do is specify the target size of each chunk in bytes (-b) followed by the name of the file to be split.

split -b 200m -d ubuntu-12.04.2-server-amd64.iso

The 657MB Ubuntu ISO was split into four chunks. Notice the incremental numbering.

x00  x01  x02  x03

To join all the files back together we use another utility, cat will look for all files starting with X*, regroup them, and output the results in to the file ubuntu-12.04.2-server-amd64.iso.

cat x* > ubuntu-12.04.2-server-amd64.iso

Split is a simple utility that can split files of any size into more manageable chunks. I regularly use split when I am forced to download files over unreliable connections and with no possibility of transfering with Rsync.



Monitor MDADM Rebuild Progress

Just in case you find your self creating or rebuilding an MDADM array here is a simple combination that will output every two seconds the status of the array.

We combine watch and cat retrieve and update the status of the array.

watch cat /proc/mdstat
Every 2.0s: cat /proc/mdstat                            Tue Mar  5 00:34:35 2013

Personalities : [raid1]
md1 : active raid1 sdc1[1] sdb1[0]
      262011712 blocks super 1.2 [2/2] [UU]
      [>....................]  resync =  3.1% (8126080/262011712) finish=20.7min

unused devices: 

Change the Keyboard Layout for CentOS / Scientific Linux

Yes, for some reason one of my VMs was configured with a different keyboard layout:

[root@system7]# cat /etc/sysconfig/keyboard


The solution is quite simple all you have to do is edit /etc/sysconfig/keyboard with your favorite editor to make the keyboard layout US friendly. I am using VI as an example you can use whatever text editor you prefer.

[root@system7]# vi /etc/sysconfig/keyboard


Save and Exit the text editor. Restart the system so the changes can take effect, now you should have a keyboard layout that you are familiar with.

Linux: How to Find a Hard Drive Serial Number

Like many other times I had to retrieve the serial number of a faulty SATA drive on a Linux box. You should retrieve and compare the serial number before replacing to reduce the chance of replacing a working drive instead of a faulty drive. Hdparm is a utility that allows for the retrieval of the serial number, if I remember correctly hdparm is included by default on Ubuntu, Scientific Linux users can install hdparm from the repositories by using yum install hdparm.

Note: hdparm requires access to the root account or similar.

Retrieve The Info

The hdparm output will be rather long, but all you need to look for is Serial Number: xx-xxxxxxxxx, this is where the serial number for the drive is contained.

# hdparm -I /dev/sdf


ATA device, with non-removable media
	Model Number:       WDC WD5001AALS-00L3B2
	Serial Number:      WD-WMASZ0044725
	Firmware Revision:  01.03B01
	Transport:          Serial, SATA 1.0a, SATA II Extensions, SATA Rev 2.5
	Supported: 8 7 6 5
	Likely used: 8

Now you can physically verify whether the drive label matches the serial number you just obtained with the help of hdparm. Check twice you wouldn’t want to pull a working drive instead.

Wipe Multiple Drives Simultaneously

This is one way you can wipe or overwrite multiple drives simultaneously it requires a little tool called Dcfldd which is available for all distributions.

If you are an Ubuntu user you can install Dcfldd from the repositories:

# apt-get install dcfldd

CentOS and Scientific Linux can install Dcfldd from the RepoForge repositories:

# yum install dcfldd

Dcfldd Wipe

Dcfldd will overwrite drive sdb and sdc with zeroes. You can also increase the block size if you want.

# dcfldd if=/dev/zero of=/dev/sdb of=/dev/sdc bs=4M

If the operation completes successfully you should receive the message No space left on device meaning there is nothing left to overwrite on the drive(s).

5120 blocks (20480Mb) written.dcfldd:: No space left on device

If you don’t beliieve me here is a screenshot displaying the activity taking place on both sdb and sdc.



Dcfldd can become useful for when you have get rid of several drives at once, as you saw the command is quite easy to remember. If you have any questions feel free to leave a comment below and I will do my best to reply as soon as possible.

Home page: Dcfldd

Ubuntu: How to Create and Open Zip Files from the Command Line

If you have an Ubuntu/Debian server installation and need to open or create Zip file then you need to install the necessary packages to work with Zip files. Fortunately, we can easily add support for Zip to our installation by installing two packages(Zip, Unzip) both available from the repositories.

Note: This post assumes you have the ability to install packages, root or sudo access.

Creating a Zip Archive

Install Zip from the repositories.

# apt-get install zip

The entire process is quite simple to understand.

# zip -r new-file-name.zip directory-to-compress/
  • zip – This is the name of the application we will be using to compress
  • -r – Short for Recursive, only use this option is you are creating a compressed archived from a directory
  • new-file-name.zip – Name of the resulting compressed archive, the naming is up to you
  • directory-to-compress/ – Name of the directory we are about to compress

It is possible to add more than one directory in to the same archive.

# zip -r new-file-name.zip directory-1/ directory-2/

But, what if I only need to compress a single file. Similar process except we don’t need to use the -r(recurse) option.

# zip report.zip LitenDuplicateReport.csv

Opening a Zip archive

Opening or extracting the contents from a compressed archive is handled not by the Zip package but by a second package called Unzip.

# apt-get install unzip

With Unzip you have two options as to how the contents will be extracted, either you can extract the contents of the compressed archive to a directory or simply extract the contents to the current directory.

# unzip nc111nt.zip -d netcat/
  • unzip – Tool that will extract contents from Zip compressed archive
  • nc111nt.zip – Name of the archive we are extracting from
  • -d – Short for destination
  • netcat – Unzip will create a new directory called netcat where the contents will be extracted to

Or you can extract the contents of the archive to the current directory you are in.

# unzip nc111nt.zip


All you need is two packages and your installation will be able to work with Zip archives. I know Ubuntu/Debian have support for Gzip but if you work with Windows users and need to share files with them then Zip might be the only way to go.