Category: Article

Xiaomi USB Type C Adapter – Convert Micro USB to Type-C

Just a heads up if you are looking for a certified Micro USB to Type C adapter then I would recommend looking at the Xiaomi USB Type C Adapter they are a great way of converting the Micro USB cables you already have to Type C. The adapter works just fine with the Nexus 6P I have yet to see any problem after almost two months of use. I bought mine from Geekbuying for under $2.oo USD.

wp-1456790651766.jpg

wp-1456790705443.jpg

wp-1456790715172.jpg

wp-1456790724740.jpg

Expand the Root Partition in Kali Linux for the Raspberry Pi

By default when Kali Linux for the Rapsberry Pi is installed the file system will only expand to occupy 3GB of storage, in my case I have a 16GB Micro SD card in my Raspberry Pi 2 with most of its capacity unused. One can easily expand the file system by making use of a script that automatically does the job for you.

File system after install.

root@kali:~# df -h

Filesystem      Size  Used Avail Use% Mounted on
rootfs          2.9G  1.5G  1.2G  56% /
/dev/root       2.9G  1.5G  1.2G  56% /
devtmpfs        460M     0  460M   0% /dev
tmpfs            93M  468K   93M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           186M     0  186M   0% /run/shm

I should note I did not create the script and found it at the following address http://www.raspberryvi.org/wiki/doku.php/raspi-expand-rootfs but it has proven useful.

Download the script into the boot directory. Locally hosted.

root@kali:~# wget -O /boot/raspi-expand-rootfs.sh http://dl.linhost.info/file1/raspi-expand-rootfs.sh

Now we make the script executable.

root@kali:~# chmod +x /boot/raspi-expand-rootfs.sh

And execute the script. Don’t be scared by the output.

root@kali:~# sh /boot/raspi-expand-rootfs.sh
Command (m for help):
Disk /dev/mmcblk0: 15.9 GB, 15931539456 bytes
4 heads, 16 sectors/track, 486192 cylinders, total 31116288 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: 0x000697c0

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1               1      125000       62500    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          125001     6143999     3009499+  83  Linux

Command (m for help): Partition number (1-4):
Command (m for help): Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): Partition number (1-4, default 2): First sector (125001-31116287, default 125001): Last sector, +sectors or +size{K,M,G} (125001-31116287, default 31116287): Using default value 31116287

Command (m for help):
Disk /dev/mmcblk0: 15.9 GB, 15931539456 bytes
4 heads, 16 sectors/track, 486192 cylinders, total 31116288 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: 0x000697c0

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1               1      125000       62500    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          125001    31116287    15495643+  83  Linux

Command (m for help): The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
update-rc.d: using dependency based boot sequencing
update-rc.d: warning: default start runlevel arguments (2 3 4 5) do not match resize2fs_once Default-Start values (2 3 4 5 S)
update-rc.d: warning: default stop runlevel arguments (0 1 6) do not match resize2fs_once Default-Stop values (none)
Root partition has been resized. The filesystem will be enlarged upon the next reboot

It is necessary to reboot the OS for the changes to take effect.

root@kali:~# reboot

Once again us the df command to verify the file system successfully expanded.

root@kali:~# df -h

Filesystem      Size  Used Avail Use% Mounted on
rootfs           15G  1.5G   13G  11% /
/dev/root        15G  1.5G   13G  11% /
devtmpfs        460M     0  460M   0% /dev
tmpfs            93M  468K   93M   1% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           186M     0  186M   0% /run/shm

If you like you can remove the script from the /boot directory.

root@kali:~# rm /boot/raspi-expand-rootfs.sh

Auto Mount USB Drives in Raspbian

Update and upgrade the Raspbian installation.

sudo apt-get update && sudo apt-get upgrade

Install the package necessary to automatically mount USB drives.

sudo apt-get install usbmount

Now plug a USB drive and issue the df command to view all volumes. My USB drive was recognized /dev/sdb and mounted as /media/usb0 by the system.

df -hT
pi@raspberrypi ~ $ df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
rootfs         rootfs    2.9G  2.6G  215M  93% /
/dev/root      ext4      2.9G  2.6G  215M  93% /
devtmpfs       devtmpfs  460M     0  460M   0% /dev
tmpfs          tmpfs      93M  256K   93M   1% /run
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs          tmpfs     186M     0  186M   0% /run/shm
/dev/mmcblk0p1 vfat       56M   15M   42M  26% /boot
/dev/sdb1      vfat      2.0G  200M  1.8G  11% /media/usb0

To un-mount a volume make use of the df command above to discover the USB drive mount point and issue the unmount command as follows.

sudo umount /media/usb0

Upgrade Ubuntu 14.10 to 15.04

You can view your version of Ubuntu with the following command.

lsb_release -a
user@ubuntu:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.10
Release:        14.10
Codename:       utopic

Update and upgrade the system.

sudo apt-get update
sudo apt-get upgrade

If not already installed, then install the update-manager-core package from the repository.

sudo apt-get install update-manager-core

Start the upgrade tool.

sudo do-release-upgrade

Now follow the prompts to complete the upgrade to Ubuntu 15.04. Read the instructions carefully.

Verify the upgrade was successful with the help of the lsb_release command.

lsb_release -a
user@ubuntu:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 15.04
Release:        15.04
Codename:       vivid

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 http://192.168.1.5/ER-e100.v1.5.0.4677648.tar
Trying to get upgrade file from http://192.168.1.5/ER-e100.v1.5.0.4677648.tar
  % 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)
v1.2.0.4574253.130626.1248

You can also delete one of the image.

delete system image

Download Test Files

While this isn’t a definitive test of available bandwidth it should help you form an idea of what an Internet link throughput is. wget -O /dev/null avoids skewed results caused by disk performance limitations.

CacheFly
Location: CDN

wget -O /dev/null http://cachefly.cachefly.net/100mb.test

SoftLayer
Location: USA and Amsterdam

wget -O /dev/null http://speedtest.dal01.softlayer.com/downloads/test100.zip
wget -O /dev/null http://speedtest.sea01.softlayer.com/downloads/test100.zip
wget -O /dev/null http://speedtest.ams01.softlayer.com/downloads/test500.zip

Linode
Location: USA, UK, and Japan

wget -O /dev/null http://speedtest.tokyo.linode.com/100MB-tokyo.bin
wget -O /dev/null http://speedtest.london.linode.com/100MB-london.bin
wget -O /dev/null http://speedtest.newark.linode.com/100MB-newark.bin
wget -O /dev/null http://speedtest.atlanta.linode.com/100MB-atlanta.bin
wget -O /dev/null http://speedtest.dallas.linode.com/100MB-dallas.bin
wget -O /dev/null http://speedtest.fremont.linode.com/100MB-fremont.bin

Leaseweb
Location: USA and Netherlands

wget -O /dev/null http://mirror.nl.leaseweb.net/speedtest/1000mb.bin
wget -O /dev/null http://mirror.us.leaseweb.net/speedtest/1000mb.bin

FDCServer
Location: USA

wget -O /dev/null http://lg.denver.fdcservers.net/100MBtest.zip

OVH

Location: France

wget -O /dev/null http://proof.ovh.net/files/100Mb.dat

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

Conclusion

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

502 Bad Gateway – Nginx and PHP-FPM

Nginx 502 Bad Gateway cost me more time than the actual Ubuntu + PHP-FPM + MySQL installation I was working on. In my case the 502 Bad Gateway error on my installation was the result of a parameter mismatch between /etc/ningx/sites-available/default and /etc/php5/fpm/pool.d/www.conf.

In order to solve the 502 Bad Gateway problem edit the Nginx file /etc/ningx/sites-available/default.

nano /etc/ningx/sites-available/default

And look for the commented line # fastcgi_pass unix:/var/run/php5-fpm.sock; and uncomment the line.

fastcgi_pass unix:/var/run/php5-fpm.sock;

You location ~ .php$ { section should look similar to mine.

 location ~ .php$ {
                fastcgi_split_path_info ^(.+.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

The final two steps are to restart Nginx and PHP-FPM.

sudo service nginx restart
sudo service php5-fpm restart

Now you have a working installation like it should have been from the beginning.

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