Mount USB drive in RPi2

By default, RPi2 limits power supply of USB ports to 0.6A, while most USB drives require more than that. This is why most USB drives cannot be used with RPi2 without external power supply to RPi2. Luckily, given that you have decent power supply (ie I have 2A charger), you can increase USB port max current, by editing `/boot/config.txt`.

IMPORTANT!!! RPi2 allows max 1.2A current through all 4 USB ports combined, so don’t even think about plugging two USB drives!!! This is because the maximum power allowed into the RPi2 is limited to 2A by the fuse (F1) so if one of your USB device draw 1A, then that leaves 1A for the RPi + GPIO + remaining USB devices.

First, check if your drive can be detected without tweaking

sudo blkid

If you see only mmcblk0 entries, this means that your drive is not recognised.

/dev/mmcblk0p1: ...
/dev/mmcblk0p2: ...
/dev/mmcblk0: PTUUID="d2fd971c" PTTYPE="dos"

Add max_usb_current=1 to /boot/config.txt:

Reboot and check if your USB drive is visible after restart:

sudo reboot
sudo blkid

Now, you should see new entry:

/dev/mmcblk0p1: ...
/dev/mmcblk0p2: ...
/dev/mmcblk0: PTUUID="d2fd971c" PTTYPE="dos"
/dev/sda1: LABEL="turo"...

And you should be able to mount it:

sudo mkdir -p /media/turo
sudo mount /dev/sda1 /media/turo

Inspired by www.htpcguides.com and www.raspberrypi.org/forums.

Raspberry Pi2 with Ubuntu Sever and Drupal?

I decided to celebrate 25th B-day of Linux by putting the latest Ubuntu 16.04 on my Raspberry Pi 2 and setting up a webserver.
This is how I did it:

  1. First, get Ubuntu armf image and prepare memory card
  2. # get image
    wget http://cdimage.ubuntu.com/ubuntu/releases/16.04/release/ubuntu-16.04-preinstalled-server-armhf+raspi2.img.xz
    
    # make sure your SD card is on sdb ie by df -h
    xzcat ubuntu-16.04-preinstalled-server-armhf+raspi2.img.xz | sudo dd of=/dev/sdb
    
  3. Configure new user & setup Drupal8 webserver
  4. # create new user & change hostname
    sudo adduser USERNAME && sudo usermod -a -G sudo USERNAME
    # edit /etc/hostname and add `127.0.1.1 newHostname` to /etc/hosts
    sudo reboot
    
    # generate locales
    sudo locale-gen en_US.UTF-8
    sudo dpkg-reconfigure locales
    
    # install software
    sudo apt install htop apache2 mysql-server libapache2-mod-php php-mysql php-sqlite3 php-curl php-xml php-gd git sqlite3 emacs-nox
    

My first impressions?
sudo apt is veeery slow. At first, I thought it’s due to old SD card I’ve been using, but it’s also true for newer SD card.
Some packages are missing (ie. git-lfs), but you can get them using some workarounds.

But everything just works!
You can check the mirror of https://ngschool.eu/ running on RPi2 here.
Maybe it’s not speed devil, but it stable and uses almost no energy 🙂

Cheers!

Inspired by Ubuntu’s Insights.

Sending emails from command-line using Gmail & SSMTP

I wanted to send email reports from my computers. For that, the easiest is to create additional Gmail account (so your private email is safe) and set-up SSMTP:

sudo apt-get install ssmtp mailutils

Configure SSMTP: comment all lines in /etc/ssmtp/ssmtp.conf and add at the end (replacing HOSTNAME/USER/PASSWORD with your info):

root=postmaster
hostname=HOSTNAME
mailhub=smtp.gmail.com:465
AuthUser=USER@gmail.com
AuthPass=PASSWORD
FromLineOverride=YES
UseTLS=YES

Then, allow access from less secure apps to created Gmail account and enable one-time sign-in for new app without captcha. It’s strongly recommended not to use your private account for that purpose!

And send emails:

echo "email body" | mail -s "Test email from "`hostname` SOMEUSER@gmail.com

Voilà!

Note, this works perfectly fine in Ubuntu, as well as in Raspberry Pi.

NX server on Raspberry Pi

Finally I had some time to get my hand on new Raspberry Pi 2.
I think it’s useful to access the RPi2 by ssh (work out of the box) and NX. Installation of NX server is quite time-consuming, but I think it’s worth to give it a try! Here is what I did:

# install dependencies
sudo apt-get install xutils-dev expect xorg-dev libjpeg8-dev libpng12-dev cups xfonts-base x11-xserver-utils autoconf

sudo mkdir -p /usr/NX/{bin,etc}

# install freenx
wget http://pkgs.fedoraproject.org/repo/pkgs/freenx-server/freenx-server-0.7.3.tar.gz/856f597e139018f7ed62713c9d6c9ed5/freenx-server-0.7.3.tar.gz
tar xpfvz freenx-server-0.7.3.tar.gz
cd freenx-server-0.7.3
patch < gentoo-nomachine.diff
make
sudo make install

# copy node.conf
# and replace #COMMAND_MD5SUM="openssl md5" with COMMAND_MD5SUM="md5sum"
# and #COMMAND_START_GNOME=gnome-session with COMMAND_START_GNOME="/usr/bin/startlxde"
sudo cp node.conf.sample /usr/NX/etc/node.conf

# get nx source
wget http://code.x2go.org/releases/source/nx-libs/nx-libs_3.5.0.13-full.tar.gz
tar xpfvz nx-libs_3.5.0.13-full.tar.gz
cd nx-libs_3.5.0.13

# compile & relax for ~1 hour...
make build-full
sudo make install

# copy libs and binaries
sudo ln -s /usr/lib/NX3/lib/nx /usr/NX/lib
sudo cp -a nx-X11/lib/X11/libNX_X11.so* nx-X11/lib/Xext/libNX_Xext.so* nx-X11/lib/Xrender/libNX_Xrender.so* nxcomp/libXcomp.so* nxcompext/libXcompext.so* nxcompshad/libXcompshad.so* /usr/NX/lib
sudo cp -a nx-X11/programs/nxauth/nxauth nx-X11/programs/Xserver/nxagent nxproxy/nxproxy /usr/NX/bin

# link binaries & install
for f in /usr/bin/nx*; do echo $f; sudo ln -s $f /usr/NX/bin; done
sudo nxsetup --install

After these steps, you should be able to connect with NX client using fake GNOME session.
Raspberry Pi 2 over NX

Post is based on TiaoWiki with some updates/improvements.