How do I revert Arduino Yun SD expansion?

Hiya,

I've got an Arduino Yun that I have expanded using the instructions on this page:

Now at the time I was running the sketch, I chose the wrong value for the MB partition size and ended up having a very small partition for saving data and a very large Unix partition (see below).

root@Arduino:~# df -h / /mnt/sda1
Filesystem                Size      Used Available Use% Mounted on
rootfs                    7.2G    237.0M      6.6G   3% /
/dev/sda1               199.8M         0    199.8M   0% /mnt/sda1

I have tried to reset my Yun by doing a 30sec hold on the WLAN button, but this does not seem to have an effect as far as the partitioning goes, I also cannot start the Arduino unless the SD card is inserted.

Any ideas how to revert the SD expansion?

Thanks!
Steven de Salas
http://desalasworks.com

Have you tried to expand the Yún disk space again with another size value?

sdesalas:
Any ideas how to revert the SD expansion?

From the forum thread discussing the topic: http://forum.arduino.cc/index.php?topic=236696.0

[quote author=Federico Fissore date=1398843712 link=msg=1702476]If you encounter any error and would like to restore your yun to its previous state, all you need to do is to reboot it with the SD card UNplugged, then edit file /etc/config/fstab removing the following section

config mount
 option target '/overlay'
 option device '/dev/sda2'


 option fstype 'ext4'
 option enabled '1'
 option enabled_fsck '0'
 option options 'rw,sync,noatime,nodiratime'

and reboot once more
[/quote]

I have tried to reset my Yun by doing a 30sec hold on the WLAN button, but this does not seem to have an effect as far as the partitioning goes

It's not clearly stated, but be aware that the 5 second and 30 second WLAN RST presses only work when the Yun is fully booted up - it's not like a lot of systems where you press and hold a reset button during power up. This often trips people up. Wait until the Yun is fully booted before you start to press the button. The reset process can take some time, so make sure you give it plenty of time to perform the reset operation and boot back up again before removing power or resetting it.

That being said, I don't know whether the 30 second reset really does revert the disk expansion.

I also cannot start the Arduino unless the SD card is inserted.

Then you may have an additional issue, as restarting without the card is the first step in reversing the disk expansion. I would suggest that you load the YunSerialTerminal example sketch, and start up the serial monitor. Then, tap the YUN RST button and let it (try to) boot up without the SD card. Finally, copy all of the boot messages from the serial monitor and post them here. It will help us figure out why it's not booting.

tim9510019:
Have you tried to expand the Yún disk space again with another size?

One of the first things the expansion sketch does is check to see if the expansion is already set up. If so, the operation aborts. You can't re-run the operation without manually reverting the changes as described above.

Thanks ShapeShifter, that's really helpful advise. I'll see what happened with the fstab file and get you those bootup logs.

Steven

sdesalas:
Thanks ShapeShifter, that's really helpful advise. I'll see what happened with the fstab file and get you those bootup logs.

Steven

Thanks for your help ShapeShifter.

It seems like I was getting confused because I did the hard reset (30s press WLAN RST button) with the SD card inserted, so I was looking for it to appear as a WLAN AP when I took the SD card back out and booted it but it was actually on my home WIFI network.

This is what the board is doing at present.

BOOTING WITH THE SD CARD INSERTED

It seems like the 30s WLAN reset removed the changes added by the ExpandingYunDiskSpace tutorial.

log in as: root
root@192.168.240.1's password: (arduino - the default password)

root@Arduino:~# cat /etc/config/fstab
config global automount
        option from_fstab 1
        option anon_mount 1

config global autoswap
        option from_fstab 1
        option anon_swap 0

root@Arduino:~#

BOOTING WITH THE SD CARD OUT

Once I take the SD card out, the Arduino Yun seems to return to the state before doing the hard reset.

log in as: root
root@10.0.0.62's password: (****** - password I was using before hard reset)

(OpenWrtLogo)

root@Arduino:~# cat /etc/config/fstab

config global 'automount'
        option from_fstab '1'
        option anon_mount '1'

config global 'autoswap'
        option from_fstab '1'
        option anon_swap '0'

config mount
        option target '/overlay'
        option device '/dev/sda2'
        option fstype 'ext4'
        option enabled '1'
        option enabled_fsck '0'
        option options 'rw,sync,noatime,nodiratime'

root@Arduino:~#

See attached dump from the startup logs.

For those interested I also found an interesting on post on the matter.

