Sunday, May 25, 2014

Moving the linux filesystem OpenWrt to the SD card

Standard the OS is on the flash of the Yun. It is possible to move (most) to the SD card.

Advantages are:
- much more space, allowing to install many more packages
- the flash can be written only a limited amount of times. If you move the OS to the SD card, this is no longer an issue. The SD card also has a limited amount of writes, but typically more than the flash, and it is much easier to replace the SD card than the flash.

Before starting, create at least one ext4 partition on the SD card (see e.g. http://myyafa.blogspot.be/2014/05/create-and-format-partitions-on-yun-sd.html)

On the Yun do (pivot root option):
opkg update
opkg install block-mount
cd /
mkdir -p /tmp/cproot
mount --bind / /tmp/cproot
tar -C /tmp/cproot -cvf - . | tar -C /mnt/sda1 -xf -
umount /tmp/cproot
edit the file /etc/config/fstab and add:


config mount
        option target        /
        option device        /dev/sda1
        option fstype        ext4
        option options       rw,sync
        option enabled       1
        option enabled_fsck  0
That's it. Reboot and the OS should now reside on the SD. If you still want to access the old filesystem on the flash (this is still used at boot for example) you can do
cd /
mkdir original-boot
and add
config mount
        option target   /original-boot
        option device   /dev/mtdblock3
        option fstype   jffs2
        option options  rw,sync
        option enabled  1
        option enabled_fsck     0
to the /etc/config/fstab file (see also http://forum.arduino.cc/index.php?topic=289215.0) (the one on the SD card)

create and format partitions on the Yun SD card

I have an 8GB SD card, I want to make a 4GB and a 3GB partition (it currently has only 1 8GB parition). With the SD card in the Yun:
fdisk /dev/sda
delete my existing partition:
Command (m for help): d
Selected partition 1
Partition 1 is deleted
create the 2 new ones:
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-15523839, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-15523839, default 15523839): +4G
Partition 1 of type Linux and of size 4 GiB is set

Command (m for help): n   
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 2): 
Using default value 2
First sector (8390656-15523839, default 8390656): 
Using default value 8390656
Last sector, +sectors or +size{K,M,G} (8390656-15523839, default 15523839): +3G
Partition 2 of type Linux and of size 3 GiB is set
save:
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
reboot:
reboot
format the new paritions:
opkg update
opkg install mtd-utils
opkg install e2fsprogs

mkfs.ext4 -L YunSD1 /dev/sda1
mkfs.ext4 -L YunSD2 /dev/sda2

update: when I tried this again in 2015, I had to do:

umount /dev/sda1
umount /dev/sda2

prior to the mkfs commands

Saturday, May 24, 2014

Upgrade Yun with new image (OpenWrt-Yun 1.0)

There is a new image for the Yun with important fixes, and better link to OpenWrt.
More info and detailed installation guidelines can be found on http://forum.arduino.cc/index.php?topic=235360.msg1693350#msg1693350 Before doing the procedure I saved the installed packages to a file:
opkg list-installed
Next I formatted my SD card(not needed, but I want a clean start). First I did this on my Ubuntu PC but this gave issues with user groups and permissions. So I did the formatting on my Yun directly:
df
umount /mnt/sda1
mkfs.ext4 -L YunSD /dev/sda1
note the /dev/sda1 iso /mnt/sda1 for the mkfs command.
mkdir /mnt/sda1/arduino

Next, extract the zip file for the update into the root folder of the SD card.

ssh to the Yun and execute:
run-sysupgrade /mnt/sda1/openwrt-ar71xx-generic-yun-16M-squashfs-sysupgrade.bin
result is (nothing needs to be done when it looks like there is a prompt with the Writing from ...:
Sending TERM to remaining processes ... uhttpd dbus-daemon dnsmasq thd ntpd uSDaemon sftp-server sleep syslogd klogd hotplug2 procd ubusd netifd 
Sending KILL to remaining processes ... 
Switching to ramdisk...
Performing system upgrade...
Unlocking firmware ...

Writing from  to firmware ...     
Upgrade completed
Rebooting system...
Rebooting didnt seem to happen automatically. Power cycled and after a while I saw the USB led on, a sign of the new image. The Yun is completely fresh, so you need to start all over, connecting to the Yun wireless network, enter default password arduino, etc...