Advertisement
Guest User

w4gerg

a guest
Jan 16th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.43 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 [ "$chromebook_arch" = "x86_64" ]
  121. then
  122. ubuntu_arch="amd64"
  123. if [ "$ubuntu_metapackage" = "default" ]
  124. then
  125. ubuntu_metapackage="ubuntu-desktop"
  126. fi
  127. elif [ "$chromebook_arch" = "i686" ]
  128. then
  129. ubuntu_arch="i386"
  130. if [ "$ubuntu_metapackage" = "default" ]
  131. then
  132. ubuntu_metapackage="ubuntu-desktop"
  133. fi
  134. elif [ "$chromebook_arch" = "armv7l" ]
  135. then
  136. ubuntu_arch="armhf"
  137. if [ "$ubuntu_metapackage" = "default" ]
  138. then
  139. ubuntu_metapackage="xubuntu-desktop"
  140. fi
  141. else
  142. echo -e "Error: This script doesn't know how to install ChrUbuntu on $chromebook_arch"
  143. exit
  144. fi
  145.  
  146. echo -e "\nChrome device model is: $hwid\n"
  147.  
  148. echo -e "Installing Ubuntu ${ubuntu_version} with metapackage ${ubuntu_metapackage}\n"
  149.  
  150. echo -e "Kernel Arch is: $chromebook_arch Installing Ubuntu Arch: $ubuntu_arch\n"
  151.  
  152. read -p "Press [Enter] to continue..."
  153.  
  154. if [ ! -d /mnt/stateful_partition/ubuntu ]
  155. then
  156. mkdir /mnt/stateful_partition/ubuntu
  157. fi
  158.  
  159. cd /mnt/stateful_partition/ubuntu
  160.  
  161. if [[ "${target_disk}" =~ "mmcblk" ]]
  162. then
  163. target_rootfs="${target_disk}p7"
  164. target_kern="${target_disk}p6"
  165. else
  166. target_rootfs="${target_disk}7"
  167. target_kern="${target_disk}6"
  168. fi
  169.  
  170. echo "Target Kernel Partition: $target_kern Target Root FS: ${target_rootfs}"
  171.  
  172. if mount|grep ${target_rootfs}
  173. then
  174. echo "Refusing to continue since ${target_rootfs} is formatted and mounted. Try rebooting"
  175. exit
  176. fi
  177.  
  178. mkfs.ext4 ${target_rootfs}
  179.  
  180. if [ ! -d /tmp/urfs ]
  181. then
  182. mkdir /tmp/urfs
  183. fi
  184. mount -t ext4 ${target_rootfs} /tmp/urfs
  185.  
  186. tar_file="http://cdimage.ubuntu.com/ubuntu-core/releases/$ubuntu_version/release/ubuntu-core-$ubuntu_version-core-$ubuntu_arch.tar.gz"
  187. if [ $ubuntu_version = "dev" ]
  188. then
  189. ubuntu_animal=`wget --quiet -O - http://changelogs.ubuntu.com/meta-release-development | grep "^Dist: " | tail -1 | sed -r 's/^Dist: (.*)$/\1/'`
  190. tar_file="http://cdimage.ubuntu.com/ubuntu-core/daily/current/$ubuntu_animal-core-$ubuntu_arch.tar.gz"
  191. fi
  192. wget -O - $tar_file | tar xzvvp -C /tmp/urfs/
  193.  
  194. mount -o bind /proc /tmp/urfs/proc
  195. mount -o bind /dev /tmp/urfs/dev
  196. mount -o bind /dev/pts /tmp/urfs/dev/pts
  197. mount -o bind /sys /tmp/urfs/sys
  198.  
  199. if [ -f /usr/bin/old_bins/cgpt ]
  200. then
  201. cp /usr/bin/old_bins/cgpt /tmp/urfs/usr/bin/
  202. else
  203. cp /usr/bin/cgpt /tmp/urfs/usr/bin/
  204. fi
  205.  
  206. chmod a+rx /tmp/urfs/usr/bin/cgpt
  207. cp /etc/resolv.conf /tmp/urfs/etc/
  208. echo chrubuntu > /tmp/urfs/etc/hostname
  209. #echo -e "127.0.0.1 localhost
  210. echo -e "\n127.0.1.1 chrubuntu" >> /tmp/urfs/etc/hosts
  211. # The following lines are desirable for IPv6 capable hosts
  212. #::1 localhost ip6-localhost ip6-loopback
  213. #fe00::0 ip6-localnet
  214. #ff00::0 ip6-mcastprefix
  215. #ff02::1 ip6-allnodes
  216. #ff02::2 ip6-allrouters" > /tmp/urfs/etc/hosts
  217.  
  218. cr_install="wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
  219. add-apt-repository \"deb http://dl.google.com/linux/chrome/deb/ stable main\"
  220. apt-get update
  221. apt-get -y install google-chrome-stable"
  222. if [ $ubuntu_arch = 'armhf' ]
  223. then
  224. cr_install='apt-get -y install chromium-browser'
  225. fi
  226.  
  227. add_apt_repository_package='software-properties-common'
  228. ubuntu_major_version=${ubuntu_version:0:2}
  229. ubuntu_minor_version=${ubuntu_version:3:2}
  230. if [ $ubuntu_major_version -le 12 ] && [ $ubuntu_minor_version -lt 10 ]
  231. then
  232. add_apt_repository_package='python-software-properties'
  233. fi
  234.  
  235. echo -e "apt-get -y update
  236. apt-get -y dist-upgrade
  237. apt-get -y install ubuntu-minimal
  238. apt-get -y install wget
  239. apt-get -y install $add_apt_repository_package
  240. add-apt-repository main
  241. add-apt-repository universe
  242. add-apt-repository restricted
  243. add-apt-repository multiverse
  244. apt-get update
  245. apt-get -y install $ubuntu_metapackage
  246. $cr_install
  247. if [ -f /usr/lib/lightdm/lightdm-set-defaults ]
  248. then
  249. /usr/lib/lightdm/lightdm-set-defaults --autologin user
  250. fi
  251. useradd -m user -s /bin/bash
  252. echo user | echo user:user | chpasswd
  253. adduser user adm
  254. adduser user sudo" > /tmp/urfs/install-ubuntu.sh
  255.  
  256. chmod a+x /tmp/urfs/install-ubuntu.sh
  257. chroot /tmp/urfs /bin/bash -c /install-ubuntu.sh
  258. rm /tmp/urfs/install-ubuntu.sh
  259.  
  260. KERN_VER=`uname -r`
  261. mkdir -p /tmp/urfs/lib/modules/$KERN_VER/
  262. cp -ar /lib/modules/$KERN_VER/* /tmp/urfs/lib/modules/$KERN_VER/
  263. if [ ! -d /tmp/urfs/lib/firmware/ ]
  264. then
  265. mkdir /tmp/urfs/lib/firmware/
  266. fi
  267. cp -ar /lib/firmware/* /tmp/urfs/lib/firmware/
  268.  
  269. echo "console=tty1 debug verbose root=${target_rootfs} rootwait rw lsm.module_locking=0" > kernel-config
  270. vbutil_arch="x86"
  271. if [ $ubuntu_arch = "armhf" ]
  272. then
  273. vbutil_arch="arm"
  274. fi
  275.  
  276. current_rootfs="`rootdev -s`"
  277. current_kernfs_num=$((${current_rootfs: -1:1}-1))
  278. current_kernfs=${current_rootfs: 0:-1}$current_kernfs_num
  279.  
  280. vbutil_kernel --repack ${target_kern} \
  281. --oldblob $current_kernfs \
  282. --keyblock /usr/share/vboot/devkeys/kernel.keyblock \
  283. --version 1 \
  284. --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
  285. --config kernel-config \
  286. --arch $vbutil_arch
  287.  
  288. #Set Ubuntu kernel partition as top priority for next boot (and next boot only)
  289. cgpt add -i 6 -P 5 -T 1 ${target_disk}
  290.  
  291. echo -e "
  292.  
  293. Installation seems to be complete. If ChrUbuntu fails when you reboot,
  294. power off your Chrome OS device and then turn it back on. You'll be back
  295. in Chrome OS. If you're happy with ChrUbuntu when you reboot be sure to run:
  296.  
  297. sudo cgpt add -i 6 -P 5 -S 1 ${target_disk}
  298.  
  299. To make it the default boot option. The ChrUbuntu login is:
  300.  
  301. Username: user
  302. Password: user
  303.  
  304. We're now ready to start ChrUbuntu!
  305. "
  306.  
  307. read -p "Press [Enter] to reboot..."
  308.  
  309. reboot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement