"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects." (Robert A. Heinlein)

Saturday 27 October 2018

Hard disk upgrading with Clonezilla


Some time ago my desktop computer welcomed me with an unpleasant message: the main hard drive was likely to fail soon.

When you receive similar messages you never know how soon “soon” means. Since disk drives prices are reasonably low I decided not to waste time, I so bought a new, bigger, hard drive to replace the faulty one.
Upgrading the computer main drive could be a time consuming business if done “by hand” since it means copying all system and user data. Fortunately many tools exist in the Linux world to ease the process, among them Clonezilla.


Clonezilla


Clonezilla is a, very small foot-print, Linux distribution dedicated to disk and partition backup or cloning. I already used it once to backup EEEPC original Xandros installation. I downloaded Clonezilla ISO image and installed it on a SUB disk using Unetbootin. Because of its very small size I’ve been able to install Clonezilla on a old 1GB USB drive.
Before starting Clonezilla Iinstalled the new drive on my desktop PC together with the old one and partitioned it using Gparted.
At boot Clonezilla offer some boot options, I selected the default one
Then, once the system had started, after the long language and keyboard selection menu, I’ve been shown several options. I selected to work in a “device-device” mode then selected the “local partition-to-local partition” copy mode.
I proceeded with copying partition one from the old disk to partition one in the new disk, once completed I repeated with partition two.
At last I powered of the computer, removed the old faulty disk and left the new one in its place. I restarted the system but, the new disk didn’t boot.
After a while I figured I forgot that Clonezilla, when copying partition-by-partition, didn’t copy boot information. Not a big deal, once you understand it.
Eventually I started again the system using Clonezilla and, using command line interface, I installed GRUB on the new disk.
sudo mkdir /mnt/ubuntu
sudo mount /dev/sda1 /mnt/ubuntu
sudo grub-install --boot-directory=/mnt/ubuntu/boot /dev/sda
After this my computer started, working like before.
By the Way now I have a unreliable spare 500 GB hard disk, what could I use it for?

Saturday 29 September 2018

Things to remember: mount your USB drives using UUID


This is just a short post to remember myself, and hopefully to my few readers, how a little more research before doing things could save from problems in future. I had to disconnect all my computer, the Raspberry and every devices because of some maintenance works I hhad to do at home. As often happens when I connected all back not everything worked as before.
Worst of all was the Raspberry Pi 3 that didn’t boot anymore or, at least, the boot process crashed betore turning on the network. I had to attach the Raspberry to my TV to discover that the boot process failed while trying to mout the attached USB drives. After some swapping of available USB slots I managed to get back to the original working position. I had to solve the problem definitively.

Mounting drives using UUID

USB drive devices are assigned on a per position basis. This is usually irrilevant for removable drives but it can become a problem when using USB for fixed, mounted on boot, drives. The solution is defining drives non by using their assigned device but the device unique identifier (UUID). The funny thing is that the solution was already on display in Raspberry “fstab” file since the system uses a similar identifier (PARTUID) in order to mount boot and root partitions.
The drive UUID can be easly printed by using “blkid” or “lsblk” commands. Here the vary informative output produced by “lsblk” command:
sudo lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL

once identified drive UUIS is just matter of replacing it inside “/etc/fstab” file like this:
# USB Disk
#/dev/sda1 /media/usbdisk ext4 rw,defaults 0 0
#/dev/sdb1 /media/backup xfs rw,defaults 0 0
UUID=bc83dfb9-ebc5-4a96-9cd2-0657fa767717 /media/usbdisk ext4 rw,defaults 0 0
UUID=debd0d49-549a-4187-8284-f20dc3c8f986 /media/backup xfs rw,defaults 0 0





Saturday 7 July 2018

The joy of virtualization: Docker


I took a relative pause from experimenting with Raspberry Pi to report my first experiences with something completely different. One of the first things you realize while programming server-side is how your program is only one piece of a bigger puzzle. Your application usually runs inside a container, connects to a database, expose or consume services and so on ... Solving this puzzle means defining an installation procedure that becomes different and sometime more complex by changing or scaling the installation target.

Docker

Docker is an container platform that overcomes the installation problems by producing a ready-to-install standardized operating-system-level virtual machine, packed with everything your application needs to be run. Unlike other virtualization solutions a Docker image only contains what your application needs without having to install and run a full hardware simulation like, for example, in Virtual Box.

Installation

Docker is available in two versions a professional “enterprise” edition and a community one (Docker CE) free to download. Installing Docker CE on Ubuntu is just matter of adding Docker repository address
sudo apt-get update

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Then installing it using the usual apt command
sudo apt-get updatesudo apt-get install docker-ce
Once the installation completed the current user, or any user who will use Docker, must be added to the “docker” group.
sudo adduser maxx docker
After logging out and in again Docker was ready for use and command
docker info
Correctly reported the empty environment initial state

First run

In order to test Docker is correctly installed and running a simple “hello-world” image is available. Just by calling the command:
docker run hello-world
Docker take care of downloading the image from its repository, installing and running it.

Another interesting image to start with is, as suggested in hello-world printout, the “ubuntu” image that installs and starts a console-only Ubuntu virtual machine with no effort.

Sunday 3 June 2018

Simple hardware interface for the Raspberry Pi Zero


I spent some hours, last weekend, working to another little step into my Raspberry Zero camera project. After experimenting remote software interface possibilities I started building some minimal bare hardware interface in order to, at least, safely turn on and off the Raspberry Pi.



A bare minimum interface
The bare minimum hardware interface for a Raspberry project is made of a power push-button and a status LED telling if the device is still active or it can be safely removed from power.
Plenty of tutorials are available on the Internet, I mostly followed instructions from here and here.
The power status information is directly provided from the UART pin without the need of writing additional software. UART must be enabled in ‘/boot/config.txt’ configuration file


enable_uart=1

Then I just connected a LED diode between UART pin and ground (trough a current limiting resistor of course).
Also the wake-up functionality is implemented by briefly connecting GPIO pin 6 to ground trough a normally-open push button.