public
Last active

Install Ubuntu 13.04 on Chromebook

  • Download Gist
install-ubuntu
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
#!/bin/bash
#
# Version 0.2, for Ubuntu 13.04 (Raring)
#
# Based on Chrubuntu 34v87 script
 
BASE_IMAGE_FILE="http://mirrors.med.harvard.edu/ubuntu-cdimage/lubuntu/releases/13.04/release/lubuntu-13.04-preinstalled-desktop-armhf+ac100.tar.gz"
 
# fw_type will always be developer for Mario.
# Alex and ZGB need the developer BIOS installed though.
fw_type="`crossystem mainfw_type`"
if [ ! "$fw_type" = "developer" ]
then
echo -e "\nYou're Chromebook is not running a developer BIOS!"
echo -e "You need to run:"
echo -e ""
echo -e "sudo chromeos-firmwareupdate --mode=todev"
echo -e ""
echo -e "and then re-run this script."
return
else
echo -e "\nOh good. You're running a developer BIOS...\n"
fi
 
# hwid lets us know if this is a Mario (Cr-48), Alex (Samsung Series 5), ZGB (Acer), etc
hwid="`crossystem hwid`"
 
echo -e "Chome OS model is: $hwid\n"
 
chromebook_arch="`uname -m`"
if [ ! "$chromebook_arch" = "armv7l" ]
then
echo -e "This version of Chrome OS is for the ARM-based Chromebooks only\n"
exit 1
else
echo -e "and you're running on a ARM-based Chromebook, awesome!\n"
fi
 
read -p "Press [Enter] to continue..."
 
powerd_status="`initctl status powerd`"
if [ ! "$powerd_status" = "powerd stop/waiting" ]
then
echo -e "Stopping powerd to keep display from timing out..."
initctl stop powerd
fi
 
powerm_status="`initctl status powerm`"
if [ ! "$powerm_status" = "powerm stop/waiting" ]
then
echo -e "Stopping powerm to keep display from timing out..."
initctl stop powerm
fi
 
setterm -blank 0
 
# Figure out what the target disk is
 
if [ "$1" != "" ]; then
target_disk=$1
echo "Got ${target_disk} as target drive"
echo ""
echo "WARNING! All data on this device will be wiped out! Continue at your own risk!"
echo ""
if [ "$target_disk" = "/dev/mmcblk0" ]; then
echo 'Cowardly refusing to install to /dev/mmcblk0 in this mode; run with no args instead'
echo 'to properly partition your disk!'
exit 1
fi
 
read -p "Press [Enter] to install ChrUbuntu on ${target_disk} or CTRL+C to quit"
 
ext_size="`blockdev --getsz ${target_disk}`"
aroot_size=$((ext_size - 65600 - 33))
parted --script ${target_disk} "mktable gpt"
cgpt create ${target_disk}
# always use 6 and 7 for sanity
cgpt add -i 6 -b 64 -s 32768 -S 1 -P 5 -l KERN-A -t "kernel" ${target_disk}
cgpt add -i 7 -b 65600 -s $aroot_size -l ROOT-A -t "rootfs" ${target_disk}
sync
blockdev --rereadpt ${target_disk}
partprobe ${target_disk}
crossystem dev_boot_usb=1
else
target_disk="`rootdev -d -s`"
# Do partitioning (if we haven't already)
ckern_size="`cgpt show -i 6 -n -s -q ${target_disk}`"
croot_size="`cgpt show -i 7 -n -s -q ${target_disk}`"
state_size="`cgpt show -i 1 -n -s -q ${target_disk}`"
 
max_ubuntu_size=$(($state_size/1024/1024/2))
rec_ubuntu_size=$(($max_ubuntu_size - 1))
# If KERN-C and ROOT-C are one, we partition, otherwise assume they're what they need to be...
if [ "$ckern_size" = "1" -o "$croot_size" = "1" ]
then
while :
do
read -p "Enter the size in gigabytes you want to reserve for Ubuntu. Acceptable range is 5 to $max_ubuntu_size but $rec_ubuntu_size is the recommended maximum: " ubuntu_size
if [ ! $ubuntu_size -ne 0 2>/dev/null ]
then
echo -e "\n\nNumbers only please...\n\n"
continue
fi
if [ $ubuntu_size -lt 5 -o $ubuntu_size -gt $max_ubuntu_size ]
then
echo -e "\n\nThat number is out of range. Enter a number 5 through $max_ubuntu_size\n\n"
continue
fi
break
done
# We've got our size in GB for ROOT-C so do the math...
 
