Creating a ChromeOS recovery drive using Ubuntu

The way to reinstall ChromeOS using Linux is to download a script from Google and run it.

Running sudo linux_recovery.sh failed with an error about the config file:

ERROR: The config file isn't valid.

linux_recovery.sh downloads /tmp/tmp.crosrec/config.txt which contains the URL of the image to download.

The entry for my Chromebook in /tmp/tmp.crosrec/config.txt is:

name=Acer C720 Chromebook
version=8172.62.0
desc=Acer C720 Chromebook
channel=stable-channel
hwidmatch=^PEPPY .*
hwid=
md5=a04e467b5a7727aee51c0079f4bd33cb
sha1=8cecc85e044b363f0b96e096619e24f8dfd96525
zipfilesize=585977912
file=chromeos_8172.62.0_peppy_recovery_stable-channel_mp-v2.bin
filesize=1535082496
url=https://dl.google.com/dl/edgedl/chromeos/recovery/chromeos_8172.62.0_peppy_recovery_stable-channel_mp-v2.bin.zip
/tmp/tmp.crosrec/config.txt

I downloaded the image and used dd to create the USB drive:

wget https://dl.google.com/dl/edgedl/chromeos/recovery/chromeos_8172.62.0_peppy_recovery_stable-channel_mp-v2.bin.zip
unzip chromeos_8172.62.0_peppy_recovery_stable-channel_mp-v2.bin.zip
sudo dd bs=4194304 of=/dev/sdb if=chromeos_8172.62.0_peppy_recovery_stable-channel_mp-v2.bin conv=sync

Installing Ubuntu on a Mac Pro 6,1 (late 2013) and 5,1 (mid 2010)

Thanks to many resources online I was able to install full single-boot Ubuntu on a Mac Pro that I was given at work. Normally I would not buy an unnecessarily expensive computer like this, but since it was free and it had 64 GB of RAM, I decided to keep it.

Initially, I used a third party LiveUSB creator, but later I realized that creating a regular LiveUSB works just fine. All I needed to do was boot with “nomodeset” as a boot parameter and edit the EFI bootloader.

The easiest and most functional procedure was to:

  1. Create a LiveUSB as usual, for example using Startup Disk Creator.
  2. Boot the LiveUSB (boot with option nomodeset) and install Ubuntu on a hard drive.
  3. In the Live USB, use efibootmgr to allow EFI to boot Ubuntu.
  4. Boot Ubuntu with option nomodeset.

Procedure:

  1. Create a LiveUSB Ubuntu as usual. I used Startup Disk Creator in Ubuntu.
  2. Boot Mac OS X and hold Alt while booting. You should see two icons, one saying “Macintosh HD” and another “EFI”.
  3. [Only 6,1] Press “e” and edit the boot command, adding “nomodeset”. This was only necessary on the 6,1. 5,1 booted fine without “nomodeset”.
    setparams 'Install Ubuntu Server'
        set gfxpayload=keep
        linux /install/vmlinuz file=/cdrom/preseed/ubuntu-server.seed nomodeset quiet --
        initrd /install/initrd.gz
  4. [Only 6,1] Press F10 to boot the Ubuntu LiveUSB. Skip this step if installing on 5,1.
  5. Install Ubuntu. I installed it to a USB 3.0 external hard drive because I wanted to preserve Mac OS X in case somebody else inherited this computer later. Install the bootloader on the desired device.
  6. Still in Ubuntu LiveUSB, modify EFI to boot Ubuntu. Follow the steps in this tutorial to get Ubuntu to boot in EFI mode (no need for refind). I did try to use rEFInd but while Ubuntu did boot, it couldn’t use the monitor, even setting nomodeset. Here are the commands I used:
    sudo apt-get update

    Install efibootmgr:

     sudo apt-get install efibootmgr

    Check your EFI to see what Ubuntu is called:

    sudo efibootmgr

    Set Ubuntu to boot first:

    sudo efibootmgr -o 0,80
  7. [Only 6,1] Now it should be possible to reboot and Ubuntu should present the boot screen where different kernels can be chosen. If you see that screen, add “nomodeset” to the boot parameters by pressing “e” in the boot screen. Add “nomodeset” to the end of line starting with “linux”, similarly to step 3.
  8. [Alternative to 7.] In case you don’t see the boot screen, boot the LiveUSB again. Mount the freshly installed / (replace sdc3 by the partition that contains /)
    mkdir fix
    sudo mount /dev/sdc3 fix
    cp fix/boot/grub/grub.cfg fix/boot/grub/grub.cfg.old
    sudo nano fix/boot/grub/grub.cfg

    This file shouldn’t be edited manually, but for the first boot it’s OK. Add nomodeset to the first entry so it looks like this:

    linux /boot/vmlinuz-3.19.0-66-generic.efi.signed root=UUID=242526b7-2821-473d-b0dc-9e9a48ea6364 ro nomodeset quiet splash $vt_handoff
  9. Reboot the LiveUSB Ubuntu, remove the pendrive and Ubuntu should boot normally. It does take a long time to boot and a purple screen (desktop edition) is shown for a while. Eventually it does boot to a full Ubuntu.
  10. [Only 6,1] Insert a USB WiFi adapter, update apt-get. Install Broadcom drivers to use the built-in WiFi:
    sudo apt-get install bcmwl-kernel-source
  11. [Only 6,1] After the first boot, permanently add nomodeset as a boot parameter: Edit file /etc/default/grub
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset"
    sudo update-grub; sudo update-grub2

The computer still boots Mac OS X. I just need to hold Alt while booting and I can choose “Macintosh HD” to boot. Not that I care about having Mac OS X there, but this way I can easily restore the computer back to its original state. I haven’t tested, but it should be a matter of using efibootmgr to reset EFI to boot Mac OS X only:

sudo efibootmgr -o 80

Note 1:

In this setup, Ubuntu is on /dev/sdb but mounts /dev/sda1 (the original Mac SSD), which contains /boot/, a vfat partition. On a Mac Pro 5,1 (late 2010), I physically removed the hard drive containing Mac OS X and installed Ubuntu to a new drive. I created a 200 MB vfat /dev/sda1 as /boot and installed Ubuntu as usual. I was able to single boot Ubuntu without any hiccups.

By the way, installation was easier than in the 6,1 because I didn’t need to use nomodeset; once I had the LiveUSB drive it was just like installing Ubuntu on a regular PC.

Note 2:

I later installed Ubuntu server. The process is the same as the one for the desktop edition.

Note 3:

Due to some bug in Xorg, when running a desktop Ubuntu on the Mac Pro 6,1 and disconnecting the VGA cable, I would get 100% CPU usage caused by kworker. The command below fixed the problem.

sudo sh -c "echo disable > /sys/firmware/acpi/interrupts/gpe16

When I removed Xorg, the problem went away and I could disconnect and connect the VGA cable without any increase in CPU activity. The server edition doesn’t present this problem.

Note 4:

I find the design of the Mac Pro the cheesiest thing ever. Apple designers: “Let’s put as many round edges as possible on this computer because round is cool, right?” No, it looks like an expensive trash can on my desk or a futuristic food processor. Tacky, tacky.

Out of memory problem in linux

I was running an R program written by a third-party and for one specific dataset the process was getting killed. My machine had plenty of RAM available and the process was repeatedly getting killed by the OOM killer.

I read a little about the subject and I learned that I can tune the OOM killer by allowing my system to overcommit memory:

echo 1 > /proc/sys/vm/overcommit_memory

To permanently change this setting from 0 to 1, add this line to /etc/sysctl.conf:

vm.overcommit_memory=1

After doing this, the R process is no longer getting killed.

Problems with Ethernet card NetXtreme BCM5720 on a Dell T320

I have a Dell T320 connected directly to another computer via their gigabit ethernet cards, both running Ubuntu 14.04.

At seemingly random occasions, when transferring data constantly from the Dell to the other computer (several hundred MB’s), the connection dropped both using NFS and ssh. It seemed to be a software problem since restarting the network interface on the Dell fixed the problem (temporarily).

