Lubuntu 14.10 on the Acer C720 Chromebook

Suraj N. Kurapati

  1. Setup
    1. Fixes
      1. Touchpad
        1. Kernel
          1. Power
            1. Wi-Fi
              1. Sound
                1. Keyboard
                  1. Sleep
                    1. /etc/rc.local
                      1. /etc/pm/sleep.d/20_acer_c720_chromebook
                    2. Extras
                      1. Automatic HDMI
                        1. ~/bin/acer-c720-display
                          1. ~/bin/acer-c720-reactor
                        2. References

                          For six long months, I used a Crouton chroot (running Debian Sid) alongside my Acer C720 Chromebook‘s native Chrome OS as my primary working environment: the Secure Shell extension provided direct, non-SSH terminal access to the chroot, where I did all of my real work, while Chrome browser provided a means to access my e-mail and the Internet.

                          However, I wasn’t able to reliably run graphical X11 applications in Chrome OS when the need arose occasionally (e.g. to display a plot in R or Octave) and, by the time a workaround for this problem was identified, my growing dissatisfaction with Chrome OS’ limitations and my concerns over personal data and activities being collected, stored, and processed in Google’s cloud prompted me to completely replace Chrome OS with a standard Linux installation.

                          I tried Elementary OS Freya, Xubuntu 14.10, and Lubuntu 14.10 and finally settled on the latter because it had the smallest operational overhead (in terms of power, CPU, and memory consumption) when my laptop was idle, according to Intel’s PowerTOP tool.

                          Now that this configuration has stabilized, having lasted an entire week of continuous use (no shutdown, only suspend and resume) without any problems, I decided to write this article and share it with the world: documented below is how I replaced Chrome OS with Lubuntu 14.10 on my Acer C720 Chromebook. May this knowledge liberate you from Google’s clutchescloud as well. :-)

                          Setup

                          1. Install John Lewis’ custom Chromebook firmware as described in the_unconventional’s guide. Doing this eliminates the annoying time-delayed “scary boot screen”, boots directly into SeaBIOS, fixes issues with Linux kernel modules.

                          2. Write the 64-bit Lubuntu 14.10 installation image to a USB stick:

                            sudo dd if=lubuntu-14.10-desktop-amd64.iso of=/dev/sdXYZ
                            

                            Plug in your USB stick and run dmesg | tail to find the XYZ value.

                          3. Boot your Acer C720 Chromebook from the USB stick prepared above.

                          4. Choose “Try Lubuntu without installing” at the USB stick’s boot menu.

                          5. Press Control+Alt+T to open a terminal and then type in the following:

                            xbacklight = 15 # temporarily reduce laptop's display brightness
                            sudo swapoff -a # disable swap to avoid security error later on
                            
                          6. Double-click the “Install Lubuntu 14.10” icon on the desktop to start the installation process, in which:

                            1. Choose “Erase disk and install Lubuntu”.
                            2. Choose “Encrypt the new Lubuntu installation for security”. Make sure to turn off swap by running sudo swapoff -a before entering your encryption passphrase to avoid a security error that aborts the installation.
                            3. Choose “Use LVM with the new Lubuntu installation”.
                            4. Choose “Continue Testing” instead of rebooting.
                          7. Press Control+Alt+T to open a terminal and then type in the following:

                            sudo -s
                            swapoff -a
                            lvremove /dev/lubuntu-vg/swap_1
                            lvextend --extents +100%FREE /dev/lubuntu-vg/root
                            e2fsck -f /dev/lubuntu-vg/root
                            resize2fs /dev/lubuntu-vg/root
                            

                            This will absorb the encrypted swap volume into your root volume, thereby giving you an extra 4 GiB (or 2 GiB depending on your Chromebook model) of disk space to work with.

                          8. Reboot the computer when you are ready to start using Lubuntu 14.10.

                          9. Disable encrypted swap, which the root volume absorbed earlier:

                            sudo sed -i 's,^/dev/mapper/lubuntu--vg-swap_1,#&,' /etc/fstab
                            
                          10. Enable TRIM support on the root volume since it’s on a solid state disk:

                            sudo sed -i '/vg-root/s/errors=remount-ro/&,noatime,discard/' /etc/fstab
                            

                          Fixes

                          After successful installation, apply the following fixes.

                          Touchpad

                          Enable touchpad by upgrading your Linux kernel to version 3.17 or newer, which has the touchpad driver built-in. To do this, download the upgrade packages (namely the linux-headers*amd64.deb and linux-generic*amd64.deb files) and install them using the sudo dpkg -i command.

                          Kernel

                          Prevent system freezes that randomly occur under Linux kernel 3.17+:

                          echo 'options i915 semaphores=0' | sudo tee -a /etc/modprobe.d/i915.conf
                          

                          I arrived at the above solution by starting with John Lewis’ suggested workaround and experimentally removing redundant overrides (according to modinfo i915 | grep parm output) that re-specified default values.

                          Power

                          Prevent instant shutdown when power key is (accidentally) pressed:

                          echo 'HandlePowerKey=ignore' | sudo tee -a /etc/systemd/logind.conf
                          

                          Wi-Fi

                          Enable Wi-Fi power savings and improve connection stability:

                          echo 'options ath9k ps_enable=1 use_chanctx=1 btcoex_enable=1 bt_ant_diversity=1' | sudo tee -a /etc/modprobe.d/ath9k.conf
                          

                          Sound

                          Specify the sound card that alsamixer(1) should use by default:

                          echo 'options snd_hda_intel index=1' | sudo tee -a /etc/modprobe.d/alsa.conf
                          

                          Keyboard

                          Install the Chromebook keyboard layout provided by Crouton:

                          wget https://raw.githubusercontent.com/dnschneid/crouton/master/targets/keyboard
                          sudo env DISTRO=debian bash ./keyboard
                          

                          Apply the Chromebook keyboard layout from within an X11 session:

                          setxkbmap -model chromebook
                          

                          Sleep

                          Make suspend and resume work correcly when lid is closed and opened:

                          /etc/rc.local

                          #!/bin/sh -e
                          #
                          # rc.local
                          #
                          # This script is executed at the end of each multiuser runlevel.
                          # Make sure that the script will "exit 0" on success or any other
                          # value on error.
                          #
                          # In order to enable or disable this script just change the execution
                          # bits.
                          #
                          # By default this script does nothing.
                          
                          # prevent ehci-pci errors that occur after resume from suspend:
                          # [  386.093443] ehci-pci 0000:00:1d.0: port 2 resume error -19
                          # [  386.093699] ehci-pci 0000:00:1d.0: port 1 resume error -19
                          echo -n 0000:00:1d.0 > /sys/bus/pci/drivers/ehci-pci/unbind
                          
                          /etc/pm/sleep.d/20_acer_c720_chromebook
                          
                          exit 0
                          

                          /etc/pm/sleep.d/20_acer_c720_chromebook

                          #!/bin/sh
                          # the following tweaks were suggested by powertop https://01.org/powertop
                          
                          # turn off bluetooth, which causes OS hangs
                          rfkill block bluetooth
                          
                          # Wireless Power Saving for interface wlan0
                          iwconfig wlan0 power on
                          
                          # NMI watchdog should be turned off
                          echo 0 > /proc/sys/kernel/nmi_watchdog
                          
                          # VM writeback timeout
                          echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
                          
                          # Enable audio codec power management
                          echo 1 > /sys/module/snd_hda_intel/parameters/power_save
                          
                          # Enable SATA link power Management for *
                          for policy in /sys/class/scsi_host/*/link_power_management_policy
                          do echo min_power > $policy
                          done
                          
                          # Runtime PM for PCI Device *
                          for control in /sys/bus/pci/devices/*/power/control
                          do echo auto > $control
                          done
                          
                          # Runtime PM for PCI Device Intel Corporation 8 Series USB xHCI HC
                          echo auto > /sys/bus/pci/devices/0000:00:14.0/power/control
                          
                          # Runtime PM for PCI Device Intel Corporation 8 Series USB EHCI #1
                          echo auto > /sys/bus/pci/devices/0000:00:1d.0/power/control
                          

                          Extras

                          After successful installation, you can set up these extras.

                          1. Install skippy-xd to emulate Chrome OS’ window list (F5) key:

                            sudo add-apt-repository ppa:landronimirc/skippy-xd-daily
                            sudo apt-get update && sudo apt-get install skippy-xd
                            
                          2. Fix zsh-history-substring-search reverse video highlighting in tmux:

                            wget https://mirrors.kernel.org/ubuntu/pool/main/n/ncurses/ncurses-base_5.9+20140118-1ubuntu1_all.deb
                            sudo dpkg -i ncurses-base_5.9+20140118-1ubuntu1_all.deb
                            sudo apt-mark hold ncurses-base
                            
                          3. Get low-battery notifications from LXDE’s battery monitor:

                            1. Right-click on the panel (task bar)
                            2. Choose “Add / Remove Panel Items”
                            3. Click the “Add” button
                            4. Choose “Battery Monitor” from the list
                            5. Click the “Edit” button
                            6. Set the “Alarm command” field to:

                              notify-send -u critical -i battery-empty "Your battery is low" "Plug in the charger!" || xmessage Battery low
                              

                              Note that you must install sudo apt-get install libnotify-bin in order to receive fancy notifications from the command above.

                            7. Set the “Alarm time (minutes left)” field to: 30

                          Automatic HDMI

                          The following scripts configure external displays automatically:

                          Simply run acer-c720-reactor& after starting LXDE to use them.

                          ~/bin/acer-c720-display

                          #!/bin/sh
                          # Uses external display if connected; or internal display otherwise.
                          
                          if grep -q '^connected' /sys/class/drm/card0-HDMI-A-1/status
                          then xrandr --output HDMI1 --auto --dpi 96 --output eDP1 --off
                          else xrandr --auto
                          fi
                          

                          ~/bin/acer-c720-reactor

                          #!/bin/sh
                          # Reacts to hardware events and (re)configures the system accordingly.
                          
                          trap "kill -- -$$" EXIT # terminate all background processes on exit
                          trap exit INT TERM # ensure the above trap is triggered on interrupt
                          
                          dmesg='dmesg --facility auth'
                          depth=$($dmesg | awk '
                            / systemd-logind.+: New session c.+ of user .+/ { depth=NR }
                            END { print depth-1 }
                          ')
                          $dmesg --follow | {
                            # discard old events
                            i=1
                            while [ $i -le $depth ]; do
                              read _discard
                              i=$(( i + 1 ))
                            done
                          
                            # process new events
                            while read event; do
                              case "$event" in
                                # lock screen was unlocked after initial login
                                # or after the laptop was resumed from suspend
                                (*' systemd-logind'*': New session c'*'of user '*\
                                |*' systemd-logind'*': Lid opened.'\
                                |*' systemd-logind'*': Operation finished.')
                                  acer-c720-docking
                                  ;;
                              esac
                            done
                          } &
                          
                          stdbuf -oL udevadm monitor --udev | while read event; do
                            case "$event" in
                              # HDMI cable was either plugged in or unplugged
                              (*' change '*'/devices/pci0000:00/0000:00:02.0/drm/card0 (drm)')
                                acer-c720-display
                                ;;
                            esac
                          done &
                          
                          wait
                          

                          References