#calculate sector size for rootc
rootc_size=$(($ubuntu_size*1024*1024*2))
 
#kernc is always 16mb
kernc_size=32768
 
#new stateful size with rootc and kernc subtracted from original
stateful_size=$(($state_size - $rootc_size - $kernc_size))
 
#start stateful at the same spot it currently starts at
stateful_start="`cgpt show -i 1 -n -b -q ${target_disk}`"
 
#start kernc at stateful start plus stateful size
kernc_start=$(($stateful_start + $stateful_size))
 
#start rootc at kernc start plus kernc size
rootc_start=$(($kernc_start + $kernc_size))
 
#Do the real work
echo -e "\n\nModifying partition table to make room for Ubuntu."
echo -e "Your Chromebook will reboot, wipe your data and then"
echo -e "you should re-run this script..."
umount /mnt/stateful_partition
# stateful first
cgpt add -i 1 -b $stateful_start -s $stateful_size -l STATE ${target_disk}
 
# now kernc
cgpt add -i 6 -b $kernc_start -s $kernc_size -l KERN-C ${target_disk}
 
# finally rootc
cgpt add -i 7 -b $rootc_start -s $rootc_size -l ROOT-C ${target_disk}
 
reboot
exit
fi
fi
 
if [[ "${target_disk}" =~ "mmcblk" ]]
then
target_rootfs="${target_disk}p7"
target_kern="${target_disk}p6"
else
target_rootfs="${target_disk}7"
target_kern="${target_disk}6"
fi
 
echo "Target Kernel Partition: $target_kern Target Root FS: ${target_rootfs}"
 
# try mounting a USB / SD Card if it's there...
if [ ! -d /tmp/usb_files ]; then
mkdir /tmp/usb_files
fi
 
echo "Looking for USB or SD media with image..."
if [ -f /tmp/usb_files/cb-ubuntu ] ; then
echo "Already mounted, great."
else
echo "Trying /dev/sda... (USB)"
mount /dev/sda /tmp/usb_files > /dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "Trying /dev/sda1... (USB)"
mount /dev/sda1 /tmp/usb_files > /dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "Trying /dev/mmcblk1p1... (SD)"
mount /dev/mmcblk1p1 /tmp/usb_files > /dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "No USB or SD media found, will download."
fi
fi
fi
fi
 
if [ -z "$IMAGE_FILE" ]; then
IMAGE_FILE="$BASE_IMAGE_FILE"
fi
 
if [[ "${IMAGE_FILE}" =~ "http" ]]; then
base_image_file="`basename \"${IMAGE_FILE}\"`"
if [ -f "/tmp/usb_files/$base_image_file" ]; then
echo "Using /tmp/usb_files/$base_image_file instead of downloading"
untar_file="/tmp/usb_files/$base_image_file"
else
echo "Downloading $IMAGE_FILE..."
untar_file="/mnt/stateful_partition/$base_image_file"
wget -c -O "/mnt/stateful_partition/$base_image_file" "$IMAGE_FILE"
if [ $? -ne 0 ] ; then
echo "Download failed!"
exit 1
fi
fi
else
if [ -f "/tmp/usb_files/$IMAGE_FILE" ]; then
untar_file="/tmp/usb_files/$IMAGE_FILE"
echo "Using ${untar_file}"
elif [ -f "$IMAGE_FILE" ]; then
untar_file="$IMAGE_FILE"
echo "Using ${untar_file}"
else
echo "File '${IMAGE_FILE}' not found, either on USB device or as absolute path!"
exit 1
fi
fi
 
# our mount target
if [ ! -d /tmp/ubuntu ]; then
mkdir /tmp/ubuntu
fi
 
if [[ -z "$SKIP_UNTAR" ]]; then
echo "Creating filesystem on ${target_rootfs}..."
mkfs.ext4 -j ${target_rootfs} && mount ${target_rootfs} /tmp/ubuntu
if [ $? -ne 0 ] ; then
echo 'Failed to create and/or mount filesystem!'
exit 1
fi
 
