2017-10-23

Installing mosh on Sailfish X

One of the awesome parts of using Sailfish OS is that you can administer your phone through ssh and sftp.
If you're using a GNU/Linux distro on your computer that can make life a lot more convenient. 



Select Settings
Select Developer Tools


Enable remote access
Simple. The next step is to check that you can connect to the phone using
ssh nemo@<your-ip>

Then disconnect, generate an ssh key if you don't have one already and copy it to the phone:

ssh-copy-id -i ~/.ssh/id_rsa nemo@<your-ip>

But there are some problems with SSH, even though the security is great as long as you know a little about RSA. If you don't, I recommend Simon Singh's The Code Book as a gentle and entertaining entry into the world of cryptography.

SSH transfers everything from the server side and does nothing to it. It's pretty dumb. That means that for instance cancelling a command with Ctrl+C will often come with a delay. It also doesn't do well with intermittent connections, because it has to catch up by sending you everything which has happened instead of just sending you the current state. Mosh is better there. See mosh.org for more.

I searched, and found this blog post from 2013 and tried running the commands half expecting the repo to be down.

ssu ar tbr-mw http://repo.merproject.org/obs/home:/dm8tbr:/branches:/nemo:/devel:/mw/latest_armv7hl/
ssu ar tbr-apps http://repo.merproject.org/obs/home:/dm8tbr:/branches:/nemo:/devel:/apps/latest_armv7hl/
pkcon refresh
pkcon install mosh


But it turns out it was fine. It installed immediately. Thanks Thomas!
So I disconnect and try to connect with

mosh nemo@<your-ip>

But as I expected it didn't work. Even though the programme is running just fine, you need to set the locale to UTF-8 first.
Ssh in again.


nano ~/.bashrc
# append the following lines
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
# Ctrl+X Y to save
source ~/.bashrc
exit
!mosh # to run the same mosh command again.
 

Success!

Experiences installing Sailfish X

Sailfish X was recently released into the wild for the price of €50.

I decided to give it a go on my Xperia X. 

This involved unlocking the bootloader, which was fairly straight-forward as I have one of the models which allows unlocking the bootloader. 

Coming from the Nexus line as I am there was an additional step to this which was new to me, which involved getting a code from Sony which allows to you to do the unlocking. Other than that it's basically finding the unlock switch in the developer options which isn't that hard.

I then attempted to download the fastboot driver, which was not that straight forward. Fastboot is the bootloader mode where you can flash images to the phone. 

Sony uses their own version of fastboot called S1 fastboot. But they have not developed their own driver. Instead they have released a modified inf file for Google's usb driver. The problem with that is that the signing gets mangled. The hash which Google has created for their driver will not match when the inf file is different. Which means you have to override Windows Driver Enforcement if enabled.

In my case I was using a corporate computer which was running bitlocker and had to get a hold of the bitlocker recovery key before I could restart the computer with advanced startup and disable windows driver enforcement and override the warnings that the driver had been tampered with. Which, of course, they had. By Sony.

This is just a dodgy thing for Sony to do. If you are going to release a driver. Sign it. Certainly if you are releasing it for Windows. I understand that most people unlocking their bootloader are hobbyists who won't be running an enterprise version of Windows, but some of us run GNU/Linux at home.

If you are also using a corporate computer with bitlocker, the recovery key can usually be found in the Active Directory Object of the computer.

Apparently this line of Powershell should get it in an administrative shell:

(Get-BitLockerVolume -MountPoint C).KeyProtector
Source: https://blogs.technet.microsoft.com/heyscriptingguy/2013/08/24/powertip-use-powershell-to-get-bitlocker-recovery-key

I went the long way about it and got it from AD via someone who had the rights to read that bit.

The next step was to download Emma. Emma is the Windows-only flashing tool which Sony provides. It flashes whole android images in their own format. 

One slight gotcha here:
If you download and install Emma and search in your start menu, you will find the emma command. If you run that, Emma will run and ask you for an account. 

If that was really how the program was expected to work it would be quite a boring step waiting for some Sony employee to see you in the list of registrants and accept that you are allowed to unlock the device that you own. Not unlike Sonys attitude earlier relating to the PS3 and the law suit against George Hotz.

It turns out you can just find the executable in program files and run that directly and it won't prompt you for a login.

You then download the newest image and flash it. Quick note here: This will do two things that you should know about.

1. The DRM-partition will be overwritten, as it wipes all the data on the phone. This includes some proprietary software which makes the camera work better. If you don't want  that to go away there is apparently some way to back it up. presumably using adb.

2. The image flashed will not update using the android OTA mechanism. Meaning that only the versions listed in Emma will be available on Android. This is also the case if you choose to drop Sailfish in the future and revert to Android. Make sure you use newest image. (The image bundles are called services in Emma)

The next thing to do was to get the Sony binaries, which can be found at developer.sonymobile.com. Here there seemed to a bit of an inconsistency. Jolla asks you to make sure Android is running build 34.3.A.0.228, before you flash Sailfish. But the vendor image you are flashing relates to Android Marshmallow (6.0) rather than Android Nougat (7.1) which that build refers to. This is because the vendor image matches the Sailfish image, not the Android you are flashing over. 

Flashing is pretty straight forward. Jolla provides a script which works just fine. I would have written it in Powershell, rather than the more old school batch, but that's fine too. The feedback it gives is mostly legible.

After having flashed I was unable to boot the phone. It kept showing the Sony logo and doing nothing. The install guide mentions this problem specifically and that made me unsure if I had the right vendor image. I tried a few different ones, without success. Eventually I found that I had forgotten to remove the µSD-card from the phone before flashing. I flashed again with the original image and the phone booted into Sailfish.

I found that the flashing had been fine all along, but the Sailfish was refusing to boot with the vfat formatted android-SD card in the phone. Kind of a weird problem, especially seeing as the card mounted just fine once Sailfish was booted up.

But I now have a function Sailfish OS phone, with MS Exchange support and Alien-Dalvik which allows me to run Android apps alongside the fancy Sailfish ones.

More coming up...


2015-11-25

An Operator's Decalogue



System administration is not an exact science. In fact it is no science at all. It is an art, and a dark one at that. The result is that philosophy affects the approach to running a well lubricated computer environment. There are absolutely points upon which can be agreed. I have attempted to compile a list of philosophical points that I hold.

Here are the ten commandments commands:


I. Thou shalt back up


This is the first point for a reason. The underlying principle here is that the unforeseen is by definition unknown. You don't know when a disk will die, only that it eventually will. 
Data you don't back up is data you don't mind losing. 
If the above sentence is not true, make it true. Remember to move the data off-site, else it's not back up.


II. Thou shalt maintain redundancy


If this seems like a reiteration of the first point, good. There is an underlying similarity, but don't confuse the two. 
Data you care about should be more than one place. 
You can achieve redundancy with replication, hardware raid, software raid (btrfs, zfs) or object storage solutions such as ceph. They do not replace backup, but they make sure that you can get from a broken state to a normal state easier.


III. Thou shalt consult thine neighbour


Making a change to the state of things requires an assessment of the consequences. Doing a quick web search, looking over the documentation and consulting another operator can save hours in a minute or two. 
Don't assume you know everything. You don't.


IV. Thou shalt share thy knowledge


Writing documentation can be a pain, but you should see it as your duty to spread your knowledge. Whether it involves writing documentation, writing tickets, talking to your colleagues, blogging, filing bug reports, sending e-mails or writing forum posts, make it known when you find idiosyncrasies, trivia and errors. 
Make a note every time you are surprised. 
Surprise is a discrepancy between the expected and the actual. Others may share your expectation.


V. Thou shalt not do a computers work


Keeping it simple and stupid involves making one solution for many problems. 
Automation can weed out biases and save labour. 
Human error can't be eliminated completely, but needless human error can. 
Learning a little scripting or even programming can help a long way. 
Processor time is cheaper than human time.


VI. Thou shalt respect your user


Pebkac occurs more often in the operator's chair than the user's. 
Understand your users use of computers and you can more accurately make the normal state a state which suits your users needs.
Happy users make happy administrators.


VII. Thou shalt fix that which is not broken


Stagnant computer environments are dying computer environments. Embrace change, but beware the consequences. Gather knowledge, identify areas of improvement and get to work. Understand the tolerance for fault, and stay a little under it, but don't aim for zero. 
Stability is important, but improvement is unstable.


VIII. Thou shalt fix that which you have broken


Change is fun, but you're not finished until you have done the cleaning up. 
Have pride in what you present to your users. 


IX. Thou shalt not make changes before the Sabbath


The downtime will be the expected time times phi [e × ϕ] if you are an optimist, 
times pi [e × π] if you are a pessimist.
Don't make a change right before going home or on holiday.



X. Insert thine own commandment here


Think for yourself.
Don't accept received knowledge without having understood it. You are the key to making the normal state the best it can be.