I couldn’t find a pattern but when I was running two tasks concomitantly that made quite a few reads and writes via ethernet over an hour or so, I repeatedly saw the network interface crash. On other light or heavy loads I couldn’t reproduce the problem.

Searching online, I found many reports of similar problems. It’s still unclear to me whether this is a problem with the tg3 driver or a bug in this chipset.

In any case, I decided to install another ethernet card on the Dell. Now, NIC’s for this server are >$100. The solution that I hope will work long-term and has survived the situation above is a cheap (~$15) USB Ethernet adapter connected to a USB 2.0 port.

I am using an Asix AX88179, which required downloading (http://www.asix.com.tw/FrootAttach/driver/AX88179_178A_LINUX_DRIVER_v1.14.2_SOURCE.tar.gz), compiling and installing (very easy) a driver, although I read somewhere that kernels >3.9 don’t need the compiled driver. According to iperf I’m getting gigabit speeds and looking at bmon I don’t notice a performance difference compared to the original card.

So here’s my suggestion if you’re having problems with your original Dell NIC and don’t want to spend much on a solution: buy a USB gigabit Ethernet adapter for $15!

One note: I had to reboot the system after installing the driver to obtain gigabit speeds.

ssh problem with Motorola NVG510

I set up ssh to my laptop at home by allowing the firewall to do ssh to it and it worked fine for a couple of days. A few days later, I couldn’t ping or ssh anymore.

After trying different things, I found out that this modem Motorola NVG510 has a defect. While it was initially doing DNS well, i.e. associating the laptop’s hostname with it’s NAT IP, sometimes it goes crazy. Now it calls my laptop something else with a hostname that I have idea where it came from. The dynamic IP is the same.

Because the firewall was set up to allow ssh to port 22 to a specific hostname, when the modem lost the laptop’s hostname, it wouldn’t relay the ssh connection correctly anymore.

What seems to be working now is to set up Default server (Firewall -> IP passthrough). I set it up to the dynamic IP of my laptop, hoping the NAT IP won’t change. I guess I could try to set up a static IP.

I may buy a decent router and set up the modem to bridge mode.

Setting up sftp access with a key file

A while ago I configured my server for sftp access using a key instead of a password. These are the notes I took when I did it but I haven’t tested it again, but I hope it works.

1. Edit ssh_config, add sftpuser in AllowUsers:

AlllowUsers youruser john mary sftpuser

2. Change where key files are located. Instead of the default ~/.ssh, it is important to put all the keys in a universal place. With the standard path of AuthorizedKeysFile, the public key authentication will fail for chrooted-users because they don’t have a home like all other users. To fix this, we set the AuthorizedKeysFile to a root-owned, non-worldwritable directory and move existing users’ keys.

AuthorizedKeysFile /etc/ssh/authorized_keys/%u

Match User sftpuser
   ChrootDirectory %h
   ForceCommand internal-sftp
   AllowTcpForwarding no
   PermitTunnel no
   X11Forwarding no

3. Run this

$ useradd sftpuser
$ mkdir /home/sftpuser
$ chown root:root /home/sftpuser/
$ chmod 755 /home/sftpuser/
$ cd /home/sftpuser
$ mkdir data
$ chown sftpuser:sftpusr data

Multiple JQuery autocomplete search fields

It’s easy to add multiple search fields using the same autocomplete.js and autocomplete.php, instead of writing one .js and one .php per field.
This is autocomplete.js:

$( ".term" ).live( "focus", function(){
    id=$(this).attr('id');
    $( '#'+id ).autocomplete({
        delay: 300,
        minLength: 2,
        source: "autocomplete.php?ind="+id,
        select: function (event, ui){
            [your code here]
        }
    })
});

Your search fields must be of class “term” (or anything that matches “.term” above in the live() function) and have unique IDs:

<input id="term1" class="term" type="text" />
<input id="term2" class="term" type="text" />

autocomplete.php receives the input field id and performs independent searches.