if [[ "$untar_file" =~ "tgz" || "$untar_file" =~ ".gz" ]] ; then
tar xvzCf /tmp/ubuntu "$untar_file"
elif [[ "$untar_file" =~ "bz2" ]] ; then
tar xvjCf /tmp/ubuntu "$untar_file"
elif [[ "$untar_file" =~ "xz" ]] ; then
tar xvJCf /tmp/ubuntu "$untar_file"
else
echo "Hmm... not sure how to untar your file"
exit 1
fi
else
if [ -d /tmp/ubuntu/lost+found ] ; then
echo "Skipping untar, /tmp/ubuntu already mounted"
else
echo "Skipping untar, just mounting ${target_rootfs}..."
mount ${target_rootfs} /tmp/ubuntu
if [ $? -ne 0 ] ; then
echo 'Failed to mount filesystem!'
exit 1
fi
fi
fi
 
# Let's get some firmware in place
cp /lib/firmware/mrvl/sd8797_uapsta.bin /tmp/ubuntu/lib/firmware/mrvl
cp /lib/firmware/mfc_fw.bin /tmp/ubuntu/lib/firmware
 
# Create the setup script in /tmp/setup-script on the ubuntu partition
cat > /tmp/ubuntu/tmp/setup-script <<EOF
rm -f /tmp/setup-script-ok
# fix up /etc/shadow so root can log in
passwd -d root
 
echo "nameserver 8.8.8.8" > /etc/resolv.conf
 
# update-initramfs will need this
mount -t devpts devpts /dev/pts
mount -t proc proc /proc
 
add-apt-repository -y ppa:chromebook-arm/ppa
apt-get update
apt-get -y --force-yes remove flash-kernel linux-ac100
apt-get -y --force-yes install cgpt chromebook-s3-default-settings vboot-utils
apt-get -y --force-yes install linux-tools-3.4.0-5
# we need this because update-initrd will still run, even though
# it doesn't need to and the image package doesn't have an initrd
touch /boot/initrd.img-3.4.0-5-chromebook
# --no-install-recommends is there because the image incorrectly
# recommends flash-kernel, which we don't want
apt-get -y --force-yes install --no-install-recommends linux-image-chromebook
apt-get -y --force-yes install xserver-xorg-video-armsoc
apt-get -y --force-yes install chromium-mali-opengles || echo Failed to install chromium-mali-opengles, this is ok
 
# clean up
umount /dev/pts
umount /proc
 
if [ ! -d /etc/X11/xorg.conf.d ] ; then mkdir /etc/X11/xorg.conf.d ; fi
 
cat > /etc/X11/xorg.conf.d/exynos5.conf <<EOZ
Section "Device"
Identifier "Mali FBDEV"
Driver "armsoc"
Option "fbdev" "/dev/fb0"
Option "Fimg2DExa" "false"
Option "DRI2" "true"
Option "DRI2_PAGE_FLIP" "false"
Option "DRI2_WAIT_VSYNC" "true"
# Option "Fimg2DExaSolid" "false"
# Option "Fimg2DExaCopy" "false"
# Option "Fimg2DExaComposite" "false"
Option "SWcursorLCD" "false"
EndSection
 
Section "Screen"
Identifier "DefaultScreen"
Device "Mali FBDEV"
DefaultDepth 24
EndSection
 
Section "InputClass"
Identifier "touchpad"
MatchIsTouchpad "on"
Option "FingerHigh" "5"
Option "FingerLow" "5"
EndSection
 
Section "InputClass"
Identifier "touchpad catchall"
Driver "synaptics"
MatchIsTouchpad "on"
MatchDevicePath "/dev/input/event*"
Option "TapButton1" "1"
Option "TapButton2" "2"
Option "TapButton3" "3"
EndSection
 
EOZ
 
echo ===== successfully executed setup script =====
touch /tmp/setup-script-ok
 
EOF
 
# run the setup script
echo ===== running chroot setup script =====
chroot /tmp/ubuntu bash /tmp/setup-script
 
echo ===== setting up kernel =====
 
# now set up the kernel
echo "console=tty1 printk.time=1 nosplash rootwait root=${target_rootfs} rw rootfstype=ext4" > /tmp/ubuntu/boot/cmdline
vbutil_kernel --pack /tmp/ubuntu/boot/chronos-kernel-image --keyblock /usr/share/vboot/devkeys/kernel.keyblock --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk --config /tmp/ubuntu/boot/cmdline --vmlinuz /tmp/ubuntu/boot/vmlinuz-3.4.0-5-chromebook --version 1 --arch arm
dd if=/tmp/ubuntu/boot/chronos-kernel-image of=${target_kern} bs=512
 
if [ -f /tmp/ubuntu/tmp/setup-script-ok ] ; then
success=1
else
success=0
fi
 
# Make the scripts -- one on the ubuntu partition, and one in local /tmp
echo "cgpt add -S 0 -T 1 -P 12 -i 6 ${target_disk}" > /tmp/ubuntu/bin/chromebook-boot-ubuntu
echo "cgpt add -S 1 -T 1 -P 12 -i 6 ${target_disk}" > /tmp/ubuntu/bin/chromebook-boot-ubuntu-always
chmod +x /tmp/ubuntu/bin/chromebook-boot-ubuntu*
cp /tmp/ubuntu/bin/chromebook-boot-ubuntu /usr/local
cp /tmp/ubuntu/bin/chromebook-boot-ubuntu-always /usr/local
 
# Unmount ubuntu
umount /tmp/ubuntu
 
echo "=========================="
 
if [ $success -ne 1 ] ; then
echo 'Something went wrong while executing the chroot setup script!'
echo 'Look above for more clues.'
exit 1
fi
 
# finally make it bootable, but just once (-S 0: flagged as not successful, -T 1: one try)
cgpt add -S 0 -T 1 -P 12 -i 6 ${target_disk}
 
echo "Done -- reboot to enter Ubuntu (not set as default, only once)."
echo "In Ubuntu, the root password is blank -- please change it and create a user"
echo "To set Ubuntu to boot again once, run"
echo " /usr/local/chromebook-boot-ubuntu"
echo "To always boot Ubuntu (after testing), run"
echo " /usr/local/chromebook-boot-ubuntu-always"
echo "These scripts are also in /bin on the Ubuntu partition."

Have you tested this on a Samsung Chromebook from factory settings yet? Very cool that you sort out the armsoc stuff inside the script.

Cool script, very easy to set up. The touch-pad seems a bit erratic though, sometimes the cursor does not move and other times it clicks when trying to just move cursor.

Any thoughts?

Cheers

this scripted failed when i want to install the image to mmcblk1

So I am looking to install ubuntu on my samsung 3 chomebook. How do i run this from the console?

I tried it last might and it had a couple of glitches.

One minor issue that I had was the SD card was already formated and auto mounted by the ChromeOS. I needed to manually unmount the partitions (trivial), but it would be nice to automagically do this in the script.

I also got an error on this because it could not find the opengles package:

   apt-get -y install xserver-xorg-video-armsoc chromium-mali-opengles

It looks like the chromiuim-mali-opengles package has been removed - but there are still references to it.

Also - I had to manually do some of the commands at the bottom of the setup-script because the "apt-get update" did not pull all of the updates.

Anyway - I was able to boot the system without it after installation.

I am not particularly happy with the default Window manager - looking for something else.

But in general this is pretty close to working.

how can i run this script on ubuntu, sorry if this an obvious questions but im new with this.

thanks for the great info. i believe i installed on my samsung chromebook xe303. i get a message

Ubuntu Raring Ringtail (development branch) localhost.localdomain tty1

it then asks for localhost login. that's where i get stuck. says above that password is blank but for the life of me, i cannot figure out user id. tried admin, user, root, sudo, blank, guest...

what am i missing? any help would be much appreciated.

on further inspection i see the script returned a bunch of error messages on the passwd and all the apt-get; then an error reading kernel file. i suspect there may be a problem somewhere from 202 or lower. again any tips most welcome.

This didn't completely work for me. Upon reboot, I'm greeted with a "plymouthd" error that other people seem to be getting here and elsewhere:
http://virtuallyhyper.com/2013/03/update-chrubuntu-12-04-to-13-04-on-the-samsung-chromebook/
https://bugs.launchpad.net/ubuntu/+source/plymouth/+bug/1082742

Anyone have thoughts for a workaround?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.