SHARE
TWEET

chromebook ubuntu 13.04

a guest Apr 9th, 2013 190 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # Based on Chrubuntu 34v87 script
  3.  
  4. BASE_IMAGE_FILE="http://cdimage.ubuntu.com/ubuntu-core/daily/current/raring-core-armhf.tar.gz"
  5.  
  6. # fw_type will always be developer for Mario.
  7. # Alex and ZGB need the developer BIOS installed though.
  8. fw_type="`crossystem mainfw_type`"
  9. if [ ! "$fw_type" = "developer" ]
  10.   then
  11.     echo -e "\nYou're Chromebook is not running a developer BIOS!"
  12.     echo -e "You need to run:"
  13.     echo -e ""
  14.     echo -e "sudo chromeos-firmwareupdate --mode=todev"
  15.     echo -e ""
  16.     echo -e "and then re-run this script."
  17.     return
  18.   else
  19.     echo -e "\nOh good. You're running a developer BIOS...\n"
  20. fi
  21.  
  22. # hwid lets us know if this is a Mario (Cr-48), Alex (Samsung Series 5), ZGB (Acer), etc
  23. hwid="`crossystem hwid`"
  24.  
  25. echo -e "Chome OS model is: $hwid\n"
  26.  
  27. chromebook_arch="`uname -m`"
  28. if [ ! "$chromebook_arch" = "armv7l" ]
  29. then
  30.   echo -e "This version of Ubuntu is for the ARM-based Chromebooks only\n"
  31. else
  32.   echo -e "and you're running on a ARM-based Chromebook, awesome!\n"
  33. fi
  34.  
  35. read -p "Press [Enter] to continue..."
  36.  
  37. powerd_status="`initctl status powerd`"
  38. if [ ! "$powerd_status" = "powerd stop/waiting" ]
  39. then
  40.   echo -e "Stopping powerd to keep display from timing out..."
  41.   initctl stop powerd
  42. fi
  43.  
  44. powerm_status="`initctl status powerm`"
  45. if [ ! "$powerm_status" = "powerm stop/waiting" ]
  46. then
  47.   echo -e "Stopping powerm to keep display from timing out..."
  48.   initctl stop powerm
  49. fi
  50.  
  51. setterm -blank 0
  52.  
  53. # Figure out what the target disk is
  54.  
  55. if [ "$1" != "" ]; then
  56.   target_disk=$1
  57.   echo "Got ${target_disk} as target drive"
  58.   echo ""
  59.   echo "WARNING! All data on this device will be wiped out! Continue at your own risk!"
  60.   echo ""
  61.   if [ "$target_disk" = "/dev/mmcblk0" ]; then
  62.     echo 'Cowardly refusing to install to /dev/mmcblk0 in this mode; run with no args instead'
  63.     echo 'to properly partition your disk!'
  64.     exit 1
  65.   fi
  66.  
  67.   read -p "Press [Enter] to install Ubuntu on ${target_disk} or CTRL+C to quit"
  68.  
  69.   ext_size="`blockdev --getsz ${target_disk}`"
  70.   aroot_size=$((ext_size - 65600 - 33))
  71.   parted --script ${target_disk} "mktable gpt"
  72.   cgpt create ${target_disk}
  73.   # always use 6 and 7 for sanity
  74.   cgpt add -i 6 -b 64 -s 32768 -S 1 -P 5 -l KERN-A -t "kernel" ${target_disk}
  75.   cgpt add -i 7 -b 65600 -s $aroot_size -l ROOT-A -t "rootfs" ${target_disk}
  76.   sync
  77.   blockdev --rereadpt ${target_disk}
  78.   partprobe ${target_disk}
  79.   crossystem dev_boot_usb=1
  80. else
  81.   target_disk="`rootdev -d -s`"
  82.   # Do partitioning (if we haven't already)
  83.   ckern_size="`cgpt show -i 6 -n -s -q ${target_disk}`"
  84.   croot_size="`cgpt show -i 7 -n -s -q ${target_disk}`"
  85.   state_size="`cgpt show -i 1 -n -s -q ${target_disk}`"
  86.  
  87.   max_ubuntu_size=$(($state_size/1024/1024/2))
  88.   rec_ubuntu_size=$(($max_ubuntu_size - 1))
  89.   # If KERN-C and ROOT-C are one, we partition, otherwise assume they're what they need to be...
  90.   if [ "$ckern_size" =  "1" -o "$croot_size" = "1" ]
  91.   then
  92.     while :
  93.     do
  94.       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
  95.       if [ ! $ubuntu_size -ne 0 2>/dev/null ]
  96.       then
  97.         echo -e "\n\nNumbers only please...\n\n"
  98.         continue
  99.       fi
  100.       if [ $ubuntu_size -lt 5 -o $ubuntu_size -gt $max_ubuntu_size ]
  101.       then
  102.         echo -e "\n\nThat number is out of range. Enter a number 5 through $max_ubuntu_size\n\n"
  103.         continue
  104.       fi
  105.       break
  106.     done
  107.     # We've got our size in GB for ROOT-C so do the math...
  108.  
  109.     #calculate sector size for rootc
  110.     rootc_size=$(($ubuntu_size*1024*1024*2))
  111.  
  112.     #kernc is always 16mb
  113.     kernc_size=32768
  114.  
  115.     #new stateful size with rootc and kernc subtracted from original
  116.     stateful_size=$(($state_size - $rootc_size - $kernc_size))
  117.  
  118.     #start stateful at the same spot it currently starts at
  119.     stateful_start="`cgpt show -i 1 -n -b -q ${target_disk}`"
  120.  
  121.     #start kernc at stateful start plus stateful size
  122.     kernc_start=$(($stateful_start + $stateful_size))
  123.  
  124.     #start rootc at kernc start plus kernc size
  125.     rootc_start=$(($kernc_start + $kernc_size))
  126.  
  127.     #Do the real work
  128.    
  129.     echo -e "\n\nModifying partition table to make room for Ubuntu."
  130.     echo -e "Your Chromebook will reboot, wipe your data and then"
  131.     echo -e "you should re-run this script..."
  132.     umount /mnt/stateful_partition
  133.    
  134.     # stateful first
  135.     cgpt add -i 1 -b $stateful_start -s $stateful_size -l STATE ${target_disk}
  136.  
  137.     # now kernc
  138.     cgpt add -i 6 -b $kernc_start -s $kernc_size -l KERN-C ${target_disk}
  139.  
  140.     # finally rootc
  141.     cgpt add -i 7 -b $rootc_start -s $rootc_size -l ROOT-C ${target_disk}
  142.  
  143.     reboot
  144.     exit
  145.   fi
  146. fi
  147.  
  148. if [[ "${target_disk}" =~ "mmcblk" ]]
  149. then
  150.   target_rootfs="${target_disk}p7"
  151.   target_kern="${target_disk}p6"
  152. else
  153.   target_rootfs="${target_disk}7"
  154.   target_kern="${target_disk}6"
  155. fi
  156.  
  157. echo "Target Kernel Partition: $target_kern  Target Root FS: ${target_rootfs}"
  158.  
  159. # try mounting a USB / SD Card if it's there...
  160. if [ ! -d /tmp/usb_files ]; then
  161.   mkdir /tmp/usb_files
  162. fi
  163. mount /dev/sda /tmp/usb_files > /dev/null 2>&1
  164. mount /dev/sda1 /tmp/usb_files > /dev/null 2>&1
  165.  
  166. if [ -z "$IMAGE_FILE" ]; then
  167.   IMAGE_FILE="$BASE_IMAGE_FILE"
  168. fi
  169.  
  170. if [[ "${IMAGE_FILE}" =~ "http" ]]; then
  171.   base_image_file="`basename \"${IMAGE_FILE}\"`"
  172.   if [ -f "/tmp/usb_files/$base_image_file" ]; then
  173.     echo "Using /tmp/usb_files/$base_image_file instead of downloading"
  174.     untar_file="/tmp/usb_files/$base_image_file"
  175.   else
  176.     echo "Downloading $IMAGE_FILE..."
  177.     untar_file="/mnt/stateful_partition/$base_image_file"
  178.     wget -c -O "/mnt/stateful_partition/$base_image_file" "$IMAGE_FILE"
  179.     if [ $? -ne 0 ] ; then
  180.       echo "Download failed!"
  181.       exit 1
  182.     fi
  183.   fi
  184. else
  185.   if [ -f "/tmp/usb_files/$IMAGE_FILE" ]; then
  186.     untar_file="/tmp/usb_files/$IMAGE_FILE"
  187.     echo "Using ${untar_file}"
  188.   elif [ -f "$IMAGE_FILE" ]; then
  189.     untar_file="$IMAGE_FILE"
  190.     echo "Using ${untar_file}"
  191.   else
  192.     echo "File '${IMAGE_FILE}' not found, either on USB device or as absolute path!"
  193.     exit 1
  194.   fi
  195. fi
  196.  
  197. # our mount target
  198. if [ ! -d /tmp/ubuntu ]; then
  199.   mkdir /tmp/ubuntu
  200. fi
  201.  
  202. echo "Creating filesystem on ${target_rootfs}..."
  203. mkfs.ext4 -j ${target_rootfs} && mount ${target_rootfs} /tmp/ubuntu
  204. if [ $? -ne 0 ] ; then
  205.   echo 'Failed to create and/or mount filesystem!'
  206.   exit 1
  207. fi
  208.  
  209. if [[ "$untar_file" =~ "tgz" || "$untar_file" =~ ".gz" ]] ; then
  210.   tar xvzCf /tmp/ubuntu "$untar_file"
  211. elif [[ "$untar_file" =~ "bz2" ]] ; then
  212.   tar xvjCf /tmp/ubuntu "$untar_file"
  213. elif [[ "$untar_file" =~ "xz" ]] ; then
  214.   tar xvJCf /tmp/ubuntu "$untar_file"
  215. else
  216.   echo "Hmm... not sure how to untar your file"
  217.   exit 1
  218. fi
  219.  
  220. # Let's get some firmware in place
  221. cp /lib/firmware/mrvl/sd8797_uapsta.bin /tmp/ubuntu/lib/firmware/mrvl
  222. cp /lib/firmware/mfc_fw.bin /tmp/ubuntu/lib/firmware
  223.  
  224. # Create the setup script in /tmp/setup-script on the ubuntu partition
  225. cat > /tmp/ubuntu/tmp/setup-script <<EOF
  226. # fix up /etc/shadow so root can log in
  227. passwd -d root
  228.  
  229. echo "nameserver 8.8.8.8" > /etc/resolv.conf
  230.  
  231. # update-initramfs will need this
  232. mount -t devpts devpts /dev/pts
  233. mount -t proc proc /proc
  234.  
  235. echo "deb http://ports.ubuntu.com/ubuntu-ports/ raring universe" >> /etc/apt/sources.list
  236. echo "deb http://ppa.launchpad.net/chromebook-arm/ppa/ubuntu raring main" > /etc/apt/sources.list.d/chromebook-arm.list
  237. apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABBBBD6B
  238. apt-get update
  239. apt-get -y install ubuntu-minimal
  240. apt-get -y install language-pack-en-base wpasupplicant
  241. apt-get -y install cgpt chromebook-s3-default-settings vboot-utils
  242. apt-get -y install linux-tools-3.4.0-5
  243. # we need this because update-initrd will still run, even though
  244. # it doesn't need to and the image package doesn't have an initrd
  245. touch /boot/initrd.img-3.4.0-5-chromebook
  246. # --no-install-recommends is there because the image incorrectly
  247. # recommends flash-kernel, which we don't want
  248. apt-get -y install --no-install-recommends linux-image-chromebook
  249. apt-get -y install xserver-xorg-video-armsoc
  250. #chromium-mali-opengles
  251.  
  252. # clean up
  253. umount /dev/pts
  254. umount /proc
  255.  
  256. if [ ! -d /etc/X11/xorg.conf.d ] ; then mkdir /etc/X11/xorg.conf.d ; fi
  257. if [ ! -f /etc/X11/xorg.conf.d/exynos5.conf ] ; then
  258.  
  259. cat > /etc/X11/xorg.conf.d/exynos5.conf <<EOZ
  260. Section "Device"
  261.         Identifier      "Mali FBDEV"
  262.         Driver          "armsoc"
  263.         Option          "fbdev"                 "/dev/fb0"
  264.         Option          "Fimg2DExa"             "false"
  265.         Option          "DRI2"                  "true"
  266.         Option          "DRI2_PAGE_FLIP"        "false"
  267.         Option          "DRI2_WAIT_VSYNC"       "true"
  268. #       Option          "Fimg2DExaSolid"        "false"
  269. #       Option          "Fimg2DExaCopy"         "false"
  270. #       Option          "Fimg2DExaComposite"    "false"
  271.         Option          "SWcursorLCD"           "false"
  272. EndSection
  273.  
  274. Section "Screen"
  275.         Identifier      "DefaultScreen"
  276.         Device          "Mali FBDEV"
  277.         DefaultDepth    24
  278. EndSection
  279.  
  280. EOZ
  281. fi
  282. EOF
  283.  
  284. # run the setup script
  285. chroot /tmp/ubuntu bash /tmp/setup-script
  286.  
  287. echo -e "#!/bin/bash\n" > /tmp/ubuntu/root/quickwpa.sh
  288. echo 'wpa_passphrase $1 $2 | wpa_supplicant -c /dev/stdin -i mlan0 -D nl80211 -B' >> /tmp/ubuntu/root/quickwpa.sh
  289. echo "dhclient mlan0" >> /tmp/ubuntu/root/quickwpa.sh
  290.  
  291. # now set up the kernel
  292. echo "console=tty1 printk.time=1 nosplash rootwait root=${target_rootfs} rw rootfstype=ext4" > /tmp/ubuntu/boot/cmdline
  293. 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
  294. dd if=/tmp/ubuntu/boot/chronos-kernel-image of=${target_kern} bs=512
  295.  
  296. # Unmount ubuntu
  297. umount /tmp/ubuntu
  298.  
  299. # finally make it bootable, but just once (-S 0: flagged as not successful, -T 1: one try)
  300. cgpt add -S 1 -T 1 -P 12 -i 6 ${target_disk}
  301.  
  302. echo -e "\n*****************\n"
  303. echo "Done -- reboot to enter Ubuntu."
  304. echo "In Ubuntu, the root password is blank -- please change it and create a user"
  305. echo ""
  306. echo "To connect to a wireless network, type:"
  307. echo "sh quickwpa.sh myssid mypasskey"
  308. #echo "To set Ubuntu to boot again, use 'cgpt add -S 0 -T 1 -P 12 -i 6 ${target_disk}'"
RAW Paste Data
Top