April 7, 2015 Hatem

Proof of concept : A $30 dollars DIY Personal Cloud Server

Personal cloud devices are available today in the market for different prices depending on the storage size, let’s say around $200 the 4TB. But it happens that I have already a storage device that I am happy with, and a mini PC in a stick (MK802) that came with Android 4.0 pre-installed.

You can find the Android mini PC in eBay for less than $30, and we will need just a micro SD card to install the operation system, so we can replace the Android with an embedded linux distribution. Finally I’ll transform it into a personal cloud server to sync my files from PC/Mac/Android …etc.

An easy way to do this is to install the system on an SD card then we can easily expand storage using USB drives. For example you can see actually in my MK802 I have already about 3G available for data :

root@MK802:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          3.6G  878M  2.6G  26% /
/dev/root       3.6G  878M  2.6G  26% /
devtmpfs        153M     0  153M   0% /dev
tmpfs            31M  200K   31M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            62M     0   62M   0% /run/shm
tmpfs           154M     0  154M   0% /tmp

It could be enough , or I can easily expand it for example using a 1T USB drive :

root@MK802:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          3.6G  916M  2.5G  27% /
/dev/root       3.6G  916M  2.5G  27% /
devtmpfs        153M     0  153M   0% /dev
tmpfs            31M  200K   31M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            62M     0   62M   0% /run/shm
tmpfs           154M     0  154M   0% /tmp
/dev/sda2       782G  120G  662G  16% /media/usb0
/dev/sda3       4.9G  9.8M  4.6G   1% /media/usb1
/dev/sda5       143G  5.7G  138G   4% /media/usb2

Hardware used :

  • MK802 : ARM based Cortex-A8 you can find it with 512MB, 1GB RAM
  • Micro SD card 4GB

Software :

  • Debian Wheezy
  • Sunxi-BSP
  • OwnCloud server

How to :

I used an Ubuntu 14.04 to get my system up and running, and it should be working fine with other version of Ubuntu, Debian, or any other Linux distribution. The next commands will be run as root, so (#sudo su) to switch to root.

First we need to get necessary packages to build our system :

# apt-get install qemu-user-static binfmt-support binutils-arm-linux-gnueabihf gcc-4.7-arm-linux-gnueabihf-base \
g++-4.7-arm-linux-gnueabihf gcc-arm-linux-gnueabihf cpp-arm-linux-gnueabihf libusb-1.0-0 libusb-1.0-0-dev git \
wget fakeroot kernel-package zlib1g-dev libncurses5-dev debootstrap

The minimal Debian Wheezy plus the necessary packages to get my personal cloud running will need around 600MB, so a 1G image is enough for my rootfs :

# mkdir ~/MK802
# cd ~/MK802
# mkdir rootfs
# dd if=/dev/zero of=rootfs.img bs=1M count=1024
# mkfs.ext4 -F rootfs.img
# mount -o loop rootfs.img rootfs

The next command will install minimal Debian inside the image :

# debootstrap --verbose --arch armhf --variant=minbase --foreign stable rootfs http://ftp.debian.org/debian

We can chroot now to our image and run the second stage of debootstrap :

# cp /usr/bin/qemu-arm-static rootfs/usr/bin/
# mkdir rootfs/dev/pts
# mount -t devpts devpts rootfs/dev/pts
# mount -t proc proc rootfs/proc
# chroot rootfs
I have no name!@hatem-laptop:/# /debootstrap/debootstrap --second-stage

In the second stage debootstrap will be unpacking and configuring different packages already installed. Notice that our new prompt indicate that the new system have “no name”, and we will fix all this shortly.

Let’s set the apt sources and install some essential stuff:

# echo "deb http://ftp.debian.org/debian/ wheezy main contrib non-free" > /etc/apt/sources.list
# echo "deb-src http://ftp.debian.org/debian/ wheezy main contrib non-free" >> /etc/apt/sources.list
# apt-get update
# apt-get install vim ntp udev netbase ifupdown iproute openssh-server iputils-ping net-tools wget ntpdate less \
console-tools module-init-tools apt-utils dialog locales isc-dhcp-client wireless-tools wpasupplicant man-db automount

We don’t need the .deb files anymore, so we can remove them already :

# apt-get clean

Set a 123 root password 😛

# passwd root

Create a new /etc/fstab, which should look something like this:

# /etc/fstab: static file system information.
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/root      /               ext4    noatime,errors=remount-ro 0 1
tmpfs          /tmp            tmpfs   defaults          0       0

Configure wireless so we can easily ssh our system by adding to /etc/interfaces:

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet dhcp
       wpa-ssid yourssid
       wpa-psk ***************************

To generate your wpa-psk you can replace yourssid and yourpassword below :

# wpa_passphrase yourssid yourpassword

Then simply replace the asterisks with the psk value.

We can also set the new hostname in /etc/hostname and replace your current hostname with MK802 or the hostname of your choice:

# vi /etc/hostname

Once you’re finished, leave the chroot environment with exit or <ctrl-d> and create a tarball of the newly created root filesystem:

# umount rootfs/proc
# umount rootfs/dev/pts
# cd rootfs
# tar -cvz * -f ../mk802rootfs.tgz

The system we created is about 296M which give us a compressed rootfs of about 100M. I told you that our system will be about 600M, that’s the Apache, MySQL and PHP that we will install later.  For now I’ll just build the kernel and bootloader then load everything in our micro SD. The easiest way is to use sunxi-bsp :

# git clone --recursive git://github.com/linux-sunxi/sunxi-bsp.git
# cd linux-sunxi
# ./configure mk802-1gb
# make

If everything worked out fine, we will find an hwpack under sunxi-bsp/output/mk802-1gb_hwpack.tar.xz, so we are ready to write everything to SD card (which is /dev/sdb in my example):

# scripts/sunxi-media-create.sh /dev/sdb sunxi-bsp/output/mk802-1gb_hwpack.tar.xz ../mk802rootfs.tgz

Our system is ready, just plug the micro SD and boot the device.  You can see below the MK802 connected to my TV :


The text is cropped in the beginning because the TV setting was in 16/9 while I am in ternminal, just changed the normal display and it’s fixed. You can see below that my MK802 is connected to internet :


MK802 is connected and identified, now I can ssh to my new system :

# ssh root@mk802
root@mk802's password:

In the second part of the installation, we will simply install and configure apache, php and mysql :

# apt-get install apache2 php5 mysql-server php5-mysql php5-gd

Download and install ownCloud :

# cd /var/www/
# wget https://download.owncloud.org/community/owncloud-8.0.2.zip
# unzip owncloud-8.0.2.zip
# rm -f owncloud-8.0.2.zip
# mysql -u root -p
mysql>create database owncloud;

Now just point your browser to http://mk802/owncloud/ and if everything is okay you should see the installation page which is very straightforward. Follow instructions and your personal cloud is ready :


I did not dig into installation details of the LAMP stack and ownCloud software, since it’s not the purpose of this article, but you can find in details installation instructions and recommendations in the ownCloud.org website. I used this installation at home and synced files from my desktop easily without any problems. ownCloud have Client available for PC/MAC/Linux/Android/iOS even if the mobile ones are paid ($1) but it’s totally worth it.

As I mentioned in the title, this is a proof of concept. It is not in anyway a recommendation for the MK802 or for Debian Wheezy, or for the ownCloud stack. Lots of boards available and could be easily used in the same way such as Raspi, PCDuino, or others. The same for the OS and the personal cloud software. However every time you have a device that will work permanently for a very long period, make sure you add heatsinks, and possibly a fan.

Feel free to share your experience.

, , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

(HBY) Consultancy