ExtendedRootFilesystem

  1. How to upgrade the internal memory by extending the root filesystem to a memory card
    1. Requirements:
    2. Overview of what we're going to do:
    3. Before we begin - Disclaimer:
    4. First Step - Preparing the memory card:
    5. Second Step - Automounting the memory card:
    6. Third Step - Swapping out the root filesystem:
    7. If it worked but you want to revert to the original state:
    8. And now, the script:
  2. a. k. a. Wolfram Ravenwolf
  3. How to create and use a swap file together with an Extended Root Filesystem
  4. some user experience
  5. I'd suggest to use ext2 instead of ext3 for the new file system. Ext3's journal won't buy you much. Instead it introduces an area on the memory card which gets written at each metadata change. Since the number of writes to any flash cell is limited, this will wear out your flash memory much earlier than without a journalling file system.
  6. If you do this you have to watch up when running the script, since it assumes that it is a ext3 file system that is formated on the mmc. It is simple to fix though: http://www.internettablettalk.com/forums/showpost.php?p=10539&postcount=59
  7. IT2006

'(There's an updated and simplified version of this page at http://maemo.org/maemowiki/HowTo_EASILY_Boot_From_MMC_card)'

{*} **Download and install the package:**

How to upgrade the internal memory by extending the root filesystem to a memory card

Hello and welcome to my step-by-step guide with detailed instructions how to upgrade your Nokia 770 Internet Tablet by extending the root filesystem to a memory card.

By adhering to the steps I'm going to show you, you'll gain the following benefits: * Memory expansion! You'll be able to use the free space on your memory card for the root filesystem so you are no longer restricted to the limited internal memory. With the added space available on a memory card, you can install much more programs and data. * Flash persistance! Even when reflashing the unit, you won't lose your stuff. Since your programs and data are stored on the memory card, reflashing the device won't cause data loss. You can restore your personal setup after a flash "in a flash" (i. e. within a minute). * Flash memory protection! With most of the regularly changing files on the memory card, the internal memory isn't being stressed as much, so its life expectancy is improved.

Requirements:

You need a memory card, of course. The one included with the Nokia 770 is only 64 MB so it's a little small. I highly recommend a bigger card, e. g. 1 GB, for maximum gain. The new installer package now includes software to partition and format the card so you can set everything up from within the Nokia 770 device! Additionally you'll need root access and an xterm on your device.

Overview of what we're going to do:

The goal we're trying to achieve is swapping some parts of the root filesystem out of the internal memory and onto the memory card. This can be done by creating symbolic links in the internal memory to the actual files which reside on the memory card. To preserve the required filesystem attributes, we need to use a Linux filesystem. That's why we have to repartition and reformat the memory card, which can be done with the included utilities.

Before we begin - Disclaimer:

Backup all of your data! Since you're going to apply an elaborate hack which entails extensive changes to the whole system, make sure everything is backed up before you begin. Also keep in mind that while I tried and tested the procedure I'm describing several times, and try to explain it properly, I cannot guarantee anything. 'You're doing it on your own risk!' That said, it's been working very well for me, so I'm pretty sure it will work for you as well if you follow my instructions...

First Step - Preparing the memory card:

As I explained, we need a Linux filesystem on the memory card, otherwise it won't work. To stay compatible with the original operating system setup, the memory card should also support VFAT, that's why we're going to repartition and reformat it. Then the first partition will look and behave like a normal memory card, including being unmounted and remounted when the USB connection is established or disconnected. The second partition will work independently of the first and become an extension to the internal memory. Here we can move and link the files we want.

To partition and format the memory card, it must be inserted into the Nokia 770, which must not be connected by USB. Before you continue, unmount the memory card, if it's mounted. To do so, open an xterm (Extras->X Terminal), gain root (sudo gainroot) and unmount the card (umount /media/mmc1). Then use a disk partitioning program (/var/lib/install/sbin/cfdisk /dev/mmcblk0) to resize the already existing VFAT partition and create a new Linux ext3 partition from the free space remaining on the device. Whole proces of partitioning is described in this discussion post. Then proceed to format the partition (mkfs.vfat /dev/mmcblk0p1).

The newly created partition won't be available to the Nokia 770 until after a reboot. Switching it off and back on probably won't suffice. The most reliable way is issuing the reboot command from the command line using an xterm (shutdown -r now). On system bootup, the special block device file /dev/mmcblk0p2 will be created for the new partition, only then can you format the Linux partition (/var/lib/install/sbin/mkfs.ext3 /dev/mmcblk0p2) and proceed to the second step.

(!) **Instead of manually doing the following steps, I highly recommend you simply use the provided shell script (`/var/lib/install/sbin/extrootfs`), which will do it automatically for you!**

Second Step - Automounting the memory card:

Now that the memory card's second partition can be accessed through /dev/mmcblk0p2, we'll have to set it up so it's mounted on system startup and unmounted on system shutdown. To do so, we're going to edit the startup and shutdown scripts. For ease of use, here are five commands to run in an xterm, they will set it up for you (there are no line breaks within commands - each command is on a single line):

cp -p /etc/fstab /etc/fstab~ && echo /dev/mmcblk0p2 /Root ext3 defaults,errors=remount-ro,noatime 0 0 >>/etc/fstab

cp -p /etc/init.d/minircS /etc/init.d/minircS~ && sed -ir 's|(/sbin/udevstart)$|\1;mount /dev/mmcblk0p2|' /etc/init.d/minircS

cp -p /etc/init.d/minireboot /etc/init.d/minireboot~ && sed -ir 's|(/media/mmc1)|/dev/mmcblk0p1 /dev/mmcblk0p2|' /etc/init.d/minireboot

cp -p /etc/init.d/minishutdown /etc/init.d/minishutdown~ && sed -ir 's|(/media/mmc1)|/dev/mmcblk0p1 /dev/mmcblk0p2|' /etc/init.d/minishutdown

mkdir -p /Root && mount /dev/mmcblk0p2

This makes backups of all the files before modification, then inserts the partition into the filesystem table and the mount as well as unmount commands into the startup and shutdown scripts. It then creates the /Root directory which refers to the new memory card partition and mounts it immediately. With the partition mounted and everything set up like that, you can proceed to the third step.

Third Step - Swapping out the root filesystem:

Now we have the memory card's new partition mounted at /Root. We can move anything in there and it is swapped out of the internal memory and onto the memory card. We then create a symbolic link in the internal memory which points to the file located on the memory card. To the device, it looks like nothing has changed, but now you can store everything you want on the memory card.

I recommend you move the root and user home directories onto the memory card (/root and /home/user) as well as user data like bookmarks (/usr/share/osso-bookmarks), settings (/etc/bluetooth/name, /var/lib/gconf, and /etc/osso-af-init/locale), even installed programs (/var/lib/install). It all depends on the size of your new partition. With the original 64 MB memory card, you might not be able to store everything on it. With my 1 GB RS-MMC, I was able to put everything on it and still have a lot of free space for additional stuff.

After everything has been moved and sym-linked, reboot the device. If it worked, you won't notice a difference. Until you look at the control panel and check out how much free space you have left. ;-) If you bricked your device, i. e. it won't boot up anymore, simply reflash it and restore the backup you made (you did make a backup, didn't you?)!

If it worked but you want to revert to the original state:

You might have a reason to return to the default state with everything stored in internal memory, e. g. to replace the old memory card with a new one. You can go back to the original state without reflashing by removing the symbolic links and moving everything from the /Root directory back to where it belongs in internal memory. After another reboot, everything should be back to normal.

And now, the script:

To make things even easier, I wrote a shell script which will do all of this automatically (the second and third step, you still have to partition the memory card yourself, as that's not done automatically for you)! Simply run it as root (sudo gainroot followed by /var/lib/install/sbin/extrootfs). Its effect will depend on your current situation: * If you run it after creating the new partition, it will move selected files and directories over there while creating the appropriate symbolic links, then reboot on its own. * If you run it after a reflashing, it will discover that you already have the files and directories on your memory card, so it will restore them. (This is a real time saver! Keep the script and an xterm installer on your first partition so they are instantly available, then install the xterm and then run the script - after the reboot, your system is back to where it was before you flashed it with all of your stuff intact!) * If you run it a second time after it already set up your system, it will revert those changes, moving everything from the memory card back to the internal memory. (You can then remove or replace the memory card!) Feel free to edit the script and change the BACKUPS and ROOT variables to specify what files and directories you want to swap out (it comes with sensible defaults - my recommendations above) and where the memory card gets mounted (default is /Root - I recommend you keep it).

I sincerely hope that this procedure will be of use to power users who would like to extend their Nokia 770 Internet Tablet even more...

Have fun - happy hacking,
-- Stefan Daniel Schwarz

a. k. a. Wolfram Ravenwolf

How to create and use a swap file together with an Extended Root Filesystem

Instead of creating a swap file on the first partition of the memory card (which causes problems with unmounting of the partition whenever a USB connection is established) or using the second partition just for swap (which severely limits its usefulness and flexibility), I recommend putting a swap file on the second partition after it's been set up as an Extended Root Filesystem as shown here. 1 . Create an empty file to hold the swap: dd if=/dev/zero of=/Root/swapfile bs=1024 count=24576 1 . Turn the empty file into a swap file: mkswap /Root/swapfile 1 . Now it can be activated like that (as root): swapon /Root/swapfile 1 . To deactivate it, use this command (as root): swapoff /Root/swapfile Since it's a file on the new partition, it won't be unmounted when the device is connected to a computer by USB. And as a regular file, it can be resized easily. Here we're using a size of 24 MB, but once a firmware update removes the limitation, we can use a bigger file for even more swap.

If you're sure you want it activated on bootup and deactivated on shutdown, modify the system startup and shutdown scripts (as root):

echo -e "/Root/swapfile\tnone\tswap\tsw\t0\t0">>/etc/fstab
sed -i '/exit/iswapon -a 2>/dev/null' /etc/init.d/minircS
sed -i '/umount/iswapoff -a 2>/dev/null' /etc/init.d/minireboot /etc/init.d/minishutdown

What's best about my way of (de)activating swap is that this works independently of the actual swap file or partition. The startup, reboot and shutdown scripts will work the same no matter if there's swap available or not. To add or remove a swap file or partition, simply modify /etc/fstab (after manually deactivating swap with swapoff -a), without having to touch the scripts again. Even if you decide against swap, it's enough to delete or comment out the line(s) in /etc/fstab, the scripts will keep working. I'd actually like Nokia to include something like that in their own system scripts with a future version of the 770's OS.

WARNING: swapfiles tend to have very high I/O activity and as flash memory has a limited number of write cycles it is possible to cause premature death to your flash memory card. It is generaly considered to be a bad idea to put swap on flash.


(!) **To discuss and get help, check out the forum thread:**

some user experience

Hi there, I proceeded as suggested in this WIKi with the default 64MB flash card. First of all, the script /var/lib/install/sbin/extrootfs copies until the card is 100% full, then reboots. I had to manually fix the lost stuff. So, I suggest, the automated script should be actually three: One for the basic settings, one for backuping, and one for the removals ;-) But, never mind, after applying the iswapon modification to minircS, I had to do my first flashing of the root-fs, as somehow the boot procedure always got stuck at about a third of the progress bar. I'm not blaming you, maybe there was a conflict with some other modification I did the night before. See the last paragraph of http://www.maemo.org/maemowiki/ModifyingRootImage as an outcome of the last night ;-) Unless there is a recover-mode in the future, there should be some more precaution when modifying minircS. I suggest, double-checking for the entries first, i.e.

  if [ -d /dev/mmcblk0p1 ] 
   [...]
  if [ -d /dev/mmcblk0p2 ] 
   [...]
  if [ -e /mountpoint/swapfile ] 
     swapon ...
   [...]

Still: Nice work, I will definitely install again, maybe first enabling the swap manually, then having a separate startup-script with tests for the presence and type of the file systems on the flash.


I'd suggest to use ext2 instead of ext3 for the new file system. Ext3's journal won't buy you much. Instead it introduces an area on the memory card which gets written at each metadata change. Since the number of writes to any flash cell is limited, this will wear out your flash memory much earlier than without a journalling file system.

If you do this you have to watch up when running the script, since it assumes that it is a ext3 file system that is formated on the mmc. It is simple to fix though: http://www.internettablettalk.com/forums/showpost.php?p=10539&postcount=59

cfdisk wouldn't allow me to partition /dev/mmcblk0, giving me an error instead (something about the partition being bigger than reported). Use cfdisk with the -z switch to override this. ( #./cfdisk /dev/mmcblk0 -z )

IT2006

In order to access your (ext2-)partition on IT2006 (SU-18_2006SE_1.2006.26-8_PR_F5_MR0_ARM), you have to add the kernel module for ext2 first, then mount:

insmod /mnt/initfs/lib/modules/current/ext2.ko
mount /dev/mmcblk0p2 /media/mmc2

In IT2006, the SWAP space can be created from the GUI on mmc1: See Tools,ControlPanel,Memory,Virtual