Advertisement
Guest User

chrubuntu

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