Install an Alternative OS on a Nokia N9

The goal is to install Maemo Leste which, according to this page is also available for the N9.
Possibly also the N9 image from here.

In any case, getting Ubiboot to work appears to be the first step. I am using the instructions from the swagman/juice Readme since they seem to be more suitable for Linux command line users. I have already downloaded all the files from here, here and here, as well as the firmware(*) mentioned earlier.

Ubiboot - Prerequisites

Flashing OpenMode is a prerequisite, and if you do not want to see the ugly boot warning: it needs to be disabled while still in closed mode!

$ disclaimer-cal remove View-openmode
disclaimer-cal: Disclaimer removed from CAL (truncated to zero size)

After that, one can continue with this complete oneliner:

# flasher -f -F firmware.bin -F emmc.bin -R ; flasher -a firmware.bin -k zImage_2.6.32.54-openmode_l2fix --flash-only=kernel -f -R

Developer mode and SSH

Although we already enabled developer mode etc. in the previous article, we might need to do it again because of re-flashing the firmware.

Enabling developer mode installs an ssh client (and server), so now we can log onto the phone thusly (assuming it's on the same LAN as 192.168.0.12):

[Computer] $ ssh user@192.168.0.12
[Computer] (...) yes

Oh, sorry, there's no password for user user, and we don't want one either - we want to go straight to key-based login!
So, on the home computer:

[Computer] $ ssh-keygen -t rsa

Copy the resulting .pub file to the phone. Then, with the USB cable unplugged, do the following on the phone's terminal:

[N9] $ cd
[N9] $ mkdir .ssh
[N9] $ chmod 700 .ssh
[N9] $ mv ~/MyDocs/id_rsa.pub ~/.ssh/authorized_keys
[N9] $ chmod 400 ~/.ssh/authorized_keys

Now, edit ~/.ssh/config on your home computer and add sth like this:

Host n9
  HostName 192.168.0.12
  User user
  IdentitiesOnly yes
  IdentityFile /home/mus/.ssh/n9-id_rsa

Now try

[Computer] $ ssh n9

If that works, continue to do the following:

[N9] $ devel-su
[N9] (password: rootme)
[N9] # vi /etc/ssh/sshd_config

Make sure the file contains the line

PasswordAuthentication no

And while we're still root, let's do the following:

[N9] # passwd

Change the password to something else than 'rootme'! Make sure the new password works properly both on the home computer and the phone's terminal.

If passwordless ssh login did not work, you might need to temporarily enable password login on the phone:

# passwd user

Or edit /etc/passwd and make sure the entry for user looks like this:

user:*:29999:29999::/home/user:/bin/sh

See this forum thread for more detail (and more confusion).

Installing Ubiboot

For Linux/CLI users, the Ubiboot Readme has better instructions. Scroll down to "Installing ubiboot to your device". We have already taken care of everything under 1.) and should be able to go straight to "2.) Selecting the place where to install the configuration file and cpio".

Because of a later step we don't choose /home/user/MyDocs/boot to install the ubiboot configuration, but /home/boot instead. If you already put the files in /home/user/MyDocs/boot you can do this:

$ devel-su
# mv /home/user/MyDocs/boot /home/boot

BTW, there's a few typos in this section:

  • "searched for a /boo/ directory" - that should be a /boot/ directory
  • "tar -xcf" will give an error. It should be "tar -xf" or "tar -xvf"

Continue with steps 3.) - 5.)

For now we do not install any other operating system, we just want this to work with our current Harmattan install.

I failed once and could not boot. Neither telnet nor ssh worked for me, but it was fairly simple to flash the normal openmode kernel, fix things, then flash the ubiboot kernel again.

Installing Maemo Leste - Prerequisites

Following this guide. Ubiboot is installed & working. The next step is called "Create a new slice on the eMMC" and links to a thread about partitioning the N9's storage. I understand this to mean that I need to create a new partition. At first I tried to do this with gparted from my desktop via ubiboot's maintenance mode. I managed to create the partitions alright (shrink /home/user/MyDocs and create a 4th partition for Maemo Leste), but the phone did not accept them.

It turns out that post #1 of this thread has quite exact step-by-step instructions. sshinto your N9 and become root (devel-su). Then:

~ # /sbin/sfdisk --no-reread /dev/mmcblk0 -N1

Disk /dev/mmcblk0: 485120 cylinders, 4 heads, 16 sectors/track
Old situation:
Units = cylinders of 32768 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/mmcblk0p1         32  128031  128000    4096000    c  W95 FAT32 (LBA)
        start: (c,h,s) expected (32,0,1) found (0,32,33)
        end: (c,h,s) expected (1023,3,16) found (510,14,16)
/dev/mmcblk0p2     288512  419583  131072    4194304   83  Linux
/dev/mmcblk0p3     419584  485119   65536    2097152   83  Linux
/dev/mmcblk0p4     128032  288511  160480    5135360   83  Linux
        start: (c,h,s) expected (1023,3,16) found (510,14,17)
        end: (c,h,s) expected (1023,3,16) found (1023,254,63)
Input in the following format; absent fields get a default value.
<start> <size> <type [E,S,L,X,hex]> <bootable [-,*]> <c,h,s> <c,h,s>
Usually you only need to specify <start> and <size> (and perhaps <type>).

/dev/mmcblk0p1 :16 128000 c
/dev/mmcblk0p1         16  128015  128000    4096000    c  W95 FAT32 (LBA)
New situation:
Units = cylinders of 32768 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/mmcblk0p1         16  128015  128000    4096000    c  W95 FAT32 (LBA)
/dev/mmcblk0p2     288512  419583  131072    4194304   83  Linux
/dev/mmcblk0p3     419584  485119   65536    2097152   83  Linux
/dev/mmcblk0p4     128032  288511  160480    5135360   83  Linux
        start: (c,h,s) expected (1023,3,16) found (510,14,17)
        end: (c,h,s) expected (1023,3,16) found (1023,254,63)
Warning: no primary partition is marked bootable (active)
This does not matter for LILO, but the DOS MBR will not boot this disk.
start of partition 4 has impossible value for head: 14 (should be in 0-3)
start of partition 4 has impossible value for sector: 17 (should be in 1-16)
I don't like this - probably you should answer No
Do you want to write this to disk? [ynq] y
Successfully wrote the new partition table

Re-reading the partition table ...
BLKRRPART: Device or resource busy
The command to re-read the partition table failed
Reboot your system now, before using mkfs

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
~ # /sbin/sfdisk --no-reread /dev/mmcblk0 -N4

Disk /dev/mmcblk0: 485120 cylinders, 4 heads, 16 sectors/track
Old situation:
Units = cylinders of 32768 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/mmcblk0p1         16  128015  128000    4096000    c  W95 FAT32 (LBA)
/dev/mmcblk0p2     288512  419583  131072    4194304   83  Linux
/dev/mmcblk0p3     419584  485119   65536    2097152   83  Linux
/dev/mmcblk0p4     128032  288511  160480    5135360   83  Linux
        start: (c,h,s) expected (1023,3,16) found (510,14,17)
        end: (c,h,s) expected (1023,3,16) found (1023,254,63)
Input in the following format; absent fields get a default value.
<start> <size> <type [E,S,L,X,hex]> <bootable [-,*]> <c,h,s> <c,h,s>
Usually you only need to specify <start> and <size> (and perhaps <type>).
/dev/mmcblk0p4 :128016 160555
Warning: given size (160555) exceeds max allowable size (160496)
/dev/mmcblk0p4 :128016 160496 L
/dev/mmcblk0p4     128016  288511  160496    5135872   83  Linux
New situation:
Units = cylinders of 32768 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/mmcblk0p1         16  128015  128000    4096000    c  W95 FAT32 (LBA)
/dev/mmcblk0p2     288512  419583  131072    4194304   83  Linux
/dev/mmcblk0p3     419584  485119   65536    2097152   83  Linux
/dev/mmcblk0p4     128016  288511  160496    5135872   83  Linux
Warning: no primary partition is marked bootable (active)
This does not matter for LILO, but the DOS MBR will not boot this disk.
Do you want to write this to disk? [ynq] y
Successfully wrote the new partition table

Re-reading the partition table ...
BLKRRPART: Device or resource busy
The command to re-read the partition table failed
Reboot your system now, before using mkfs

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)

After a reboot:

~ # /sbin/sfdisk -l /dev/mmcblk0

Disk /dev/mmcblk0: 485120 cylinders, 4 heads, 16 sectors/track
Units = cylinders of 32768 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/mmcblk0p1         16  128015  128000    4096000    c  W95 FAT32 (LBA)
/dev/mmcblk0p2     288512  419583  131072    4194304   83  Linux
/dev/mmcblk0p3     419584  485119   65536    2097152   83  Linux
/dev/mmcblk0p4     128016  288511  160496    5135872   83  Linux

Now create filesystems in the partitions:

~ # /sbin/mkfs.vfat /dev/mmcblk0p1
mkfs.vfat 2.11 (12 Mar 2005)
~ # /sbin/mkfs.ext4 /dev/mmcblk0p4
mke2fs 1.41.12maemo1 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
321280 inodes, 1283968 blocks
64198 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1317011456
40 block groups
32768 blocks per group, 32768 fragments per group
8032 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Test-mounting both partitions is succesful.

After this initial effort it is easier to install various operating systems. Because I only have the 16GB model, I do not create an elaborate multiboot scheme with an extended partition containing many more logical partitions, but test OSs one by one on that one spare partition. It is then only a question of deleting all files on that partition & un-tar-ing the new one.

Maemo Leste

Extracting the archive to the appropriate partition (/dev/mmcblk0p4 in our case). First I copied the archive to storage (/dev/mmcblk0p1 on /home/user/MyDocs) via USB cable, then I ssh'd into the phone and did this:

$ devel-su
# mkdir ml
# mount /dev/mmcblk0p4 ml
# cd ml
# cp /home/user/MyDocs/maemo-leste-1.0-armhf-n9-20190315.tar.gz .
# tar -xzvf maemo-leste-1.0-armhf-n9-20190315.tar.gz
# rm maemo-leste-1.0-armhf-n9-20190315.tar.gz
# cd
# umount ml
# rmdir ml

Don't forget to also edit ubiboot.conf accordingly.

Reboot - something is clearly happening, there's a lot of familiar-looking Linux bootup messages scrolling past - after a few minutes it boots into something graphical which is totally unusable. I know that there's problems with screen rotation. After a while I can at least see parts of something resembling a GUI, and it even responds to touches - after a minute or so. But nothing ever comes out of these touches.

Devuan Embedded for N9

Found here. Very similar to Maemo Leste, except it didn't even boot into anything graphical, just log text scrolling down the window.

Sailfish OS (old version!)

There's a pretty detailed wiki article on how to set that up. Fortunately we already did most of that, and once more it comes down to extracting an archive. After ssh:ing into Harmattan, a slightly different command this time:

# mkdir m
# mount /dev/mmcblk0p4 m
# tar -xvjf /home/user/MyDocs/vgrade-sailfish_r5.1.tar.bz2 --numeric-owner -C m/

Now the wiki article recommends to remove the root password:

# nano m/etc/shadow

And "delete the all letters, numbers and symbols after "root:" and before :XXXXX:0:99999:7:::" until that line looks sth like this:

root::16067:0:99999:7:::

Save, and unmount:

# cd
# umount m

Now we still need to edit ubiboot.conf! It's probably best if you use the ubiboot.conf and .cpio provided here, and drop them into your existing ubiboot /boot directory.

That's it. Save, exit, reboot.

It works. There's one very annoying bug: swipe gestures (which Sailfish OS relies on heavily) are rotated 90 degrees. This destroys all intuitiveness and makes it difficult to use the OS. Apart from that, it looks very nice and stable.


(*) This forum thread has a list of alternative firmwares. Unlike stated above, I am currently using this package for no valid reason. I believe this is sufficient.