Wednesday, April 24, 2013

On Cleaning Ubuntu's boot partition

I got two Ubuntu servers which have been shutdown for months. Upon powering them up, I did the usual "apt-get update; apt-get upgrade" on both but received the following error:

gzip: stdout: No space left on device

Did a "df -kh" and noticed the /boot partition is almost full. 

root@web-host:/boot# df -kh
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/web--host-root   70G  9.8G   56G  15% /
... ... 
/dev/sda1                   228M  224M     0 100% /boot

Note: Ubuntu's default /boot partition size is 228MB, and the /boot directory stores previous (unused) versions of linux in case if they are needed. 

To clean up the /boot directory:

1. Use "apt-get autoremove" and problem solved.

2. In case if this doesn't work, I found a web post with a script to remove all unused linux images.

#dpkg --get-selections|grep 'linux-image*'|awk '{print $1}'|egrep -v "linux-image-$(uname -r)|linux-image-generic" |while read n;do apt-get -y remove $n;done

While the following error still occurs occassionally, the /boot usage is reduced to 26%.
update-initramfs: Generating /boot/initrd.img-3.2.0-33-generic
gzip: stdout: No space left on device

Subsequent "apt-get update; apt-get upgrade" are successful and returns no error. 

P.S. There's this program called GParted which comes with Ubuntu Live CD (ubuntu desktop 13.0.4 ships with Gparted v.0.12.1). It allows for resizing of /boot partition. 

However, if the Ubuntu servers have Logical Volume Manager (LVM) on its sda5 partition (sitting on top of sda2), then use Gparted's own live CD (v.0.14) which supports resizing LVM.

Thursday, November 22, 2012

Raspberry Pi

A colleague recently told me about Raspberry Pi originally developed for educational purposes. 

It is a credit card low cost computer running on a stripped down version of Debian. Considering its price and it is running on open source operating system, it definitely caught my attention.

Herewith one of the reviews on this product. 

There are several articles written about cool ideas to use this hardware (such as here, and here), including remote security camera, media streamer, internet radio etc.

Based on what I have read so far, this board should be able to deliver any applications or functions that is not overly CPU demanding. 

On a personal note, I am particularly fond of its low-noise aspect, such that it can sit pretty well anywhere in my home without generating too much disturbances. 

I did a quick calculation on the cost of building one of these including casing and flash drive, which works out to be less than $75.00 (but I have not considered the delivery cost of Pi itself): 

Cost ($)
Ebay AU
32GB SD card
Ebay AU

Getting started
To have it up and running, there are several getting started guides available online, and here is a quite comprehensive one with pictures illustrating the steps. 

In summary, it is as simple as preparing the operating system on the SD card (from either a windows or linux machine), plug it in, power it up and off you go. 

Others Tech References
- Design Spark provides a schematics capture and PCB layout tool for free. 
- I found a guide detailing building GNU/Linux on ARM machine from the ground up. 
Gooseberry - an alternative to Raspberry Pi.

It's definitely on my agenda. 

Monday, November 19, 2012

OwnCloud on Ubuntu. Media Server (miniDLNA). Remote Access

Recently I took a half an hour video using my Samsung S3. The video was approximately 3.6GB, which is  close to the upper limit offered by several publicly available cloud/ online storage services such as Dropbox, Google Drive, or Ubuntu One.

That is enough incentive for me to build my own private cloud, considering my 1.5TB harddrive is the only storage limitation and I have full ownership over its security.

OwnCloud Server

I came across OwnCloud, an open source, php web based software.

Owncloud is a centralized storage solution: the software automatically stores your files onto its server.

It also has its own clients for linux, windows, android etc, so it's quite flexible in my opinion.

On my ubuntu server running on 12.04.1 LTS (with LAMP stack), it's installation is simply:

root@ubuntu:/opt# apt-get install owncloud

At the time of writing, this gives you ownCloud version 3 (the latest version is owncloud 4), so keep in mind the compatible sync clients's version is 1.05

Upon successful installation, OwnCloud can be accessed via web interface http://server-ip-address/owncloud. All file upload, download and folder creation can be done here: 

OwnCloud Sync Clients
OwnCloud's web interface allows for max of 2MB upload, I understand this as a PHP limitation. 

OwnCloud has several sync clients available for different OSes, which don't have such limitations. So far I have tried two clients (both version 1.05 for Windows and Linux respectively) with the following findings:

1. Windows 8

Upon first setting up owncloud clientsync account, I encountered this client and server timing out of sync error. This prohibits the server and client to synchronize their files.

As a work around, I have set up the Ubuntu server as an NTP server. Then I pointed my windows machine towards it. 

For reference:
# apt-get install ntp

Start/ stop NTP
# /etc/init.d/ntp --help
Usage: /etc/init.d/ntp {start|stop|restart|try-restart|force-reload|status}

As client
# ntpdate

(In all fairness, it turned out the Windows machine was configured to the incorrect timezone, hence prohibiting it from synchronizing with the server).

2. Ubuntu Laptop LTS 12.04
Having installed the ownCloud sync client on my netbook, I have encountered no synchronization issues (apparently the netbook already has a public NTP working properly). 

I have left my netbook switched on allowing it to be sync for the entire day. Did a tcpdump to confirm there are https traffic being exchanged between the client and server.

The sync is finally successful. I suspect the initial sync took longer than the subsequent incremental updates. 

Home Access (miniDLNA)

Leveraging the Ethernet over Power setup I previously posted, it makes sense to enable DLNA on my OwnCloud server. This essentially converts my server to become a centralized storage, which allows for access from all devices via DLNA.

MiniDLNA is a light weight DLNA server software, which installation is as simple as running "apt-get install minidlna". A google search of "dlna ubuntu" returns this quick tip as its first result covering all the essential configurations. 

For my setup, by default, OwnCloud stores its client files in the following directory:
/var/lib/owncloud/data/root/files/ clientsync

In addition, I have also created a "music" and "photos" folders under the same directory. These directories are added to the media directories of minidlna (/etc/minidlna.conf)

# set this to the directory you want scanned.
# * if have multiple directories, you can have multiple media_dir= lines
# * if you want to restrict a media_dir to a specific content type, you
# can prepend the type, followed by a comma, to the directory:
# + "A" for audio (eg. media_dir=A,/home/jmaggard/Music)
# + "V" for video (eg. media_dir=V,/home/jmaggard/Videos)
# + "P" for images (eg. media_dir=P,/home/jmaggard/Pictures)

Notice I have set them as "A" for audio and "P" for images. 

At this point, if I run minidlna, the server returns an “Media directory not accessible!" error .

There is a post on the owncloud community forum describing the fix - by adding both root and minidlna users to the group www-data:
root@ubuntu:/opt# usermod -a -G www-data root
root@ubuntu:/opt# usermod -a -G www-data minidlna

Now, apply -R option to force a full rescan, before restarting minidlna:
root@ubuntu:/opt# minidlna -R

root@ubuntu:/opt# /etc/init.d/minidlna force-reload
* Restarting DLNA/UPnP-AV media server minidlna [ OK ]

/var/log/minidlna.log confirms file scan is successful:

[2012/11/17 14:23:26] minidlna.c:155: warn: received signal 15, good-bye
[2012/11/17 14:23:26] minidlna.c:907: warn: Starting MiniDLNA version 1.0.21 [SQLite 3.7.9].
[2012/11/17 14:23:26] minidlna.c:935: warn: Creating new database...
[2012/11/17 14:23:26] minidlna.c:1002: warn: HTTP listening on port 8200
[2012/11/17 14:23:26] scanner.c:719: warn: Scanning /var/lib/owncloud/data/root/files/music
[2012/11/17 14:23:26] scanner.c:790: warn: Scanning /var/lib/owncloud/data/root/files/music finished (166 files)!
[2012/11/17 14:23:26] scanner.c:719: warn: Scanning /var/lib/owncloud/data/root/files/photos
[2012/11/17 14:23:28] scanner.c:790: warn: Scanning /var/lib/owncloud/data/root/files/photos finished (1359 files)!

Remote Access
As mentioned earlier, there are largely two methods for ownCloud clients to access OwnCloud server - web access and sync client. 

There are some useful tweaks which enhance the security and ease of remote access:

1. Enhance security by enabling SSL (and redirecting all HTTP to HTTPS)

2. Enabling remote access by utilizing free dynamic dns services as covered in my earlier post

For example, rather than configuring https://Server-LAN-IP/owncloud, configure https://dynamicDNS-URL:some-random-port/owncloud as the owncloud server's address.

Stating the obvious, the dynamicDNS-URL is intended to be accessible via the public internet. That also means you can access your ownCloud from anywhere in the world with internet connectivity. 

Further notes
I recall enabling SSL on my Apache2 server involved a couple of steps, from creating SSL certificate to enabling the corresponding module in Apache2 software.
It is a worthwhile topic which I may write another post on when I get around to it. 

HP mini 1000 - Ubuntu 12.04 LTS

A quick post on my HP mini 1000 network, which I first blogged (post) in the beginning of this year.

First time I started it up in ten months, the software manager automatically offered to upgrade it to 12.04 LTS. The rest was point and click and a couple of hours of waiting - which has been really worthwhile:

Giving credit to Ubuntu, the latest LTS version has fixed at least two bugs:
1. The wireless connection is functioning properly and its icon correctly reflects its status.
2. The little blue LED button which enables/ disables the wireless connection now functions properly.

Not bad for a three years old Intel atom netbook as I am planning to do more things with it.

Dynamic DNS - dnsdynamic and no-ip

Dynamic DNS (ddns) allows for remote access to publicly hosted server with dynamic IP address, using a pre-defined URL. 

I am covering two dynamic DNS providers offering free services, and how to setup their ddns clients respectively:

1. No-IP
No-IP comes with its own linux ddns client, which can be installed using "apt-get noip2". 
To manually setup your details, run noip2 with the "-C" option. 

root@web-host:# noip2 -h

USAGE: noip2 [ -C [ -F][ -Y][ -U #min]
        [ -u username][ -p password][ -x progname]]
        [ -c file][ -d][ -D pid][ -i addr][ -S][ -M][ -h]

Version Linux-2.1.9
Options: -C               create configuration data
         -F               force NAT off
         -Y               select all hosts/groups
         -U minutes       set update interval
         -u username      use supplied username
         -p password      use supplied password
         -x executable    use supplied executable
         -c config_file   use alternate data path
         -d               increase debug verbosity
         -D processID     toggle debug flag for PID
         -i IPaddress     use supplied address
         -I interface     use supplied interface
         -S               show configuration data
         -M               permit multiple instances
         -K processID     terminate instance PID
         -z               activate shm dump code
         -h               help (this text)

Note: the /usr/local/etc/noip2.conf returns some seemly encrypted text, so it's not meant to be changed. 

DNSdynamic service uses ddclient in ubuntu. Herewith my configuration for reference:

root@ubuntu:# cat /etc/ddclient.conf
# Configuration file for ddclient generated by debconf
# /etc/ddclient.conf

login= (username)

Replace the corresponding fields with your own account details.

P.S. Remember to set up port forwarding if your servers are sitting behind NAT.