I think I’ll try doing a hard reset with the sd card out next removing the offending text on /etc/config/fstab as per Federico Fisore’s comment. See how I go…

yun.expansion.reset.startuplog.withsd.txt (12 KB)

yun.expansion.reset.startuplog.withoutsd.txt (14.9 KB)

Yep I can confirm that removing the config mount section on /etc/config/fstab and doing a soft reset (YUN RST) worked fine.

I used nano for this as I find it easier for editing files than vi.

root@Arduino:~# nano /etc/config/fstab

The Arduino is at the same state as before I started.

I'm now in the process of reformatting the SD card for another try - its clearly got a bootable partition that I want to remove before putting it back in.

sdesalas:
its clearly got a bootable partition that I want to remove before putting it back in.

No, that's not the way it works - you are not booting from the SD card.

You are still booting using the built-in bootloader, and the internal file system. Whether or not you have expanded the system disk space, the initial boot sequence is the same: the kernel is loaded from the internal file system, and part way through the remaining startup process, the file system settings are checked. It is at this point that the system overlay settings are found in the fstab file system configuration, and the SD card system is mounted. As I understand it, the SD card overlays (not replaces) the internal file system. When files are read, it looks on the SD card first, and if not found it looks for the file on the internal file system. When writing files are written to the SD card.

I'm sure that was a gross oversimplification, but the main point is that you are not booting from the card. As long as you have removed the overlay settings from the internal file system's fstab, it will not try to access your SD card as a system volume. I think you are safe to just repeat the process, and it will totally reformat your card with the new settings automatically.

More info: ExtRoot: How it works [Old OpenWrt Wiki]

sdesalas:
Yep I can confirm that removing the config mount section on /etc/config/fstab and doing a soft reset (YUN RST) worked fine.

I used nano for this as I find it easier for editing files than vi.

root@Arduino:~# nano /etc/config/fstab

The Arduino is at the same state as before I started.

I'm now in the process of reformatting the SD card for another try - its clearly got a bootable partition that I want to remove before putting it back in.

Do it without remove SD card.

Mount internal flash file system first:

/bin/mkdir -p /mnt/mtdblock3
/bin/mount -t jffs2 /dev/mtdblock3 /mnt/mtdblock3
nano /mnt/mtdblock3/etc/config/fstab

Revert boot to internal flash

Hi guys,

I tried removing the overlay config on /etc/config/fstab after booting with the card out, then formatting the SD card (clearing all partitions) and then re-running the YunDiskSpaceExpander.ino script.

All worked fine.

Here is my partition breakdown which is more along the lines of what I intended.

root@Arduino:~# df -h / /mnt/sda1
Filesystem                Size      Used Available Use% Mounted on
rootfs                  777.0M     52.0M    686.1M   7% /
/dev/sda1                 6.6G     16.0K      6.6G   0% /mnt/sda1

ShapeShifter: Thanks for the tip about the overlay code sitting on the SD card (rather than a whole boot partition). The thing that got me was the fact the system was actually using different root passwords depending on which was it booted. Didn't know it was possible to do something like that but I guess it makes sense and saves resources.

sdesalas:
The thing that got me was the fact the system was actually using different root passwords depending on which was it booted.

Not just different passwords, but they can have different network settings and SSID names, different node names, and many other changes between the two systems - it can certainly get confusing. Once the operating system kernel is loaded, and the overlay partition is mounted, anything that is loaded/started/configured after that point can be different.

The fact that the kernel is loaded from the on-board file system, and then the rest of the processes are launched from the overlay system has a subtle implication that is easy to miss. The various daemons and utilities are built and linked to a specific set of libraries, that may be dependent on the version of the kernel - certain system calls by utilities and processes make calls directly into the kernel. That means the kernel that is loaded in memory (early on, from the internal file system) must match the executable files that are on the overlay system.

This means that performing a system upgrade can be a complicated process: if you upgrade the system while booted with the SD card installed, you’ll update the kernel on the SD card (which isn’t used) but not the kernel on the internal flash (which is used.) If you upgrade the system while booted without a card, you’ll upgrade the system executables on the internal flash (most of which aren’t used) but won’t upgrade the system executables on the SD card (which are used.) It would be very easy to get the two file systems out of sync. I’ve seen dire warnings on the OpenWRT site about this happening, but I haven’t really figured out the solution. The safest bet might be to install any upgrades while the SD card is not inserted, and then perform the disk expansion over again from scratch - it’s the most reliable way to make sure the two systems are compatible.