Thursday, December 19, 2013

Garmin and OpenStreetMap

I've got a handheld GPS from Garmin - the eTrex Vista HCx, which I bought in anticipation of a trip that didn't happen, and haven't had any real reason to use it until now.

Now, I'm headed to Myanmar and could use some GPS to guide my bike adventures. Trouble is, garmin would like me to pay a lot for some pretty useless and out of date maps. Luckily, openstreetmap has come a long way and is now looking pretty good, even for Myanmar. So here, I've just figured out the rather tricky process of getting maps onto the device and getting them recognized.

Get a usable map with the information you need for the region you'll be in. The easiest option is to download something somebody else created. Have a look here, and particularly here, although the latter appears to need a >=4GB microSD card (mine is 1GB). Unfortunately none of the pre-made maps cover Myanmar, at least not in enough detail for me.

1) Download the area of OSM you need using the API. I did the following to download.
wget -O myanmar.osm http://www.overpass-api.de/api/xapi?map?bbox=93.4,15.5,98.0,23.0
This bounding box covers most parts of Myanmar that tourists are allowed to visit.
2) Next, convert it to the format needed by Garmin. For this, use mkgmap which is a java command line program available from here. For my purposes, it was necessary to provide a custom style file which specifies what features go into the garmin map and how they look. I used the cyclemap style explained here, and downloaded cyclemap.TYP to the same directory:
svn co http://svn.openstreetmap.org/applications/utils/export/garmincyclemap/network/cyclemap
3) I unzipped the mkgmap files to another subdirectory in the same location.
4) I used the cyclemap styles unmodified, although they could have been improved for my uses (they're designed for the UK). Then I simply ran:
java -jar mkgmap-r2889/mkgmap.jar --style-file=cyclemap --remove-short-arcs --style-file=cyclemap --route --net --mapname=Myanmar --description=Myanmar --gmapsupp myanmar.osm

This produced gmapsupp.img, which is the garmin-format map file I needed. (I had no need to split the osm or ask java for extra memory, but more info here.)

The next step is getting this onto the device. In theory, the easiest option should be to simply copy this file to the Garmin\ subdirectory on the microSD card using a card reader. But in my experience, the garmin device never recognized it. That leaves two other options.

1) In windows, install the Garmin USB drivers (first!). Then connect and turn on the Garming GPS using the USB cable. Under Menu->Setup->Interface and select USB Mass Storage. This will show the SD card as a drive on the computer. Copy the gmapsupp.img file to the Garmin\ directory on the device. (Note there can only be one custom map file on the device at a time and it must be in this location/filename). Eject it and power down the device.
2) Use sendfile to copy the file onto the device (this should work in linux or windows; in windows it also requires the Garmin USB drivers). After completing, eject the device and power it down.

Finally, disconnect the GPS from the computer and power on. There should be mention of OPENSTREETMAP copyrights during bootup. To confirm that the map is there, you can go to Menu->Setup->Map and scroll right to the info icon, where you should see your map selected. You should also be able to zoom out and pan to the coverage area (if you're already within the coverage area, no need to pan!). Note that it may only really be visible at certain zoom levels. You could also "Find" a city, say, or other place in your new map.

Enjoy!

Wednesday, December 4, 2013

Upgrading from Linux Mint 15 (Olivia) to Linux Mint 16 (Petra)

To upgrade, as opposed to the recommended method, which is to re-install with the new CD, recover the apps you've installed using mint backup, restore your data, and re-configure everything, I used the apt system, which is a bit more risky. (It may be worth burning the install disk and running it as a live CD to ensure your hardware is well-supported). Here's what I did:

1) Update the repositories to point to their new locations:

$ sudo sed -i 's/raring/saucy/' /etc/apt/sources.list.d/*.list
$ sudo sed -i 's/olivia/petra/' /etc/apt/sources.list.d/*.list

2) Update the repositories:

$ sudo apt-get update

Look for any errors. Some repositories for non-mint apps may not yet have a special version for Mint 16, but they will likely still work. If you do get errors, find the corresponding .list file and undo the above change (eg, change 's/raring/saucy/' --> 's/saucy/raring/'), on only that .list file. Re-update the repositories.

3) Quit any open apps. Then, perform the upgrade. This step will require several gigabytes of downloads, which will take a while (if it doesn't, something is wrong; abort and fix).

$ sudo apt-get dist-upgrade

Along the way, you'll be prompted whether to keep or overwrite any config files that have been changed by the maintainers. Almost always, you'll want to say Yes. It will keep your old files with an extension like .dpkg_old, in case you need to do any merging. The main case where I needed to do this was with my samba setup.

Then, just to be safe, run:

$ sudo apt-get upgrade

4) Finally, some last minute changes. Make sure your drives in fstab will still mount. I use the ufsd from Paragon (instructions here) for ntfs and hfs+ drives, and this will need to be re-compiled for the newly installed kernel after reboot. But for now, comment them out in /etc/fstab.

Also, if you had to use the default UEFI boot file, copy the new grub file to that location (you might want to back it up first):

$ sudo cp /boot/efi/EFI/linuxmint/grubx64.efi /boot/efi/EFI/boot/bootx64.efi

When you think you've sorted out all the kinks, reboot: sudo shutdown -r now

5) If you're lucky, the machine will come up and you'll be able to log on. Otherwise, another good opportunity to use that linux live disk you've got.

Install the ufsd drivers for the new kernel following the instructions linked to above. Uncomment the lines in /etc/fstab and run sudo mount -a then verify they all loaded. For some reason, under linux mint 16 (but not 15), the ufsd kernel module will not autoload - it's necessary to add the ufsd driver to /etc/modules by adding a line "ufsd" to the end -- otherwise the file system will not be recognized and boot will hang.

6) After update, I had some duplicate icons in the menu for some reason. These are easiest removed by running gksudo nemo and navigating to /usr/share/applications and removing dups, retaining those that utilize the currently running cinnamon-settings app.

Done.

Using the same ssh key between linux and mac

If you are dual booting and you want to be able to ssh in (particularly by IP, or if the host names are the same) to both operating systems, then you'll want to set up ssh to share the same server keys between operating systems.

Otherwise, after a client connects with one operating system and then tries to connect again while you're booted in the other OS, they'll get this message:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.

To use the same ssh keys, copy them from one OS to the other. I chose to use the ones from linux in macos (in macos they're stored directly under /etc, in ubuntu/linux mint they're under /etc/ssh/):

 /etc/ssh $ ls -l
total 276
-rw-r--r-- 1 root root 242091 Nov  8 14:37 moduli
-rw-r--r-- 1 root root   1669 Mar 26  2013 ssh_config
-rw-r--r-- 1 root root   2489 Nov 11 12:57 sshd_config
-rw------- 1 root root    668 Nov 11 12:57 ssh_host_dsa_key
-rw-r--r-- 1 root root    600 Nov 11 12:57 ssh_host_dsa_key.pub
-rw------- 1 root root    227 Nov 11 12:57 ssh_host_ecdsa_key
-rw-r--r-- 1 root root    172 Nov 11 12:57 ssh_host_ecdsa_key.pub
-rw------- 1 root root   1679 Nov 11 12:57 ssh_host_rsa_key
-rw-r--r-- 1 root root    392 Nov 11 12:57 ssh_host_rsa_key.pub
-rw-r--r-- 1 root root    338 Dec  2 15:52 ssh_import_id
 /etc/ssh $ sudo mkdir /macos/etc/ssh-backup
 /etc/ssh $ sudo mv /macos/etc/ssh_host* /macos/etc/ssh-backup/
 /etc/ssh $ sudo cp ssh_host* /macos/etc
 /etc/ssh $ ls -l /macos/etc/ssh*
-rw-r--r-- 1 root root    0 Nov  4 23:27 /macos/etc/ssh_config
-rw-r--r-- 1 root root    0 Nov  4 23:27 /macos/etc/sshd_config
-rw------- 1 root root  668 Dec  4 18:48 /macos/etc/ssh_host_dsa_key
-rw-r--r-- 1 root root  600 Dec  4 18:48 /macos/etc/ssh_host_dsa_key.pub
-rw------- 1 root root  227 Dec  4 18:48 /macos/etc/ssh_host_ecdsa_key
-rw-r--r-- 1 root root  172 Dec  4 18:48 /macos/etc/ssh_host_ecdsa_key.pub
-rw------- 1 root root 1679 Dec  4 18:48 /macos/etc/ssh_host_rsa_key
-rw-r--r-- 1 root root  392 Dec  4 18:48 /macos/etc/ssh_host_rsa_key.pub

/macos/etc/ssh-backup:
total 24
-rw------- 1 root root  668 Nov 11 00:23 ssh_host_dsa_key
-rw-r--r-- 1 root root  590 Nov 11 00:23 ssh_host_dsa_key.pub
-rw------- 1 root root  965 Nov 11 00:23 ssh_host_key
-rw-r--r-- 1 root root  630 Nov 11 00:23 ssh_host_key.pub
-rw------- 1 root root 1679 Nov 11 00:23 ssh_host_rsa_key
-rw-r--r-- 1 root root  382 Nov 11 00:23 ssh_host_rsa_key.pub

Voila. You can ssh into either OS without any warnings.

You may also want to set the same ~/.ssh/authorized_keys under home dirs in both your OSes, to allow password-free authentication between the client and both servers. A reminder on how to set this up --
On the client:

cd ~/.ssh
ssh-keygen -f id_rsa -C 'comment to identify client' -N '' -t rsa -b 4096 -q


This creates a private and a public key. Copy the id_rsa.pub key to the server. (eg, scp id_rsa.pub user@serverhost:/home/user/ ). On the server:


cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
rm id_rsa.pub

All set. You can repeat as desired for each client user/machine. Then just copy authorized keys to the other OS and it'll work without a password in either.