forked from keithzg/chrubuntu-script
-
Notifications
You must be signed in to change notification settings - Fork 2
/
chrubuntu-install.sh
executable file
·590 lines (505 loc) · 19.8 KB
/
chrubuntu-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
#!/bin/bash
#
# Script to install Ubuntu on Chromebooks
#
# Copyright 2012-2013 Jay Lee
#
# here would be nice to have some license - BSD one maybe
#
# Allow debugging
if [ -n "$DEBUG" ]; then
echo "Enabling debug mode"
DEBUG_WRAP="echo"
DEBUG_CMD="set -x"
set -x
exec 2>&1
else
set -e
fi
# User related defaults
user_name="user"
auto_login="[ -f /usr/lib/lightdm/lightdm-set-defaults ] && /usr/lib/lightdm/lightdm-set-defaults --autologin user"
# hwid lets us know if this is a Mario (Cr-48), Alex (Samsung Series 5), ZGB (Acer), etc
hwid="`crossystem hwid`" || hwid="cross"
# Target specifications
target_mnt="/tmp/urfs"
chromebook_arch="`uname -m`"
host_name="chrubuntu"
ubuntu_metapackage="default"
ubuntu_latest=`wget --quiet -O - http://changelogs.ubuntu.com/meta-release | grep "^Version: " | tail -1 | sed -r 's/^Version: ([^ ]+)( LTS)?$/\1/'`
ubuntu_version=$ubuntu_latest
base_pkgs="ubuntu-minimal locales tzdata dialog wget"
ppas=""
setterm -blank 0
# Basic sanity checks
# Make sure that we have root permissions
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Make sure we run as bash
if [ ! $BASH_VERSION ]; then
echo "This script must be run in bash"
exit 1
fi
if [ ! "$hwid" = "cross" ]; then
# 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" -a ! "$hwid" = "cross" ]; then
echo -e "You're Chromebook is not running a developer BIOS!\n"
echo -e "You need to run:\n"
echo -e "\tsudo chromeos-firmwareupdate --mode=todev\n"
echo -e "and then re-run this script."
exit
fi
fi
# Gather options from command line and set flags
while getopts aeh:m:np:P:rt:v: opt; do
case "$opt" in
a) always="yes" ;;
e) encrypt_home="--encrypt-home"
base_pkgs="$base_pkgs ecryptfs-utils" ;;
h) host_name=${OPTARG} ;;
m) ubuntu_metapackage=${OPTARG} ;;
n) unset auto_login ;;
p) pkgs="$pkgs ${OPTARG}" ;;
P) ppas="$ppas ${OPTARG}" ;;
r) repart="yes" ;;
t) target_disk=${OPTARG} ;;
v) ubuntu_version=${OPTARG} ;;
*) cat <<EOB
Usage: [DEBUG=yes] sudo $0 [-m <ubuntu_metapackage>] [-n ] [-p <ppa:user/repo>] [-r] [-t <disk>] [-v <ubuntu_version>]
-a : Always boot into ubuntu
-e : Enable user home folder encryption
-h : Specify hostname for target system (default is chrubuntu)
-m : Ubuntu meta package (Desktop environment)
-n : Disable user auto logon
-p : Specify additional packages, might be called multiple times (space separated)
-P : Specify additional PPAs, might be called multiple times (space separated)
-r : Repartition disk
-t : Specify target disk
-v : Specify ubuntu version (lts/latest/dev)
Example: $0 -a -e -m "ubuntu-standard" -n -p "mc htop" -P "ppa:eugenesan/ppa ppa:nilarimogard/webupd8" -r -t "/dev/sdc" -v "lts".
EOB
exit 1 ;;
esac
done
# Fetch missing bit in cross mode from ChromeOS recovery or stop powerd in native mode
if [ "$hwid" = "cross" ]; then
echo "Running in cross mode"
# Get platform url
echo "Fetching recovery index..."
wget -q -c https://dl.google.com/dl/edgedl/chromeos/recovery/recovery.conf -O recovery.conf
echo "Select your platfrom..."
IFS_OLD=$IFS
IFS=$'\n'
for line in $(grep -e '^name=' -e '^url=' recovery.conf); do
if echo "$line" | grep '^url=' > /dev/null; then
# We reached previousely selected platfrom
# Extracting recovery url
if [ "$yesno" = "y" ]; then
url=$(echo "$line" | cut -f2 -d'=')
break
fi
else
name=$(echo "$line" | cut -f2 -d'=')
read -p "Name: $name, [y/N]?" yesno
if [ "$yesno" = "y" ]; then
continue
else
unset yesno
fi
fi
done
IFS=$IFS_OLD
echo "Fetching recovery image [$url]..."
wget -c $url -O recovery.zip
# Unpack recovery image
echo "Unpacking recovery image..."
7z x recovery.zip -so > recovery.img
# Extract ChromeOS kernel. On recovery images.
# Kern A is the recovery kernel, Kern B is what we want.
echo "Mounting recovery boot partition..."
mkdir -p $target_mnt
umount $target_mnt || echo .
mount -ro loop,offset=$((`cgpt show -i 12 -n -b -q recovery.img`*512)) recovery.img $target_mnt
echo "Extracting ChromeOS kernel image..."
cp $target_mnt/syslinux/vmlinuz.B vmlinuz
killall nautilus || echo .
umount $target_mnt
# Extract ChromeOS kernel modules.
# Get start and size of our root partition
echo "Mounting recovery rootfs partition..."
rootfs_start="`cgpt show -i 3 -n -b -q recovery.img`"
mkdir -p $target_mnt
umount $target_mnt || echo .
mount -ro loop,offset=$(($rootfs_start*512)) recovery.img $target_mnt
echo "Extracting ChromeOS kernel modules/firmwares..."
tar -C $target_mnt -cf vmlinuz.tar lib/modules lib/firmware
killall nautilus || echo .
chromebook_arch=`file $target_mnt/sbin/init | awk '{print $7}'`
umount $target_mnt
rm -R $target_mnt recovery.img
else
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
fi
# Partitioning
if [ -n "$target_disk" -o "$hwid" = "cross" ]; then
echo -e "Got ${target_disk} as target drive\n"
echo -e "WARNING! All data on this device will be wiped out! Continue at your own risk!\n"
read -p "Press [Enter] to install ChrUbuntu on ${target_disk} or CTRL+C to quit"
ext_size="`blockdev --getsz ${target_disk}`"
aroot_size=$((ext_size - 65600 - 33))
parted --script ${target_disk} "mktable gpt"
cgpt create ${target_disk}
cgpt add -i 6 -b 64 -s 32768 -S 1 -P 5 -l KERN-A -t "kernel" ${target_disk}
cgpt add -i 7 -b 65600 -s $aroot_size -l ROOT-A -t "rootfs" ${target_disk}
sync
blockdev --rereadpt ${target_disk}
partprobe ${target_disk}
[ "$hwid" = "cross" ] || crossystem dev_boot_usb=1
else
# Get default root device
target_disk="`rootdev -d -s`"
echo -e "Using ${target_disk} as target drive\n"
# Read all required partitions parameters (ROOT-C and KERN-C starts are for optional restore later)
ckern_start="`cgpt show -i 6 -n -b -q ${target_disk}`"
ckern_size="`cgpt show -i 6 -n -s -q ${target_disk}`"
croot_start="`cgpt show -i 7 -n -b -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}`"
state_start="`cgpt show -i 1 -n -b -q ${target_disk}`"
broot_start="`cgpt show -i 5 -n -b -q ${target_disk}`"
# 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" -o "$repart" = "yes" ]; then
echo -e "WARNING! All data on this device will be wiped out! Continue at your own risk!\n"
read -p "Press [Enter] to install ChrUbuntu on ${target_disk} or CTRL+C to quit"
# Do partitioning (if we haven't already)
max_ubuntu_size=$((($broot_start-$state_start)/1024/1024/2))
# Try reverse order if calculations goes wrong.
# Observed on recent Parrot machines with 320GB HDD
if [ $max_ubuntu_size -lt 0 ]; then
echo -e "WARNING! Looks like your system has weird partitions layout!"
echo -e "ROOT-A/ROOT-B/STATEFUL resides in reverse order."
echo -e "Continue at your own risk!"
read -p "Press [Enter] to continue or CTRL+C to quit"
max_ubuntu_size=$(($state_size/1024/1024/2))
stateful_size=$state_size
else
stateful_size=$(($broot_start-$state_start))
fi
rec_ubuntu_size=$(($max_ubuntu_size - 1))
while :; do
echo -e "\nEnter the size in gigabytes you want to reserve for Ubuntu."
echo -e "(Acceptable range is 5 to $max_ubuntu_size, but $rec_ubuntu_size is the recommended maximum)"
read -p "Ubuntu Size: " ubuntu_size
if [ ! $ubuntu_size -ne -1 2 > /dev/null ]; then
echo -e "\n\nNumbers only please...\n\n"
continue
fi
if [ $ubuntu_size -lt 0 -o $ubuntu_size -gt $max_ubuntu_size ]; then
echo -e "\n\nThat number is out of range. Enter a number 5 through $max_ubuntu_size\n\n"
continue
fi
break
done
# We've got our size in GB for ROOT-C so do the math...
if [ "$ubuntu_size" = "0" ]; then
# If zero size specified we revert to original layout
# TODO: Store ckern_start and croot_start somewhere on device and use them for reconstruction
rootc_size=1
kernc_size=1
else
# Calculate sector size for rootc
rootc_size=$(($ubuntu_size*1024*1024*2))
# Pin kernc always at 16mb
kernc_size=32768
fi
# New stateful start is the same as original one
stateful_start=$state_start
# New stateful size with rootc and kernc subtracted from original
stateful_size=$((stateful_size - $rootc_size - $kernc_size))
# Start kernc at stateful start plus stateful size
kernc_start=$(($state_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 Ubuntu."
echo -e "Your Chromebook will reboot, wipe your data and then"
echo -e "you should re-run this script..."
read -p "Press [Enter] to continue or CTRL+C to quit"
if [ "$repart" = "yes" ]; then
# Kill old parts
$DEBUG_WRAP cgpt add -i 1 -t unused ${target_disk}
$DEBUG_WRAP cgpt add -i 6 -t unused ${target_disk}
$DEBUG_WRAP cgpt add -i 7 -t unused ${target_disk}
fi
# Make stateful first
$DEBUG_WRAP cgpt add -i 1 -b $stateful_start -s $stateful_size -t data -l STATE ${target_disk}
# Now kernc
$DEBUG_WRAP cgpt add -i 6 -b $kernc_start -s $kernc_size -t kernel -l KERN-C ${target_disk}
# Finally rootc
$DEBUG_WRAP cgpt add -i 7 -b $rootc_start -s $rootc_size -t rootfs -l ROOT-C ${target_disk}
echo -e "Finished partitioning. Reboot is required to continue installation."
echo -e "After reboot re-run the installation."
read -p "Press [Enter] to reboot or CTRL+C to quit"
reboot
exit
fi
fi
# Ubuntu architecture
if [ "$chromebook_arch" = "x86_64" ]; then
ubuntu_arch="amd64"
[ "$ubuntu_metapackage" = "default" ] && ubuntu_metapackage="ubuntu-desktop"
elif [ "$chromebook_arch" = "i686" -o "$chromebook_arch" = "Intel" ]; then
ubuntu_arch="i386"
[ "$ubuntu_metapackage" = "default" ] && ubuntu_metapackage="ubuntu-desktop"
elif [ "$chromebook_arch" = "armv7l" -o "$chromebook_arch" = "arm" ]; then
ubuntu_arch="armhf"
[ "$ubuntu_metapackage" = "default" ] && ubuntu_metapackage="xubuntu-desktop"
else
echo -e "Error: This script doesn't know how to install ChrUbuntu on $chromebook_arch"
exit
fi
# Ubuntu versioning
if [ "$ubuntu_version" = "lts" ]; then
ubuntu_version=`wget --quiet -O - http://changelogs.ubuntu.com/meta-release | grep "^Version:" | grep "LTS" | tail -1 | sed -r 's/^Version: ([^ ]+)( LTS)?$/\1/'`
elif [ "$ubuntu_version" = "latest" ]; then
ubuntu_version=$ubuntu_latest
fi
if [ "$ubuntu_version" = "dev" ]; then
ubuntu_codename=`wget --quiet -O - http://changelogs.ubuntu.com/meta-release-development | grep "^Dist: " | tail -1 | sed -r 's/^Dist: (.*)$/\1/'`
ubuntu_version=`wget --quiet -O - http://changelogs.ubuntu.com/meta-release-development | grep "^Version:" | tail -1 | sed -r 's/^Version: ([^ ]+)( LTS)?$/\1/'`
tar_file="http://cdimage.ubuntu.com/ubuntu-core/daily/current/$ubuntu_codename-core-$ubuntu_arch.tar.gz"
else
tar_file="http://cdimage.ubuntu.com/ubuntu-core/releases/$ubuntu_version/release/ubuntu-core-$ubuntu_version-core-$ubuntu_arch.tar.gz"
fi
# Convert $ubuntu_version from 12.04.3 to 1204
ubuntu_version=`echo $ubuntu_version | cut -f1,2 -d. | sed -e 's/\.//g'`
# ChrUbuntu partitions configuration
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
# Print summary
echo -e "\nChrome device model is: $hwid\n"
echo -e "Installing Ubuntu $ubuntu_version with metapackage $ubuntu_metapackage\n"
echo -e "Kernel Arch is: $chromebook_arch Installing Ubuntu Arch: $ubuntu_arch\n"
echo -e "Target Kernel Partition: $target_kern, Target Root FS: ${target_rootfs}, Target Mount Point: ${target_mnt}\n"
read -p "Press [Enter] to continue..."
if mount | grep ${target_rootfs} > /dev/null; then
echo "Found formatted and mounted ${target_rootfs}."
echo "Continue at your own risk!"
read -p "Press [Enter] to continue or CTRL+C to quit"
umount ${target_mnt}/{dev/pts,dev,sys,proc,}
fi
# Creating target filesystem
mkfs.ext4 ${target_rootfs}
mkdir -p $target_mnt
mount -t ext4 ${target_rootfs} $target_mnt
# Fetching and unpacking target template
wget -O - $tar_file | tar xzp -C $target_mnt/
# Preparing target's mounts for chroot
for mnt in dev dev/pts sys proc; do
mount -o bind /$mnt $target_mnt/$mnt
done
# Inject working network config into target
cp /etc/resolv.conf $target_mnt/etc/
echo $host_name > $target_mnt/etc/hostname
# Select coresponding apt repos tool
if [ $ubuntu_version -lt 1210 ]; then
add_apt_repository_package='python-software-properties'
else
add_apt_repository_package='software-properties-common'
pkgs="$pkgs libnss-myhostname"
fi
# Create and run 1st 2nd stage installation script
echo "$DEBUG_CMD" > $target_mnt/install-ubuntu.sh
echo "
$DEBUG_CMD
apt-get -y update
apt-get -y install aptitude
aptitude -y dist-upgrade
aptitude -y install $base_pkgs $add_apt_repository_package
locale-gen en_US.UTF-8
update-locale LANG=en_US.UTF-8
dpkg-reconfigure tzdata
service stop rsyslog || echo .
service stop cron || echo .
" >> $target_mnt/install-ubuntu.sh
chmod a+x $target_mnt/install-ubuntu.sh
chroot $target_mnt /bin/bash -c /install-ubuntu.sh
rm $target_mnt/install-ubuntu.sh
# Enable all ubuntu components
for component in main universe restricted multiverse partner; do
sed -i "/^# deb.*$component/ s/^# //" $target_mnt/etc/apt/sources.list
done
# Create and run 2nd 2nd-stage installation script
echo "$DEBUG_CMD" > $target_mnt/install-ubuntu.sh
for ppa in $ppas; do
# Add repositories addition to 2nd stage installation script
echo "add-apt-repository -y $ppa" >> $target_mnt/install-ubuntu.sh
done
if echo "$ubuntu_metapackage" | grep desktop > /dev/null; then
if [ ! $ubuntu_arch = 'armhf' ] ; then
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> $target_mnt/etc/apt/sources.list.d/google-chrome.list
pkgs="$pkgs google-chrome-stable"
else
pkgs="$pkgs chromium-browser"
fi
fi
echo "
aptitude -y update
aptitude -y dist-upgrade
aptitude -y --allow-untrusted install $pkgs $ubuntu_metapackage
service stop rsyslog || echo .
service stop cron || echo .
" >> $target_mnt/install-ubuntu.sh
chmod a+x $target_mnt/install-ubuntu.sh
chroot $target_mnt /bin/bash -c /install-ubuntu.sh
rm $target_mnt/install-ubuntu.sh
# Create and run 3rd 2nd-stage installation script
echo "$DEBUG_CMD" > $target_mnt/install-ubuntu.sh
if [ $ubuntu_version -lt 1304 ]; then
# pre-raring
# Inject cgpt tool into target
if [ -f /usr/bin/old_bins/cgpt ]; then
cp -p /usr/bin/old_bins/cgpt $target_mnt/usr/bin/
else
cp -p /usr/bin/cgpt $target_mnt/usr/bin/
fi
else
# post-raring
# Inject cgpt and vboot tools into target
echo "aptitude -y install cgpt vboot-kernel-utils" >> $target_mnt/install-ubuntu.sh
if [ $ubuntu_arch = "armhf" ]; then
cat > $target_mnt/usr/share/X11/xorg.conf.d/exynos5.conf <<EOZ
Section "Device"
Identifier "Mali FBDEV"
Driver "armsoc"
Option "fbdev" "/dev/fb0"
Option "Fimg2DExa" "false"
Option "DRI2" "true"
Option "DRI2_PAGE_FLIP" "false"
Option "DRI2_WAIT_VSYNC" "true"
# Option "Fimg2DExaSolid" "false"
# Option "Fimg2DExaCopy" "false"
# Option "Fimg2DExaComposite" "false"
Option "SWcursorLCD" "false"
EndSection
Section "Screen"
Identifier "DefaultScreen"
Device "Mali FBDEV"
DefaultDepth 24
EndSection
EOZ
cat > $target_mnt/usr/share/X11/xorg.conf.d/touchpad.conf <<EOZ
Section "InputClass"
Identifier "touchpad"
MatchIsTouchpad "on"
Option "FingerHigh" "5"
Option "FingerLow" "5"
EndSection
EOZ
echo "aptitude -y --without-recommends install linux-image-chromebook xserver-xorg-video-armsoc" >> $target_mnt/install-ubuntu.sh
# Valid for raring, so far also for saucy but will change
kernel=$target_mnt/boot/vmlinuz-3.4.0-5-chromebook
fi
echo "
service stop rsyslog || echo .
service stop cron || echo .
" >> $target_mnt/install-ubuntu.sh
chmod a+x $target_mnt/install-ubuntu.sh
chroot $target_mnt /bin/bash -c /install-ubuntu.sh
rm $target_mnt/install-ubuntu.sh
fi
# Keep CrOS partitions from showing/mounting in Ubuntu
udev_target=${target_disk:5}
echo "KERNEL==\"$udev_target1\" ENV{UDISKS_IGNORE}=\"1\"
KERNEL==\"$udev_target3\" ENV{UDISKS_IGNORE}=\"1\"
KERNEL==\"$udev_target5\" ENV{UDISKS_IGNORE}=\"1\"
KERNEL==\"$udev_target8\" ENV{UDISKS_IGNORE}=\"1\"
" > $target_mnt/etc/udev/rules.d/99-hide-disks.rules
# Treat user creation on live system due to missing ecryptfs support in ChromeOS kernel
sed -i 's/root:x:/root::/' $target_mnt/etc/passwd
echo "
echo \"Please enter details of normal user\"
read -p \"username: \" user_name
deluser --remove-home \$user_name
adduser \$user_name $encrypt_home
adduser \$user_name adm
adduser \$user_name sudo
$auto_login
sed -i 's/root::/root:x:/' /etc/passwd
mv /mkuser.sh /tmp/
" > $target_mnt/mkuser.sh
chmod +x $target_mnt/mkuser.sh
# Fix bug causing high CPU usage after closing LID
# Note: as side effect LID will stop working!
sed -i 's/^$/\necho\ disable\ >\ \/sys\/firmware\/acpi\/interrupts\/gpe1F\n/' $target_mnt/etc/rc.local
# We do not have kernel for x86 chromebooks in archive at all
# and ARM one only in 13.04 and later
if [ $ubuntu_arch != "armhf" -o $ubuntu_version -lt 1304 ]; then
if [ "$hwid" = "cross" ]; then
tar -C $target_mnt -xvf vmlinuz.tar
kernel=vmlinuz
else
KERN_VER=`uname -r`
mkdir -p $target_mnt/lib/modules/$KERN_VER/
cp -ar /lib/modules/$KERN_VER/* $target_mnt/lib/modules/$KERN_VER/
[ ! -d $target_mnt/lib/firmware/ ] && mkdir $target_mnt/lib/firmware/
cp -ar /lib/firmware/* $target_mnt/lib/firmware/
kernel=/boot/vmlinuz-`uname -r`
fi
config=vmlinuz.cfg
fi
# We force rootfs to be first hdd in cross mode
[ "$hwid" = "cross" ] && target_rootfs=/dev/sda
echo "console=tty1 debug verbose root=${target_rootfs} rootwait rw lsm.module_locking=0" > $config
if [ $ubuntu_arch = "armhf" ]; then
vbutil_arch="arm"
else
vbutil_arch="x86"
fi
vbutil_kernel --pack newkern \
--keyblock /usr/share/vboot/devkeys/kernel.keyblock \
--version 1 \
--signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
--config $config \
--vmlinuz $kernel \
--arch $vbutil_arch
dd if=newkern of=${target_kern} bs=4M
umount ${target_mnt}/{dev/pts,dev,sys,proc,}
echo -e "Installation seems to be complete.\n"
echo -e "The ChrUbuntu login is:"
echo -e "\tUsername: root"
echo -e "\tPassword: (no password)\n"
echo -e "Note:\t After reboot you should login as root and invoke /mkuser.sh."
echo -e "\tAbove script will create new user, remove root password and self destroy."
if [ "$always" = "yes" ]; then
echo "Setting Ubuntu kernel partition as top priority for all following boots."
cgpt add -i 6 -P 5 -S 1 ${target_disk}
echo -e "If ChrUbuntu fails when you reboot, you will have to perform full ChromeOS recovery "
echo -e "After thay you may retry ChrUbuntu install."
echo -e "If you're unhappy with ChrUbuntu when you reboot be sure to run:"
echo -e "\tsudo cgpt add -i 2 -P 5 -S 1 ${target_disk}\n"
echo -e "To make ChromeOS the default boot option.\n"
else
echo "Setting Ubuntu kernel partition as top priority for next boot only."
cgpt add -i 6 -P 5 -T 1 ${target_disk}
echo -e "If ChrUbuntu fails when you reboot, power off your Chrome OS device."
echo -e "When turned on, you'll be back in Chrome OS."
echo -e "If you're happy with ChrUbuntu when you reboot be sure to run:"
echo -e "\tsudo cgpt add -i 6 -P 5 -S 1 ${target_disk}\n"
echo -e "To make ChruBuntu the default boot option.\n"
fi
read -p "We're now ready to start ChrUbuntu, Press [Enter] to reboot..."
reboot