Wednesday, October 10, 2012

Autoreplicación parte 2

Otra opción posible en cuanto a la autoreplicación (ver la primera parte aquí), es hacer una copia "live" de la carta SD con la cual boot el Pi (/dev/mmcblk0), sobre una otra carta del mismo tamaño o mas (por ejemplo 4GB boot -> carta 4GB o mas).

Aquí tengo una carta todavia no configurada (con raspi-config). Así, hay un mínimo de servicios en operación, y no hay necesidad de poner el sistema operativo en modo "usuario solo". Voy a hacer una otra copia sobre una carta SD en el lector de carta USB (/dev/sda):



Linux raspberrypi 3.2.27+ #160 PREEMPT Mon Sep 17 23:18:42 BST 2012 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
/usr/bin/xauth:  file /home/pi/.Xauthority does not exist

NOTICE: the software on this Raspberry Pi has not been fully configured. Please run 'sudo raspi-config'

pi@raspberrypi ~ $ ls /dev/sd*
/dev/sda  /dev/sda1
pi@raspberrypi ~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          1.8G  1.3G  347M  80% /
/dev/root       1.8G  1.3G  347M  80% /
devtmpfs         93M     0   93M   0% /dev
tmpfs            19M  220K   19M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            37M     0   37M   0% /run/shm
/dev/mmcblk0p1   56M   36M   21M  63% /boot
pi@raspberrypi ~ $ time sudo dd bs=1M if=/dev/mmcblk0 of=/dev/sda
3781+1 records in
3781+1 records out
3965190144 bytes (4.0 GB) copied, 793.701 s, 5.0 MB/s

real 13m13.810s
user 0m0.090s


He añadido "time" al frente de sudo dd para saber cuanto tiempo que requiere eso. En comparacion con el metodo de autoreplication del articulo precedente requiere mas o menos 2 veces mas tiempo:


fdion@raspberrypi ~ $ time sudo dd bs=1M if=2012-09-18-wheezy-raspbian.img of=/dev/sda
1850+0 records in
1850+0 records out
1939865600 bytes (1.9 GB) copied, 404.55 s, 4.8 MB/s

real 6m44.632s
user 0m0.020s
sys 0m33.330s


El método directa ("live") es mas lento, pero la ventaja es que no hay necesidad de usar 1.9GB simplemente para tener la imagen. Una vez que uno configura el pi con raspi-config, el método del articulo precedente es la única manera de hacer nuevas cartas. Sino hay riesgo de corrupción.

Tuesday, October 9, 2012

Autoreplicación

Parece que hay muchos problemas con hacer una carta SD para el Raspberry Pi.

Uno es a causa de la gran variedad de computadores y sistemas operativos. Por otra parte, hay muchas personas que no tengan otro computador, el Pi es el único.

He oído de grupos de usuarios que deben comprar unos cartas SD con Raspbian pre-instalado, sin manera de hacer la replicación de la carta para ayudar a otros.

En realidad, si uno pone la imagen de Raspbian sobre la carta SD, es posible hacer autoreplicación, es decir, que el Pi hace copias de la carta por si mismo.

 Si desean hacerlo, hay que comprar un lector de carta SD, similar al siguiente (con una carta SD de 16GB, pero el minimo es 2GB):



Y connectarlo (con cable o directo) al USB.



Hay que tener también al mínimo 2.5GB disponible. En vez de http://www.gtlib.gatech.edu/pub/raspberrypi/images/raspbian/2012-09-18-wheezy-raspbian/2012-09-18-wheezy-raspbian.zip seria una buena idea de eligir algo mas cerca en esta lista: http://downloads.raspberrypi.org/download.php?file=/images/raspbian/2012-09-18-wheezy-raspbian/2012-09-18-wheezy-raspbian.zip


fdion@raspberrypi ~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs           15G   11G  2.9G  80% /
/dev/root        15G   11G  2.9G  80% /
devtmpfs        109M     0  109M   0% /dev
tmpfs            22M  248K   22M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            44M     0   44M   0% /run/shm
/dev/mmcblk0p1   56M   35M   22M  62% /boot
fdion@raspberrypi ~ $ wget http://www.gtlib.gatech.edu/pub/raspberrypi/images/raspbian/2012-09-18-wheezy-raspbian/2012-09-18-wheezy-raspbian.zip
fdion@raspberrypi ~ $ unzip 2012-09-18-wheezy-raspbian.zip
fdion@raspberrypi ~ $ ls /dev/sd*
ls: cannot access /dev/sd*: No such file or directory
fdion@raspberrypi ~ $ ls /dev/sd*
ls: cannot access /dev/sd*: No such file or directory
fdion@raspberrypi ~ $ ls /dev/sd*
/dev/sda  /dev/sda1
fdion@raspberrypi ~ $ ls *.img
2012-09-18-wheezy-raspbian.img


El lector de SD es /dev/sda (si es sdb, hay que substituir of=/dev/sdb). Ahora si, estamos listos a grabar una carta SD del Pi:


fdion@raspberrypi ~ $ sudo dd bs=1M if=2012-09-18-wheezy-raspbian.img of=/dev/sda
1850+0 records in
1850+0 records out
1939865600 bytes (1.9 GB) copied, 428.218 s, 4.5 MB/s
fdion@raspberrypi ~ $ sudo sync


El sudo sync es muy importante. Sin hacerlo, la carta no operara.

Y es todo, la carta esta lista para distribuir a otra persona.

Tengo unos cartas listas a distribuir, pero con la imagen Raspbian en la carta, y así no hay que descargar nada, simplemente hacer el dd y el sync.

Si seria de ayuda a su grupo de usuario una carta SD así, puedo enviarles una. Tengo solo unos, y por eso voy a enviar a grupos que le necesitan realmente. Dejan un mensaje aquí con el nombre de su grupo de usuario, la manera de contactarlo y cuantas personas hay en el grupo.

Monday, October 8, 2012

O polifusivel e o Pi

Raspberry Pi esta concebido para usar 500 mA. E, para cada porta USB 100mA, para um total de 700 mA. Para proteger o Pi, há uma polifusível T075 (750 mA). F3 na imagem abaixo:




O que acontece com o seu computador quando você puxar muita energia nas portas USB? Se você tem uma fonte de alimentação de 700mA, não muito. O dispositivo USB não vai funcionar.

Mas se você tem uma fonte de energia capaz de mais de 1A?

O polifusível irá ativar e cortar o circuito.

Depois disso, você vai ter que esperar vários minutos a várias horas até aproximadamente o fusível de volta tem o estado normal.

Sunday, October 7, 2012

Pi with an adaFruit on top

Lots of I/O

Added a mcp23017 and an mcp3008 to an Adafruit prototyping card for the raspberry pi.


I have plenty of digital outs (16 extra) for the steppers for a reprap 3d printer and plenty of analog inputs (8) to measure temperatures and voltages.


Tuesday, October 2, 2012

ZFS file system on Raspberry Pi

FISH


I do a good bit of hardware integration with the web, with manufacturing equipment, with embedded systems and with big data set, or that can sustain multiple failures. Not necessarily all at once, but typically, people expect FISH from me :)

FISH is Fully Integrated Software and Hardware (btw, as a side note, the internal project at Sun to create appliances based on ZFS was known as FISHWorks). The Raspberry Pi is a cool piece of hardware, but I typically need stuff that is only (or mostly) found on Solaris and derived OSes, such as ZFS. I've been using ZFS for many years now, since the first public release on Solaris Nevada. ZFS scales and give you data integrity. And it can run on the largest systems known to man.

It scales


For example, I'm listening right now to ZFS Day's live video stream and hearing a talk about ZFS on the Sequoia supercomputer, which is the fastest supercomputer out there. They are using it as a native port, not using FUSE.

What is ZFS? 


Wikipedia: "ZFS is a combined file system and logical volume manager designed by Sun Microsystems. The features of ZFS include data integrity verification against data corruption modes, support for high storage capacities, integration of the concepts of filesystem and volume management, snapshots and copy-on-write clones, continuous integrity checking and automatic repair, RAID-Z and native NFSv4 ACLs. ZFS is implemented as open-source software, licensed under the Common Development and Distribution License (CDDL)."

From Supercomputers to $35 computers


So, ZFS scales at the highest level obviously. Well, it also scales down: I've been using a bit ZFS on the Raspberry Pi using FUSE, until I can get a Solaris derived OS ( such as illumos, smartos, openindiana, opensolaris etc) on the Raspberry Pi. That way, at least I have ZFS. Still missing zones, smf and dtrace, but it is a start.

Now just a reminder, the Pi only has 256MB total ram, and a BCM arm processor. So first thing first, we need to give as much ram to the OS as possible, and reduce the video buffer size:



I'm using a 240MB split on that Raspberry Pi since it is running only in text mode at the console, and I remote to it using ssh -X.


If you use the composite out you might want to use the 224MB split and definitely 192 or 128 using HDMI, but then at that point, you are chocking ZFS. That's 128 for OS and ZFS and whatever apps you are running...

Fully loaded


Altough Raspbian comes with a good amount of stuff preloaded, it was not intended to be used with FUSE out of the box, and ZFS was probably never on the radar screen of anybody. So let's start with adding the FUSE stuff and the libraries and tools we will need to build ZFS. This is the shortlist:


fdion@raspberrypi ~/zfs $ sudo apt-get install fuse-utils libfuse-dev libfuse2
fdion@raspberrypi ~/zfs $ sudo apt-get install libaio-dev libattr1-dev attr
fdion@raspberrypi ~/zfs $ sudo apt-get install git scons



If you build it...


So we have the prerequisites. Let's get the code, compile it and install the tools:


fdion@raspberrypi ~ $ mkdir zfs
fdion@raspberrypi ~ $ cd zfs
fdion@raspberrypi ~/zfs $ git clone https://bitbucket.org/cli/zfs-fuse-arm.git
fdion@raspberrypi ~/zfs $ cd zfs-fuse-arm/
fdion@raspberrypi ~/zfs/zfs-fuse-arm $ cd src
fdion@raspberrypi ~/zfs/zfs-fuse-arm/src $ scons
[a lot of stuff will scroll by]
fdion@raspberrypi ~/zfs/zfs-fuse-arm/src $ sudo scons install
[again, more stuff will scroll by]

Wow, it compiled (scons). And installed (sudo scons install). It's a good thing we are using the zfs-fuse-arm version, because the mainline wont go very far on the compile.

A demonstration, if you please? 


Well of course! Let's start the zfs-fuse daemon and create two virtual disks. I'm creating two 100M disks here using dd/ (this is on a slow SD card, rated 10MB/s). You could also use an actual /dev (like a pair of USB keys):


fdion@raspberrypi ~/zfs/zfs-fuse-arm/src/zfs-fuse $ sudo sh run.sh &

fdion@raspberrypi ~/zfs/zfs-fuse-arm/src/zfs-fuse $ cd
fdion@raspberrypi ~ $ cd zfs
fdion@raspberrypi ~/zfs $ mkdir test
fdion@raspberrypi ~/zfs $ cd test
fdion@raspberrypi ~/zfs/test $ dd if=/dev/zero of=fakedisk1 bs=1024k count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 10.2747 s, 10.2 MB/s
fdion@raspberrypi ~/zfs/test $ dd if=/dev/zero of=fakedisk2 bs=1024k count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 10.7517 s, 9.8 MB/s

Up to now we haven't done anything with ZFS per say. And basically to mirror two drives in ZFS and create a new storage out of that, all we have to do:


fdion@raspberrypi ~/zfs/test $ sudo zpool create mymirror mirror /home/fdion/zfs/test/fakedisk1 /home/fdion/zfs/test/fakedisk2


Now let's create a filesystem on that new zpool device, and mount it to a local folder in my home directory, change permissions so I can write to it and finally copy some files from /etc to my new filesystem:


fdion@raspberrypi ~/zfs/test $ cd
fdion@raspberrypi ~ $ mkdir myfilesystem
fdion@raspberrypi ~ $ sudo zfs create mymirror/myfilesystem -o mountpoint=/home/fdion/myfilesystem
fdion@raspberrypi ~ $ sudo chown fdion:pi myfilesystem/
fdion@raspberrypi ~/myfilesystem $ cp /etc/*.conf .
cp: cannot open `/etc/fuse.conf' for reading: Permission denied
fdion@raspberrypi ~/myfilesystem $ ls
adduser.conf          gssapi_mech.conf  libaudit.conf   pnm2ppa.conf
asound.conf           hdparm.conf       logrotate.conf  resolv.conf
ca-certificates.conf  host.conf         mke2fs.conf     rsyslog.conf
colord.conf           idmapd.conf       mtools.conf     sensors3.conf
debconf.conf          insserv.conf      nsswitch.conf   sysctl.conf
deluser.conf          ld.so.conf        ntp.conf        ts.conf
gai.conf              libao.conf        pam.conf        ucf.conf
fdion@raspberrypi ~/myfilesystem $ sudo zfs list
NAME                    USED  AVAIL  REFER  MOUNTPOINT
mymirror                191K  63.3M    22K  /mymirror
mymirror/myfilesystem  89.5K  63.3M  89.5K  /home/fdion/myfilesystem
fdion@raspberrypi ~/myfilesystem $ sudo zpool list
NAME       SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
mymirror  95.5M   196K  95.3M     0%  1.00x  ONLINE  -
fdion@raspberrypi ~/myfilesystem $ 




How cool is that? I now have a mirrored backup of my .conf files. Well, not quite. We are using fake disks, so if the SD card dies I loose all.

So next time we'll demo with actual USB drives.