blob: 85617f04be4aef65ddd5148693d4d6c630a8304d (
plain) (
blame)
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
|
#!/bin/bash
# This is the first working nvidia extractor.
BASEDIR=/root/temp/
TMSCRIPTS=/root/tm-scripts/
MODULE_DIR="$TMSCRIPTS/remote/modules/kernel/"
KERNELSRCDIR="$MODULE_DIR/ksrc"
ROOTLOWERDIR="/"
ROOTUPPERDIR="$BASEDIR/rootupper"
ROOTBINDDIR="$BASEDIR/rootbind"
ROOTMOUNTDIR="$BASEDIR/rootmount"
BINDMOUNTS="/dev /proc /run /sys"
NVIDIA="$BASEDIR/NVIDIA-Linux-x86_64-331.38.run"
NVIDIAEXTRACTDIR="$ROOTMOUNTDIR/NVIDIA"
NVEXTRACTDIR="/NVIDIA" # this one relative to chroot"
STARTDM="false"
# This is just an experiment to look whether the annoying message "could not insert kernel module"
# by the nvidia installer when compiling on a computer lacking a nvidia gpu card could be killed.
# It does not work, as the nvidia-installer uses a self-brewed module loader.
dump_modprobe () {
[ -d "$ROOTMOUNTDIR/sbin" ] || mkdir "$ROOTMOUNTDIR/sbin"
for FILE in insmod modprobe; do
cat>"$ROOTMOUNTDIR/sbin/$FILE"<<-EOF
#/bin/sh
exit 0
EOF
chmod +x "$ROOTMOUNTDIR/sbin/$FILE"
done
}
stop_display_managers () {
for DM in kdm gdm lightdm; do
ps a|grep -v grep|grep "$DM"
ERR=$?
if [ "$ERR" -eq 0 ]; then
/etc/init.d/"$DM" stop
killall "$DM" # line above leaves a residue sometimes...
STARTDM="$DM"
echo "Stopped $DM."
break
fi
done
}
# Several directories for bind mount and overlay mounts.
make_dirs () {
mkdir "$ROOTUPPERDIR"
mkdir "$ROOTBINDDIR"
mkdir "$ROOTMOUNTDIR"
}
mount_dirs () {
mount -o bind "$ROOTLOWERDIR" "$ROOTBINDDIR"
mount -o remount,ro "$ROOTBINDDIR"
mount -t overlayfs overlayfs -o lowerdir="$ROOTBINDDIR",upperdir="$ROOTUPPERDIR" "$ROOTMOUNTDIR"
for MOUNT in $BINDMOUNTS; do
echo "Erzeuge bind-mount $MOUNT ..."
mount -o bind "$MOUNT" "$ROOTMOUNTDIR/$MOUNT" || echo "Bind mount auf $MOUNT schlug fehl."
done
}
# We inject a bashrc to be executed within the chroot.
gen_bashrc () {
echo "chroot erfolgreich."
COMMON_OPTIONS=' --no-nouveau-check --no-network --no-backup --no-rpms --no-runlevel-check --no-distro-scripts --no-cc-version-check --no-x-check --no-precompiled-interface --silent '
cat >"$ROOTMOUNTDIR/$HOME/.bashrc"<<-EOF
alias ll='ls -alF'
PS1='\[\e[1;33m\]chroot@\h:\w\$ \[\e[1;32m\]'
cd "$NVEXTRACTDIR"
echo "First pass... compiling kernel module."
./nvidia-installer $COMMON_OPTIONS --kernel-source-path /"$KERNELSRCDIR" # compiles .ko, but not always the rest.
echo "Second pass... compiling everything else."
./nvidia-installer $COMMON_OPTIONS --no-kernel-module # compiles the rest - hopefully.
exit
EOF
}
unpack_nvidia () {
[ -d "$NVIDIAEXTRACTDIR" ] && rm -rf "$NVIDIAEXTRACTDIR"
echo "Entpacke $NVIDIA ..."
sh "$NVIDIA" --extract-only --target "$NVIDIAEXTRACTDIR"
}
umount_dirs () {
for MOUNT in $BINDMOUNTS; do
umount "$ROOTMOUNTDIR/$MOUNT"
done
umount "$ROOTMOUNTDIR"
umount "$ROOTBINDDIR"
}
start_display_manager () {
[ "$STARTDM" != "false" ] && echo /etc/init.d/"$DM" start
}
# stop_display_managers
make_dirs
echo "Mounte Verzeichnisse ..."
mount_dirs
echo "Lege .bashrc ab ..."
gen_bashrc
echo "Entpacke NVidia-Installer ..."
unpack_nvidia
echo "Dumpe modprobe / insmod ..."
# dump_modprobe
echo "Fertig für chroot."
chroot "$ROOTMOUNTDIR"
echo "chroot durch."
echo "Unmounte Verzeichnisse."
umount_dirs
# start_display_manager
|