forked from RaumZeit/LinuxOnAcerCB5-311
-
Notifications
You must be signed in to change notification settings - Fork 1
/
archlinux.sh
477 lines (345 loc) · 12 KB
/
archlinux.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
set -e
CWD=`pwd`
MY_REPO_PATH="http://www.tbi.univie.ac.at/~ronny/alarm/"
MY_CHROOT_DIR=/tmp/arfs
PROGRESS_PID=
LOGFILE="${CWD}/archlinux-install.log"
spin='-\|/'
function progress () {
arg=$1
echo -n "$arg "
while true
do
i=$(( (i+1) %4 ))
printf "\r$arg ${spin:$i:1}"
sleep .1
done
}
function start_progress () {
# Start it in the background
progress "$1" &
# Save progress() PID
PROGRESS_PID=$!
disown
}
function end_progress () {
# Kill progress
kill ${PROGRESS_PID} >/dev/null 2>&1
echo -n " ...done."
echo
}
#
# Note, this function removes the script after execution
#
function exec_in_chroot () {
script=$1
if [ -f ${MY_CHROOT_DIR}/${script} ] ; then
chmod a+x ${MY_CHROOT_DIR}/${script}
chroot ${MY_CHROOT_DIR} /bin/bash -c /${script} >> ${LOGFILE} 2>&1
rm ${MY_CHROOT_DIR}/${script}
fi
}
function setup_chroot () {
mount -o bind /proc ${MY_CHROOT_DIR}/proc
mount -o bind /dev ${MY_CHROOT_DIR}/dev
mount -o bind /dev/pts ${MY_CHROOT_DIR}/dev/pts
mount -o bind /sys ${MY_CHROOT_DIR}/sys
}
function unset_chroot () {
if [ "x${PROGRESS_PID}" != "x" ]
then
end_progress
fi
umount ${MY_CHROOT_DIR}/proc
umount ${MY_CHROOT_DIR}/dev
umount ${MY_CHROOT_DIR}/dev/pts
umount ${MY_CHROOT_DIR}/sys
}
trap unset_chroot EXIT
function copy_chros_files () {
start_progress "Copying files from ChromeOS to ArchLinuxARM rootdir"
mkdir -p ${MY_CHROOT_DIR}/run/resolvconf
cp /etc/resolv.conf ${MY_CHROOT_DIR}/run/resolvconf/
ln -s -f /run/resolvconf/resolv.conf ${MY_CHROOT_DIR}/etc/resolv.conf
echo alarm > ${MY_CHROOT_DIR}/etc/hostname
echo -e "\n127.0.1.1\tlocalhost.localdomain\tlocalhost\talarm" >> ${MY_CHROOT_DIR}/etc/hosts
mkdir -p ${MY_CHROOT_DIR}/lib/firmware/
cp -ar /lib/firmware/* ${MY_CHROOT_DIR}/lib/firmware/
end_progress
}
function install_dev_tools () {
start_progress "Installing development base packages"
#
# Add some development tools and put the alarm user into the
# wheel group. Furthermore, grant ALL privileges via sudo to users
# that belong to the wheel group
#
cat > ${MY_CHROOT_DIR}/install-develbase.sh << EOF
pacman-key --init
pacman-key --populate archlinuxarm
pacman -Syyu --needed --noconfirm sudo wget dialog base-devel devtools vim rsync git vboot-utils
usermod -aG wheel alarm
sed -i 's/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/' /etc/sudoers
EOF
exec_in_chroot install-develbase.sh
end_progress
}
function install_xbase () {
start_progress "Installing X-server basics"
cat > ${MY_CHROOT_DIR}/install-xbase.sh <<EOF
pacman -Syy --needed --noconfirm \
iw networkmanager network-manager-applet \
lightdm lightdm-gtk-greeter \
chromium \
xorg-server xorg-apps xf86-input-synaptics \
xorg-twm xorg-xclock xterm xorg-xinit \
xorg-server-common xorg-server-xvfb \
xf86-input-mouse xf86-input-keyboard \
xf86-input-evdev xf86-input-synaptics xf86-video-fbdev
systemctl enable NetworkManager
systemctl enable lightdm
EOF
exec_in_chroot install-xbase.sh
end_progress
}
function install_xfce4 () {
start_progress "Installing XFCE4"
# add .xinitrc to /etc/skel that defaults to xfce4 session
cat > ${MY_CHROOT_DIR}/etc/skel/.xinitrc << EOF
#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)
if [ -d /etc/X11/xinit/xinitrc.d ]; then
for f in /etc/X11/xinit/xinitrc.d/*; do
[ -x \"\$f\" ] && . \"\$f\"
done
unset f
fi
# exec gnome-session
# exec startkde
exec startxfce4
# ...or the Window Manager of your choice
EOF
cat > ${MY_CHROOT_DIR}/install-xfce4.sh << EOF
pacman -Syy --needed --noconfirm xfce4 xfce4-goodies
# copy .xinitrc to already existing home of user 'alarm'
cp /etc/skel/.xinitrc /home/alarm/.xinitrc
cp /etc/skel/.xinitrc /home/alarm/.xprofile
sed -i 's/exec startxfce4/# exec startxfce4/' /home/alarm/.xprofile
chown alarm:users /home/alarm/.xinitrc
chown alarm:users /home/alarm/.xprofile
EOF
exec_in_chroot install-xfce4.sh
end_progress
}
function install_kernel () {
start_progress "Installing kernel"
cat > ${MY_CHROOT_DIR}/install-kernel.sh << EOF
wget https://github.com/reey/PKGBUILDs/releases/download/v4.19.10/linux-nyan-4.19.10-1-armv7h.pkg.tar.xz
wget https://github.com/reey/PKGBUILDs/releases/download/v4.19.10/linux-nyan-chromebook-4.19.10-1-armv7h.pkg.tar.xz
wget https://github.com/reey/PKGBUILDs/releases/download/v4.19.10/linux-nyan-headers-4.19.10-1-armv7h.pkg.tar.xz
pacman -R --noconfirm linux-armv7
yes n | pacman -U --noconfirm linux-nyan-*
#pacman -Syy --needed --noconfirm linux-armv7-rc linux-armv7-rc-chromebook
#pacman -Syy --needed --noconfirm linux-armv7 linux-armv7-chromebook
dd if=/boot/vmlinux.kpart of=${target_kern}
echo elan_i2c > /etc/modules-load.d/elan_touchpad.conf
echo bq24735_charger > /etc/modules-load.d/bq2473_charger.conf
EOF
exec_in_chroot install-kernel.sh
end_progress
}
function tweak_misc_stuff () {
# hack for removing uap0 device on startup (avoid freeze)
echo 'install mwifiex_sdio /sbin/modprobe --ignore-install mwifiex_sdio && sleep 1 && iw dev uap0 del' > ${MY_CHROOT_DIR}/etc/modprobe.d/mwifiex.conf
cat > ${MY_CHROOT_DIR}/etc/udev/rules.d/99-tegra-lid-switch.rules <<EOF
ACTION=="remove", GOTO="tegra_lid_switch_end"
SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="platform", KERNELS=="gpio-keys.4", TAG+="power-switch"
LABEL="tegra_lid_switch_end"
EOF
}
function install_misc_utils () {
start_progress "Installing some more utilities"
cat > ${MY_CHROOT_DIR}/install-utils.sh <<EOF
pacman -Syy --needed --noconfirm sshfs screen file-roller
EOF
exec_in_chroot install-utils.sh
end_progress
}
function install_sound () {
start_progress "Installing sound (alsa/pulseaudio)"
cat > ${MY_CHROOT_DIR}/install-sound.sh <<EOF
pacman -Syy --needed --noconfirm \
alsa-lib alsa-utils alsa-tools alsa-oss alsa-firmware alsa-plugins \
pulseaudio pulseaudio-alsa
EOF
exec_in_chroot install-sound.sh
end_progress
}
echo "" > $LOGFILE
# 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
echo ""
echo "WARNING! This script will install binary packages from an unofficial source!"
echo ""
echo "If you don't trust me (Ronny Lorenz a.k.a. RaumZeit) press CTRL+C to quit"
echo "(see https://github.com/RaumZeit/LinuxOnAcerCB5-311 for further details)"
echo ""
read -p "Press [Enter] to proceed installation of ArchLinuxARM"
if [ "$1" != "" ]; then
target_disk=$1
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 ArchLinuxARM on ${target_disk} or CTRL+C to quit"
kern_part=1
root_part=2
ext_size="`blockdev --getsz ${target_disk}`"
aroot_size=$((ext_size - 65600 - 33))
cgpt create ${target_disk}
cgpt add -i ${kern_part} -b 64 -s 32768 -S 1 -P 5 -l KERN-A -t "kernel" ${target_disk}
cgpt add -i ${root_part} -b 65600 -s $aroot_size -l ROOT-A -t "rootfs" ${target_disk}
sync
blockdev --rereadpt ${target_disk}
crossystem dev_boot_usb=1
else
target_disk="`rootdev -d -s`"
kern_part=6
root_part=7
# Do partitioning (if we haven't already)
ckern_size="`cgpt show -i ${kern_part} -n -s -q ${target_disk}`"
croot_size="`cgpt show -i ${root_part} -n -s -q ${target_disk}`"
state_size="`cgpt show -i 1 -n -s -q ${target_disk}`"
max_archlinux_size=$(($state_size/1024/1024/2))
rec_archlinux_size=$(($max_archlinux_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 ArchLinux. Acceptable range is 5 to $max_archlinux_size but $rec_archlinux_size is the recommended maximum: " archlinux_size
if [ ! $archlinux_size -ne 0 2>/dev/null ]
then
echo -e "\n\nNumbers only please...\n\n"
continue
fi
if [ $archlinux_size -lt 5 -o $archlinux_size -gt $max_archlinux_size ]
then
echo -e "\n\nThat number is out of range. Enter a number 5 through $max_archlinux_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=$(($archlinux_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 ArchLinux."
echo -e "Your Chromebook will reboot, wipe your data and then"
echo -e "you should re-run this script..."
umount -l /mnt/stateful_partition
# stateful first
cgpt add -i 1 -b $stateful_start -s $stateful_size -l STATE ${target_disk}
# now kernc
cgpt add -i ${kern_part} -b $kernc_start -s $kernc_size -l KERN-C ${target_disk}
# finally rootc
cgpt add -i ${root_part} -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`"
archlinux_arch="armv7"
archlinux_version="latest"
echo -e "\nChrome device model is: $hwid\n"
echo -e "Installing ArchLinuxARM ${archlinux_version}\n"
echo -e "Kernel Arch is: $chromebook_arch Installing ArchLinuxARM Arch: ${archlinux_arch}\n"
read -p "Press [Enter] to continue..."
if [ ! -d /mnt/stateful_partition/archlinux ]
then
mkdir /mnt/stateful_partition/archlinux
fi
cd /mnt/stateful_partition/archlinux
if [[ "${target_disk}" =~ "mmcblk" ]]
then
target_rootfs="${target_disk}p${root_part}"
target_kern="${target_disk}p${kern_part}"
else
target_rootfs="${target_disk}${root_part}"
target_kern="${target_disk}${kern_part}"
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/arfs ]
then
mkdir /tmp/arfs
fi
mount -t ext4 ${target_rootfs} /tmp/arfs
tar_file="http://archlinuxarm.org/os/ArchLinuxARM-${archlinux_arch}-${archlinux_version}.tar.gz"
start_progress "Downloading and extracting ArchLinuxARM rootfs"
curl -s -L --output - $tar_file | tar xzvvp -C /tmp/arfs/ >> ${LOGFILE} 2>&1
end_progress
setup_chroot
copy_chros_files
install_dev_tools
install_xbase
install_xfce4
install_sound
install_kernel
install_misc_utils
#tweak_misc_stuff
#Set ArchLinuxARM kernel partition as top priority for next boot (and next boot only)
cgpt add -i ${kern_part} -P 5 -T 1 ${target_disk}
echo -e "
Installation seems to be complete. If ArchLinux 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 ArchLinuxARM when you reboot be sure to run:
sudo cgpt add -i ${kern_part} -P 5 -S 1 ${target_disk}
To make it the default boot option. The ArchLinuxARM login is:
Username: alarm
Password: alarm
Root access can either be gained via sudo, or the root user:
Username: root
Password: root
We're now ready to start ArchLinuxARM!
"
read -p "Press [Enter] to reboot..."
reboot