Samsung Galaxy display running CyanogenMod

How to Connect the Samsung Galaxy Android to Linux or OpenBSD

Samsung Galaxy USB Storage

The Samsung Galaxy series certainly should be compatible with Linux. After all, they run the Android operating system, which is based on Linux. The About phone screen even shows the base Linux kernel version. This page shows how I've connected my SGH-T989, the T-Mobile version, running CyanogenMod, based on Android and the Linux kernel.

However, if you download the manual (11.0 MB), you see nothing about using it with computers running Linux, BSD, OS X, or any other Unix-based operating system.

Be aware that Android and therefore CyanogenMod dropped support for USB mass storage starting with Android v3.0. It used to be as easy to use as a USB thumb drive, now it takes a little work to set things up to work with the PTP/MTP protocols. The alternative is to unmount the MicroSD card, remove it from the phone and place it in a reader.

How to use the Samsung Galaxy S2 with Linux

You will need the mtpfs program, which will probably be in a package with the same name. See my page on software package management for details on how to figure out which package you need to add and how to go about that. You may want to look at the mtpfs web page for further details.

Start by selecting the MTP protocol for connecting your phone:
<Settings button> | Storage | <Settings menu> | Media device (MTP)

You see me making that change below.

'USB computer connection' screen selecting MTP media device on Samsung Galaxy S2 smart phone running CyanogenMod.
'About phone' screen on Samsung Galaxy S2 smart phone running CyanogenMod.

Connect the phone. Something like the following will appear in the Linux machine's kernel ring buffer:

$ dmesg | tail
... some lines deleted ...
[271527.319166] usb 2-8: new high-speed USB device number 11 using ehci-pci
[271527.436410] usb 2-8: New USB device found, idVendor=04e8, idProduct=6860
[271527.436415] usb 2-8: New USB device strings: Mfr=2, Product=3, SerialNumber=4
[271527.436417] usb 2-8: Product: Android
[271527.436418] usb 2-8: Manufacturer: Android
[271527.436419] usb 2-8: SerialNumber: 88df75ea
[271527.437807] cdc_acm 2-8:1.1: This device cannot do calls on its own. It is not a modem.
[271527.437910] cdc_acm 2-8:1.1: ttyACM0: USB ACM device

Mount it. Be patient, the mtpfs command may take about 40 seconds:

$ mkdir ~/android
$ mtpfs ~/android
Listing raw device(s)
Device 0 (VID=04e8 and PID=6860) is a Samsung Galaxy models (MTP).
   Found 1 device(s):
   Samsung: Galaxy models (MTP) (04e8:6860) @ bus 2, dev 11
Attempting to connect device
Android device detected, assigning default bug flags
Listing File Information on Device with name: (NULL)
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda6       909G   51G  812G   6% /
devtmpfs        3.8G     0  3.8G   0% /dev
tmpfs           3.8G  876K  3.8G   1% /dev/shm
tmpfs           3.8G  824K  3.8G   1% /run
tmpfs           3.8G     0  3.8G   0% /sys/fs/cgroup
tmpfs           3.8G  1.7G  2.2G  44% /tmp
/dev/sdc1       1.8T  1.4T  497G  73% /home
/dev/sdb1       917G  863G   55G  95% /home2
/dev/sdd1       459G  201G  258G  44% /home3
/dev/sda1       186M  153M   20M  89% /boot
tmpfs           3.8G  824K  3.8G   1% /var/spool/postfix/run/saslauthd
mtpfs            15G  3.5G   12G  24% /home/cromwell/android

This is mounted with FUSE so root cannot read it. This gets a little strange:

$ sudo bash
Password:
# df /home/cromwell/android
df: '/home/cromwell/android': Permission denied
# ls -l /home/cromwell/android
ls: cannot access /home/cromwell/android: Permission denied
# ls -ld /home/cromwell/android
ls: cannot access /home/cromwell/android: Permission denied
# ls -l /home/cromwell | grep android
d?????????    ? ?        ?                 ?            ? android/

Meanwhile you have access to the file systems on the phone, the internal storage and that on the SD card. Timestamps are also strange on the FUSE file system, everything's time stamp is -1, or one second before the UNIX epoch began in 1970.

$ cd ~/android
$ ls -laF
drwxrwxrwx   2 cromwell cromwell     0 Dec 31  1969 ./
drwxr-xr-x 196 cromwell cromwell 57344 Mar 11 14:15 ../
drwxrwxrwx   2 cromwell cromwell     0 Dec 31  1969 Internal storage/
drwxrwxrwx   2 cromwell cromwell     0 Dec 31  1969 Playlists/
drwxrwxrwx   2 cromwell cromwell     0 Dec 31  1969 SD card/
% du -sh *
467M    Internal storage
0       Playlists
1.8G    SD card

When you're done, unmount it:

$ cd
$ fusermount -u ~/android

Another thing to consider: enable SSH service on your phone and connect to your phone over SSH over 802.11 wireless.

How to use the Samsung Galaxy S2 with OpenBSD

Install the libmtp, libid3tag, and flac packages:

# pkg_add libmtp libid3tag flac

Download and build gmtp using gmake.

$ cd /tmp
$ gtar xf ~/gmtp-latestversion.tar.gz
$ cd ~/gmtp-latestversion
$ ./configure
$ gmake
$ su root -c 'gmake install'
Password:

Connect the phone. Something like the following will appear in the kernel ring buffer:

$ dmesg | tail
... some lines deleted ...
umodem0 at uhub1 port 1 configuration 1 interface 1 "Android Android" rev 2.00/4.00 addr 2
umodem0: data interface 2, has no CM over data, has no break
umodem0: status change notification available
ucom0 at umodem0
ugen0 at uhub1 port 1 configuration 1 "Android Android" rev 2.00/4.00 addr

Run gmtp and click the Connect button. Again, expect this to take 40 seconds or so. You will get a pop-up window asking if you want to connect to the SD card or internal storage. Select one, click OK, and browse away.

CyanogenMod File Permission Mystery

My camera app stores images in /storage/sdcard1/DCIM/Camera/, which is the removeable Micro SD card. I have connected in over SSH using SSHDroid. Look at this strange result, I have never encountered files of mode 0075 before:

root@SGH-T989:/storage/sdcard1/DCIM/Camera # ls -la
d---rwxr-x  2 system  sdcard_r    32768 Mar 11 20:00 .
d---rwxr-x  4 system  sdcard_r    32768 Mar 11 15:51 .
----rwxr-x  1 system  sdcard_r  3786464 Mar 11 19:59 IMG_20140311_195956.jpg
----rwxr-x  1 system  sdcard_r  3734592 Mar 11 20:00 IMG_20140311_200000.jpg
----rwxr-x  1 system  sdcard_r  3765426 Mar 11 20:00 IMG_20140311_200004.jpg

The odd mode comes from how it's mounted, notice the fmask= and dmask= options setting the umask for this VFAT file system:

root@SGH-T989:/storage/sdcard1/DCIM/Camera # mount | grep storage
/dev/block/vold/179:97 /storage/sdcard1 vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
/dev/block/vold/179:28 /storage/sdcard0 vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
tmpfs /storage/sdcard0/.android_secure tmpfs ro,seclabel,relatime,size=0k,mode=000 0 0

The mode is persistent, chmod 644 * runs with no error and a return value of 0, but it has no effect.

So, the dmask and fmask options are why directories and files get these strange permission masks. My real question is why those strange permissions are needed.

Update: a later version of Cyanogenmod fixed this.

WARNING:

Content below this point is now of historical interest only. Android and therefore CyanogenMod dropped support for USB mass storage starting with Android v3.0. Use the PTP/MTP protocols as described above, or simply unmount the MicroSD card and place it in a reader.

Also see my page about using digital cameras with Linux and BSD.