Last active
May 17, 2016 18:14
-
-
Save BlaiseRideout/c7da88d965880e6e5d2d to your computer and use it in GitHub Desktop.
An untested Debian version of ChrUbuntu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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." | |
| exit | |
| fi | |
| 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 | |
| setterm -blank 0 | |
| if [ "$2" != "" ]; then | |
| target_disk=$2 | |
| 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 "" | |
| read -p "Press [Enter] to install ChrDebian on ${target_disk} or CTRL+C to quit" | |
| 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_debian_size=$(($state_size/1024/1024/2)) | |
| rec_debian_size=$(($max_debian_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 Debian. Acceptable range is 5 to $max_debian_size but $rec_debian_size is the recommended maximum: " debian_size | |
| if [ ! $debian_size -ne 0 2>/dev/null ] | |
| then | |
| echo -e "\n\nNumbers only please...\n\n" | |
| continue | |
| fi | |
| if [ $debian_size -lt 5 -o $debian_size -gt $max_debian_size ] | |
| then | |
| echo -e "\n\nThat number is out of range. Enter a number 5 through $max_debian_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=$(($debian_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 Debian." | |
| echo -e "Your Chromebook will reboot, wipe your data and then" | |
| echo -e "you should re-run this script..." | |
| umount -f /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 | |
| # hwid lets us know if this is a Mario (Cr-48), Alex (Samsung Series 5), ZGB (Acer), etc | |
| hwid="`crossystem hwid`" | |
| chromebook_arch="`uname -m`" | |
| latest_debian="stable" | |
| debian_version=${1:-$latest_debian} | |
| if [ "$debian_version" = "latest" ] | |
| then | |
| debian_version=$latest_debian | |
| fi | |
| if [ "$chromebook_arch" = "x86_64" ] | |
| then | |
| debian_arch="amd64" | |
| elif [ "$chromebook_arch" = "i686" ] | |
| then | |
| debian_arch="i386" | |
| elif [ "$chromebook_arch" = "armv7l" ] | |
| then | |
| debian_arch="armhf" | |
| else | |
| echo -e "Error: This script doesn't know how to install ChrDebian on $chromebook_arch" | |
| exit | |
| fi | |
| echo -e "\nChrome device model is: $hwid\n" | |
| echo -e "Installing debian ${debian_version}\n" | |
| echo -e "Kernel Arch is: $chromebook_arch Installing debian Arch: $debian_arch\n" | |
| read -p "Press [Enter] to continue..." | |
| if [ ! -d /mnt/stateful_partition/debian ] | |
| then | |
| mkdir /mnt/stateful_partition/debian | |
| fi | |
| cd /mnt/stateful_partition/debian | |
| 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}" | |
| if mount|grep ${target_rootfs} | |
| then | |
| echo "Refusing to continue since ${target_rootfs} is formatted and mounted. Try rebooting" | |
| exit | |
| fi | |
| mkfs.ext4 ${target_rootfs} | |
| if [ ! -d /tmp/urfs ] | |
| then | |
| mkdir /tmp/urfs | |
| fi | |
| mount -t ext4 ${target_rootfs} /tmp/urfs | |
| echo "Downloading debootstrap..." | |
| debootstrap_deb=$(wget --no-remove-listing -O - -q http://http.debian.net/debian/pool/main/d/debootstrap | grep 'all.deb' | awk -F 'href' '{print $2}' | cut -d '"' -f2 | sort -r | head -n 1) | |
| wget -P debootstrap "http://http.debian.net/debian/pool/main/d/debootstrap/${debootstrap_deb}" | |
| echo -e "cd debootstrap | |
| ar vx $debootstrap_deb | |
| tar xf data.tar.gz | |
| mv usr / | |
| /usr/sbin/debootstrap --arch $debian_arch $debian_version / http://http.debian.net/debian/ | |
| " > /tmp/urfs/run-debootstrap.sh | |
| chmod a+x /tmp/urfs/run-debootstrap.sh | |
| mkdir /tmp/urfs/bin | |
| cp /bin/bash /tmp/urfs | |
| chroot /tmp/urfs bash -c /run-debootstrap.sh | |
| rm /tmp/urfs/run-debootstrap.sh | |
| rm -rf /tmp/urfs/debootstrap | |
| cp /etc/hosts /tmp/urfs/etc/hosts | |
| cp /proc/mounts /tmp/urfs/etc/mtab | |
| mount -o bind /proc /tmp/urfs/proc | |
| mount -o bind /dev /tmp/urfs/dev | |
| mount -o bind /dev/pts /tmp/urfs/dev/pts | |
| mount -o bind /sys /tmp/urfs/sys | |
| # Look for Chrome OS utilities. cgpt and vbutil_kernel are needed. Other utilities are optional but will be copied if they exist in the same directory. | |
| CHROMEBIN_DIR=/usr/bin/old_bins | |
| # This was the contents of /usr/bin/old_bins on my system: | |
| CHROMEBINS=( cgpt chromeos-tpm-recovery common_minimal.sh crossystem dev_debug_vboot dev_sign_file dumpRSAPublicKey dump_kernel_config enable_dev_usb_boot gbb_utility make_dev_firmware.sh make_dev_ssd.sh resign_firmwarefd.sh set_gbb_flags.sh tpm-nvsize tpm_init_temp_fix tpmc vbutil_firmware vbutil_kernel vbutil_key vbutil_keyblock vbutil_what_keys ) | |
| if [ ! -x $CHROMEBIN_DIR/cgpt -o ! -x $CHROMEBIN_DIR/vbutil_kernel ]; then | |
| # If old_bins doesn't exist, use which to locate them. | |
| # We search old_bins first because if they ARE in old_bins, the scripts returned by "which" are something different and won't work. | |
| CHROMEBIN_DIR=`dirname $(which cgpt 2>/dev/null) 2>/dev/null` | |
| if [ ! -x "$CHROMEBIN_DIR/cgpt" -o ! -x "$CHROMEBIN_DIR/vbutil_kernel" ]; then | |
| # If they still weren't found, bail. | |
| echo "Chrome OS binaries not found (need cgpt and vbutil_kernel)." | |
| echo "Did you forget to exit your chroot?" | |
| exit 1 | |
| fi | |
| fi | |
| for BINARY in "${CHROMEBINS[@]}"; do | |
| cp -a "$CHROMEBIN_DIR/$BINARY" /tmp/urfs/usr/bin/ | |
| done | |
| chmod a+rx /tmp/urfs/usr/bin/cgpt | |
| cp /etc/resolv.conf /tmp/urfs/etc/ | |
| echo ChrDebian > /tmp/urfs/etc/hostname | |
| #echo -e "127.0.0.1 localhost | |
| echo -e "\n127.0.1.1 ChrDebian" >> /tmp/urfs/etc/hosts | |
| # The following lines are desirable for IPv6 capable hosts | |
| #::1 localhost ip6-localhost ip6-loopback | |
| #fe00::0 ip6-localnet | |
| #ff00::0 ip6-mcastprefix | |
| #ff02::1 ip6-allnodes | |
| #ff02::2 ip6-allrouters" > /tmp/urfs/etc/hosts | |
| echo -e "apt-get -y update | |
| apt-get -y dist-upgrade | |
| apt-get update | |
| tasksel install standard | |
| tasksel install laptop | |
| useradd -m user -s /bin/bash | |
| echo user | echo user:user | chpasswd | |
| adduser user adm | |
| adduser user sudo" > /tmp/urfs/install-debian.sh | |
| chmod a+x /tmp/urfs/install-debian.sh | |
| chroot /tmp/urfs /bin/bash -c /install-debian.sh | |
| rm /tmp/urfs/install-debian.sh | |
| KERN_VER=`uname -r` | |
| mkdir -p /tmp/urfs/lib/modules/$KERN_VER/ | |
| cp -ar /lib/modules/$KERN_VER/* /tmp/urfs/lib/modules/$KERN_VER/ | |
| if [ ! -d /tmp/urfs/lib/firmware/ ] | |
| then | |
| mkdir /tmp/urfs/lib/firmware/ | |
| fi | |
| cp -ar /lib/firmware/* /tmp/urfs/lib/firmware/ | |
| echo "console=tty1 debug verbose root=${target_rootfs} rootwait rw lsm.module_locking=0" > kernel-config | |
| vbutil_arch="x86" | |
| if [ $debian_arch = "armhf" ] | |
| then | |
| vbutil_arch="arm" | |
| fi | |
| current_rootfs="`rootdev -s`" | |
| current_kernfs_num=$((${current_rootfs: -1:1}-1)) | |
| current_kernfs=${current_rootfs: 0:-1}$current_kernfs_num | |
| vbutil_kernel --repack ${target_kern} \ | |
| --oldblob $current_kernfs \ | |
| --keyblock /usr/share/vboot/devkeys/kernel.keyblock \ | |
| --version 1 \ | |
| --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \ | |
| --config kernel-config \ | |
| --arch $vbutil_arch | |
| #Set debian kernel partition as top priority for next boot (and next boot only) | |
| cgpt add -i 6 -P 5 -T 1 ${target_disk} | |
| echo -e " | |
| Installation seems to be complete. If ChrDebian fails when you reboot, | |
| power off your Chrome OS device and then turn it back on. You'll be back | |
| in Chrome OS. If you're happy with ChrDebian when you reboot be sure to run: | |
| sudo cgpt add -i 6 -P 5 -S 1 ${target_disk} | |
| To make it the default boot option. The ChrDebian login is: | |
| Username: user | |
| Password: user | |
| We're now ready to start ChrDebian! | |
| " | |
| read -p "Press [Enter] to reboot..." | |
| reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment