#bananapi → On how compressed files should be used
I am among the lucky people who got back home from DebConf with a brand new computer: a Banana Pi. Despite the name similarity, it is not affiliated with the very well known Raspberry Pi, although it is a very comparable (although much better) machine: A dual-core ARM A7 system with 1GB RAM, several more on-board connectors, and same form-factor.
I have not yet been able to get it to boot, even from the images distributed on their site (although I cannot complain, I have not devoted more than a hour or so to the process!), but I do have a gripe on how the images are distributed.
I downloaded some images to play with: Bananian, Raspbian, a Scratch distribution, and Lubuntu. I know I have a long way to learn in order to contribute to Debian’s ARM port, but if I can learn by doing… ☻
So, what is my gripe? That the three images are downloaded as archive files:
0 gwolf@mosca『9』~/Download/banana$ ls -hl bananian-latest.zip \
Lubuntu_For_BananaPi_v3.1.1.tgz Raspbian_For_BananaPi_v3.1.tgz \ Scratch_For_BananaPi_v1.0.tgz -rw-r–r– 1 gwolf gwolf 222M Sep 25 09:52 bananian-latest.zip -rw-r–r– 1 gwolf gwolf 823M Sep 25 10:02 Lubuntu_For_BananaPi_v3.1.1.tgz -rw-r–r– 1 gwolf gwolf 1.3G Sep 25 10:01 Raspbian_For_BananaPi_v3.1.tgz -rw-r–r– 1 gwolf gwolf 1.2G Sep 25 10:05 Scratch_For_BananaPi_v1.0.tgz </code>
Now… that is quite an odd way to distribute image files! Specially when looking at their contents:
0 gwolf@mosca『14』~/Download/banana$ unzip -l bananian-latest.zip
Length Date Time Name
--------- ---------- ----- ----
2032664576 2014-09-17 15:29 bananian-1409.img
2032664576 1 file
0 gwolf@mosca『15』~/Download/banana$ for i in Lubuntu_For_BananaPi_v3.1.1.tgz \
Raspbian_For_BananaPi_v3.1.tgz Scratch_For_BananaPi_v1.0.tgz do tar tzvf $i; done -rw-rw-r– bananapi/bananapi 3670016000 2014-08-06 03:45 Lubuntu_1404_For_BananaPi_v3_1_1.img -rwxrwxr-x bananapi/bananapi 3670016000 2014-08-08 04:30 Raspbian_For_BananaPi_v3_1.img -rw——- bananapi/bananapi 3980394496 2014-05-27 01:54 Scratch_For_BananaPi_v1_0.img </code>
And what is bad about them? That they force me to either have heaps of disk space available (2GB or 4GB for each image) or to spend valuable time extracting before recording the image each time.
Why not just compressing the image file without archiving it? That is,
0 gwolf@mosca『7』~/Download/banana$ tar xzf Lubuntu_For_BananaPi_v3.1.1.tgz
0 gwolf@mosca『8』~/Download/banana$ xz Lubuntu_1404_For_BananaPi_v3_1_1.img
0 gwolf@mosca『9』~/Download/banana$ ls -hl Lubun*
-rw-r--r-- 1 gwolf gwolf 606M Aug 6 03:45 Lubuntu_1404_For_BananaPi_v3_1_1.img.xz
-rw-r--r-- 1 gwolf gwolf 823M Sep 25 10:02 Lubuntu_For_BananaPi_v3.1.1.tgz
Now, wouldn’t we need to decompress said files as well? Yes, but thanks to the magic of shell redirections, we can just do it on the fly. That is, instead of having 3×4GB+1×2GB files sitting on my hard drive, I just need to have several files ranging between 145M and I guess ~1GB. Then, it’s as easy as doing:
0 gwolf@mosca『8』~/Download/banana$ dd if=<(xzcat bananian-1409.img.xz) of=/dev/sdd
And the result should be the same: A fresh new card with Bananian ready to fly. Right, right, people using these files need to have xz installed on their systems, but… As it stands now, I can suppose current prospective users of a Banana Pi won’t fret about facing a standard Unix tool!
(Yes, I’ll forward this rant to the Banana people, it’s not just bashing on my blog :-P )
[update] Several people (thanks!) have contacted me stating that I use a bashism: The <(…) construct is specific to Bash. If you want to do this with any other shell, it can be done with a simple pipe:
$ xzcat bananian-1409.img.xz | dd of=/dev/sdd
That allows for less piping to be done on the kernel, and is portable between different shells. Also, a possibility would be:
$ xzcat bananian-1409.img.xz > /dev/sdd
Although that might not be desirable, as it avoids the block-by-block nature of dd. I’m not sure if it makes a realdifference, but it’s worth saying :)
And yes, some alternatives for not unarchiving the file — Here in the blog, an anon commenter suggests (respectively, for zip and .tar.gz files):
$ dd if=<(unzip -p bananian-latest.zip) of=/dev/sdd
$ dd if=<(tar -xOf Lubuntu_For_BananaPi_v3.1.1.tgz) of=/dev/sdd
And a commenter by IRC suggests:
$ paxtar -xOaf Raspbian_For_BananaPi_v3.1.tgz Raspbian_For_BananaPi_v3_1.img | sudo dd bs=262144 of=/dev/…
Anonymous 2014-09-25 10:28:08
Just use dd if=<(unzip -p
dd if=<(unzip -p bananian-latest.zip) of=/dev/sdd
dd if=<(tar -xOf Lubuntu_For_BananaPi_v3.1.1.tgz) of=/dev/sdd
As there is only a single file in each of the archives this works nicely. In case of multiple files, one can simply add the file to be extracted to the command.