Advertisement
Guest User

25 234

a guest
Jan 16th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.71 KB | None | 0 0
  1. # fw_type will always be developer for Mario.
  2. # Alex and ZGB need the developer BIOS installed though.
  3. fw_type="`crossystem mainfw_type`"
  4. if [ ! "$fw_type" = "developer" ]
  5. then
  6. echo -e "\nYou're Chromebook is not running a developer BIOS!"
  7. echo -e "You need to run:"
  8. echo -e ""
  9. echo -e "sudo chromeos-firmwareupdate --mode=todev"
  10. echo -e ""
  11. echo -e "and then re-run this script."
  12. exit
  13. fi
  14.  
  15. powerd_status="`initctl status powerd`"
  16. if [ ! "$powerd_status" = "powerd stop/waiting" ]
  17. then
  18. echo -e "Stopping powerd to keep display from timing out..."
  19. initctl stop powerd
  20. fi
  21.  
  22. setterm -blank 0
  23.  
  24. if [ "$3" != "" ]; then
  25. target_disk=$3
  26. echo "Got ${target_disk} as target drive"
  27. echo ""
  28. echo "WARNING! All data on this device will be wiped out! Continue at your own risk!"
  29. echo ""
  30. read -p "Press [Enter] to install ChrUbuntu on ${target_disk} or CTRL+C to quit"
  31.  
  32. ext_size="`blockdev --getsz ${target_disk}`"
  33. aroot_size=$((ext_size - 65600 - 33))
  34. parted --script ${target_disk} "mktable gpt"
  35. cgpt create ${target_disk}
  36. cgpt add -i 6 -b 64 -s 32768 -S 1 -P 5 -l KERN-A -t "kernel" ${target_disk}
  37. cgpt add -i 7 -b 65600 -s $aroot_size -l ROOT-A -t "rootfs" ${target_disk}
  38. sync
  39. blockdev --rereadpt ${target_disk}
  40. partprobe ${target_disk}
  41. crossystem dev_boot_usb=1
  42. else
  43. target_disk="`rootdev -d -s`"
  44. # Do partitioning (if we haven't already)
  45. ckern_size="`cgpt show -i 6 -n -s -q ${target_disk}`"
  46. croot_size="`cgpt show -i 7 -n -s -q ${target_disk}`"
  47. state_size="`cgpt show -i 1 -n -s -q ${target_disk}`"
  48.  
  49. max_ubuntu_size=$(($state_size/1024/1024/2))
  50. rec_ubuntu_size=$(($max_ubuntu_size - 1))
  51. # If KERN-C and ROOT-C are one, we partition, otherwise assume they're what they need to be...
  52. if [ "$ckern_size" = "1" -o "$croot_size" = "1" ]
  53. then
  54. while :
  55. do
  56. 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
  57. if [ ! $ubuntu_size -ne 0 2>/dev/null ]
  58. then
  59. echo -e "\n\nNumbers only please...\n\n"
  60. continue
  61. fi
  62. if [ $ubuntu_size -lt 5 -o $ubuntu_size -gt $max_ubuntu_size ]
  63. then
  64. echo -e "\n\nThat number is out of range. Enter a number 5 through $max_ubuntu_size\n\n"
  65. continue
  66. fi
  67. break
  68. done
  69. # We've got our size in GB for ROOT-C so do the math...
  70.  
  71. #calculate sector size for rootc
  72. rootc_size=$(($ubuntu_size*1024*1024*2))
  73.  
  74. #kernc is always 16mb
  75. kernc_size=32768
  76.  
  77. #new stateful size with rootc and kernc subtracted from original
  78. stateful_size=$(($state_size - $rootc_size - $kernc_size))
  79.  
  80. #start stateful at the same spot it currently starts at
  81. stateful_start="`cgpt show -i 1 -n -b -q ${target_disk}`"
  82.  
  83. #start kernc at stateful start plus stateful size
  84. kernc_start=$(($stateful_start + $stateful_size))
  85.  
  86. #start rootc at kernc start plus kernc size
  87. rootc_start=$(($kernc_start + $kernc_size))
  88.  
  89. #Do the real work
  90.  
  91. echo -e "\n\nModifying partition table to make room for Ubuntu."
  92. echo -e "Your Chromebook will reboot, wipe your data and then"
  93. echo -e "you should re-run this script..."
  94. umount -f /mnt/stateful_partition
  95.  
  96. # stateful first
  97. cgpt add -i 1 -b $stateful_start -s $stateful_size -l STATE ${target_disk}
  98.  
  99. # now kernc
  100. cgpt add -i 6 -b $kernc_start -s $kernc_size -l KERN-C ${target_disk}
  101.  
  102. # finally rootc
  103. cgpt add -i 7 -b $rootc_start -s $rootc_size -l ROOT-C ${target_disk}
  104.  
  105. reboot
  106. exit
  107. fi
  108. fi
  109.  
  110. # hwid lets us know if this is a Mario (Cr-48), Alex (Samsung Series 5), ZGB (Acer), etc
  111. hwid="`crossystem hwid`"
  112.  
  113. chromebook_arch="`uname -m`"
  114.  
  115. ubuntu_metapackage=${1:-default}
  116.  
  117. latest_ubuntu=`wget --quiet -O - http://changelogs.ubuntu.com/meta-release | grep "^Version: " | tail -1 | sed -r 's/^Version: ([^ ]+)( LTS)?$/\1/'`
  118. ubuntu_version=${2:-$latest_ubuntu}
  119.  
  120. if [ "$ubuntu_version" = "lts" ]
  121. then
  122. ubuntu_version=`wget --quiet -O - http://changelogs.ubuntu.com/meta-release | grep "^Version:" | grep "LTS" | tail -1 | sed -r 's/^Version: ([^ ]+)( LTS)?$/\1/'`
  123. elif [ "$ubuntu_version" = "latest" ]
  124. then
  125. ubuntu_version=$latest_ubuntu
  126. fi
  127.  
  128. if [ "$chromebook_arch" = "x86_64" ]
  129. then
  130. ubuntu_arch="amd64"
  131. if [ "$ubuntu_metapackage" = "default" ]
  132. then
  133. ubuntu_metapackage="ubuntu-desktop"
  134. fi
  135. elif [ "$chromebook_arch" = "i686" ]
  136. then
  137. ubuntu_arch="i386"
  138. if [ "$ubuntu_metapackage" = "default" ]
  139. then
  140. ubuntu_metapackage="ubuntu-desktop"
  141. fi
  142. elif [ "$chromebook_arch" = "armv7l" ]
  143. then
  144. ubuntu_arch="armhf"
  145. if [ "$ubuntu_metapackage" = "default" ]
  146. then
  147. ubuntu_metapackage="xubuntu-desktop"
  148. fi
  149. else
  150. echo -e "Error: This script doesn't know how to install ChrUbuntu on $chromebook_arch"
  151. exit
  152. fi
  153.  
  154. echo -e "\nChrome device model is: $hwid\n"
  155.  
  156. echo -e "Installing Ubuntu ${ubuntu_version} with metapackage ${ubuntu_metapackage}\n"
  157.  
  158. echo -e "Kernel Arch is: $chromebook_arch Installing Ubuntu Arch: $ubuntu_arch\n"
  159.  
  160. read -p "Press [Enter] to continue..."
  161.  
  162. if [ ! -d /mnt/stateful_partition/ubuntu ]
  163. then
  164. mkdir /mnt/stateful_partition/ubuntu
  165. fi
  166.  
  167. cd /mnt/stateful_partition/ubuntu
  168.  
  169. if [[ "${target_disk}" =~ "mmcblk" ]]
  170. then
  171. target_rootfs="${target_disk}p7"
  172. target_kern="${target_disk}p6"
  173. else
  174. target_rootfs="${target_disk}7"
  175. target_kern="${target_disk}6"
  176. fi
  177.  
  178. echo "Target Kernel Partition: $target_kern Target Root FS: ${target_rootfs}"
  179.  
  180. if mount|grep ${target_rootfs}
  181. then
  182. echo "Refusing to continue since ${target_rootfs} is formatted and mounted. Try rebooting"
  183. exit
  184. fi
  185.  
  186. mkfs.ext4 ${target_rootfs}
  187.  
  188. if [ ! -d /tmp/urfs ]
  189. then
  190. mkdir /tmp/urfs
  191. fi
  192. mount -t ext4 ${target_rootfs} /tmp/urfs
  193.  
  194. tar_file="http://cdimage.ubuntu.com/ubuntu-core/releases/$ubuntu_version/release/ubuntu-core-$ubuntu_version-core-$ubuntu_arch.tar.gz"
  195. if [ $ubuntu_version = "dev" ]
  196. then
  197. ubuntu_animal=`wget --quiet -O - http://changelogs.ubuntu.com/meta-release-development | grep "^Dist: " | tail -1 | sed -r 's/^Dist: (.*)$/\1/'`
  198. tar_file="http://cdimage.ubuntu.com/ubuntu-core/daily/current/$ubuntu_animal-core-$ubuntu_arch.tar.gz"
  199. fi
  200. wget -O - $tar_file | tar xzvvp -C /tmp/urfs/
  201.  
  202. mount -o bind /proc /tmp/urfs/proc
  203. mount -o bind /dev /tmp/urfs/dev
  204. mount -o bind /dev/pts /tmp/urfs/dev/pts
  205. mount -o bind /sys /tmp/urfs/sys
  206.  
  207. if [ -f /usr/bin/old_bins/cgpt ]
  208. then
  209. cp /usr/bin/old_bins/cgpt /tmp/urfs/usr/bin/
  210. else
  211. cp /usr/bin/cgpt /tmp/urfs/usr/bin/
  212. fi
  213.  
  214. chmod a+rx /tmp/urfs/usr/bin/cgpt
  215. cp /etc/resolv.conf /tmp/urfs/etc/
  216. echo chrubuntu > /tmp/urfs/etc/hostname
  217. #echo -e "127.0.0.1 localhost
  218. echo -e "\n127.0.1.1 chrubuntu" >> /tmp/urfs/etc/hosts
  219. # The following lines are desirable for IPv6 capable hosts
  220. #::1 localhost ip6-localhost ip6-loopback
  221. #fe00::0 ip6-localnet
  222. #ff00::0 ip6-mcastprefix
  223. #ff02::1 ip6-allnodes
  224. #ff02::2 ip6-allrouters" > /tmp/urfs/etc/hosts
  225.  
  226. cr_install="wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
  227. add-apt-repository \"deb http://dl.google.com/linux/chrome/deb/ stable main\"
  228. apt-get update
  229. apt-get -y install google-chrome-stable"
  230. if [ $ubuntu_arch = 'armhf' ]
  231. then
  232. cr_install='apt-get -y install chromium-browser'
  233. fi
  234.  
  235. add_apt_repository_package='software-properties-common'
  236. ubuntu_major_version=${ubuntu_version:0:2}
  237. ubuntu_minor_version=${ubuntu_version:3:2}
  238. if [ $ubuntu_major_version -le 12 ] && [ $ubuntu_minor_version -lt 10 ]
  239. then
  240. add_apt_repository_package='python-software-properties'
  241. fi
  242.  
  243. echo -e "apt-get -y update
  244. apt-get -y dist-upgrade
  245. apt-get -y install ubuntu-minimal
  246. apt-get -y install wget
  247. apt-get -y install $add_apt_repository_package
  248. add-apt-repository main
  249. add-apt-repository universe
  250. add-apt-repository restricted
  251. add-apt-repository multiverse
  252. apt-get update
  253. apt-get -y install $ubuntu_metapackage
  254. $cr_install
  255. if [ -f /usr/lib/lightdm/lightdm-set-defaults ]
  256. then
  257. /usr/lib/lightdm/lightdm-set-defaults --autologin user
  258. fi
  259. useradd -m user -s /bin/bash
  260. echo user | echo user:user | chpasswd
  261. adduser user adm
  262. adduser user sudo" > /tmp/urfs/install-ubuntu.sh
  263.  
  264. chmod a+x /tmp/urfs/install-ubuntu.sh
  265. chroot /tmp/urfs /bin/bash -c /install-ubuntu.sh
  266. rm /tmp/urfs/install-ubuntu.sh
  267.  
  268. KERN_VER=`uname -r`
  269. mkdir -p /tmp/urfs/lib/modules/$KERN_VER/
  270. cp -ar /lib/modules/$KERN_VER/* /tmp/urfs/lib/modules/$KERN_VER/
  271. if [ ! -d /tmp/urfs/lib/firmware/ ]
  272. then
  273. mkdir /tmp/urfs/lib/firmware/
  274. fi
  275. cp -ar /lib/firmware/* /tmp/urfs/lib/firmware/
  276.  
  277. echo "console=tty1 debug verbose root=${target_rootfs} rootwait rw lsm.module_locking=0" > kernel-config
  278. vbutil_arch="x86"
  279. if [ $ubuntu_arch = "armhf" ]
  280. then
  281. vbutil_arch="arm"
  282. fi
  283.  
  284. current_rootfs="`rootdev -s`"
  285. current_kernfs_num=$((${current_rootfs: -1:1}-1))
  286. current_kernfs=${current_rootfs: 0:-1}$current_kernfs_num
  287.  
  288. vbutil_kernel --repack ${target_kern} \
  289. --oldblob $current_kernfs \
  290. --keyblock /usr/share/vboot/devkeys/kernel.keyblock \
  291. --version 1 \
  292. --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
  293. --config kernel-config \
  294. --arch $vbutil_arch
  295.  
  296. #Set Ubuntu kernel partition as top priority for next boot (and next boot only)
  297. cgpt add -i 6 -P 5 -T 1 ${target_disk}
  298.  
  299. echo -e "
  300.  
  301. Installation seems to be complete. If ChrUbuntu fails when you reboot,
  302. power off your Chrome OS device and then turn it back on. You'll be back
  303. in Chrome OS. If you're happy with ChrUbuntu when you reboot be sure to run:
  304.  
  305. sudo cgpt add -i 6 -P 5 -S 1 ${target_disk}
  306.  
  307. To make it the default boot option. The ChrUbuntu login is:
  308.  
  309. Username: user
  310. Password: user
  311.  
  312. We're now ready to start ChrUbuntu!
  313. "
  314.  
  315. read -p "Press [Enter] to reboot..."
  316.  
  317. reboot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement