Tuesday, February 17, 2015

Fix for iPhone not charging through USB on Ubuntu Linux


Connecting an iPhone/iPad/iPod to Ubuntu or a modern Linux system is usually a plug-and-play experience. However, with new iOS versions, sometimes the device simply fails to charge through USB even if it is recognized by the system. While rebooting Ubuntu solves the problem, it is actually possible to resolve the problem without a reboot.

battery, linux, debian, fix, tutorial, charge, USB, iPhone, iPad, iPod
The Ubuntu Linux distribution is certainly great in many aspects, although when it comes to supporting the newest iOS versions on Apple devices, the support is usually lagging behind and also buggy and lacking. Many users of the newer iOS versions have run into cases where they have plugged in their iPhone to their Ubuntu system with everything working smoothly, and all of a sudden (while the iPhone is plugged in), the iPhone simply cease to charge or become unreachable on Ubuntu. Rebooting the computer does bring the iPhone back to life, however, the problem is more easily solved if we understand it better. 

Investigations show that an iDevice, in particularly, iPhone can end up in a locked state, from the perspective of Ubuntu, if the user receives a phone call, text message, or any other notification event that actually activates a closed or iOS-frozen background process and making it active. Thus, this indicates that something on the Ubuntu system which deals with the USB communication with the iPhone must be the culprit. Remember, a reboot of, for example, Ubuntu actually does make everything work again.

The culprit turns out to be the daemon known as usbmuxd (USB Multiplex Daemon) which communicates with iPhone/iPod/iPad devices by opening TCP ports and connections through the usbmuxd protocol. Unfortunately, full and proper support for the newest iOS versions is usually lacking, which can throw the usbmuxd process into weird states that fails to properly establish communication with an iPhone. In such cases, the iPhone may simply not charge, even though the user can otherwise access the iPhone in Ubuntu Linux, or the iPhone may not be visible at all from the high-level user interfaces.

iphone, battery empty, charging, charge, usb, ubuntu, linux
A particularly interesting case, illustrated to the left, is when the iPhone detects a plugged in USB cable, but it simply does not charge at any measurable rate, even though the symbol from the lock screen indicates it. This means that usbmuxd has failed to communicate properly with the iPhone to put it into charging mode.

Perhaps the "correct" way to fix the problem is to either commit a fix to bring full support to usbmuxd for new iOS versions, or to manually install a newer version of usbmuxd, if it exists. However, the former alternative is probably too technical for most users, and the latter is really not the way Ubuntu is designed to be used. Ubuntu should be user-friendly, and one such aspect is to remove the need of users from having to manually install libraries and packages from sources outside of the default repositories (hardcore Windows users will probably disagree, that is fine, you can continue your internet treasure hunts). For me, when I encounter the error of my iPhone not charging anymore on my Ubuntu and Debian Linux systems, a simple restart of usbmuxd has by far been easiest way to resolve the issue. This is easily accomplished through the following steps:
  1. Identify the usbmuxd process: Open up a terminal and type,
    $ ps aux | grep usbmux
    which should return an output like
    usbmux    6781  0.0  0.0 230120  6584 ?        Sl   09:30   0:00 /usr/sbin/usbmuxd -u -U usbmux
  2. Kill usbmuxd: The highlighted number (6781) above is the process id/number for usbmuxd (unique for all systems and the state of a system). What we want to do is to kill this process and restart it. This can be done by the following command in the terminal,
    $ sudo kill -9 6781
  3. Restart usbmuxd: With usbmuxd dead we need to manually start it again in order for Ubuntu to one again recognize the iPhone/iPad/iPod. Bring up the terminal once again and type,
    $ sudo usbmuxd -u -U usbmux
    here, the flag -u means to run it in udev operation mode and -U to change the user of the process to usbmux after startup.
Note that for steps  2 and 3, we need to use sudo since the process is owned by the user "usbmux" and starting it in step 3 requires USB priviledges.

Following this the iPhone should automatically be picked up by the Ubuntu Linux system and starting to charge and to transfer data! Hopefully this will be useful for some of you out there who, like me, had been forced to restart the whole computer when the issue popped up. As mentioned above, for me, this typically happened when I received a phone call, text message or certain push notifications while my iPhone was plugged into my Ubuntu or Debian machines through USB.


No comments:

Post a Comment