Mercurial > hg > aboriginal
annotate sources/root-filesystem/sbin/init.sh @ 1728:b89324905ca2 draft
Giant redo to put simple-root-filesystem in initmpfs.
NO_NATIVE_COMPILER and NO_ROOTDIRS went away, kernel built moved back into
system-image.sh, old root-filesystem.sh and root-image.sh are no longer used,
I need to fix up several things (chroot-splice.sh, the lfs-bootstrap build
is breaking in mpfr, haven't tested this on all targets yet... but the basics
are in.
author | Rob Landley <rob@landley.net> |
---|---|
date | Fri, 06 Feb 2015 01:51:54 -0600 |
parents | 7083fb6ef82c |
children | 34f7ca02767c |
rev | line source |
---|---|
1577
7083fb6ef82c
Bash is causing a (harmless but annoying) segfault on arm for some reason, so use ash to run init script.
Rob Landley <rob@landley.net>
parents:
1483
diff
changeset
|
1 #!/bin/ash |
190
12b7ecb79ad0
A little init script for mini-native.sh that gets it read to build stuff.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 |
570
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
3 export HOME=/home |
1728
b89324905ca2
Giant redo to put simple-root-filesystem in initmpfs.
Rob Landley <rob@landley.net>
parents:
1577
diff
changeset
|
4 export PATH=/bin:/sbin |
415
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
5 |
190
12b7ecb79ad0
A little init script for mini-native.sh that gets it read to build stuff.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 # Populate /dev |
1440 | 7 mountpoint -q proc || mount -t proc proc proc |
415
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
8 mountpoint -q sys || mount -t sysfs sys sys |
1474
d97db0ec50fe
If host kernel hasn't got devtmpfs, call mdev -s. (Mostly for chroot-setup.sh.)
Rob Landley <rob@landley.net>
parents:
1440
diff
changeset
|
9 mountpoint -q dev || mount -t devtmpfs dev dev || mdev -s |
1279
8c0b1c9b6525
Mounting a tmpfs on /dev means /dev/pts isn't there, so mkdir it.
Rob Landley <rob@landley.net>
parents:
1247
diff
changeset
|
10 mkdir -p dev/pts |
1247
84ea1b53b73c
Mounting /dev/pts is useful.
Rob Landley <rob@landley.net>
parents:
1217
diff
changeset
|
11 mountpoint -q dev/pts || mount -t devpts dev/pts dev/pts |
190
12b7ecb79ad0
A little init script for mini-native.sh that gets it read to build stuff.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 |
1483
54db423b7fef
If CPUS isn't set, calculate it. KVM or chroot can have >1.
Rob Landley <rob@landley.net>
parents:
1474
diff
changeset
|
13 # If nobody said how many CPUS to use in builds, try to figure it out. |
54db423b7fef
If CPUS isn't set, calculate it. KVM or chroot can have >1.
Rob Landley <rob@landley.net>
parents:
1474
diff
changeset
|
14 if [ -z "$CPUS" ] |
54db423b7fef
If CPUS isn't set, calculate it. KVM or chroot can have >1.
Rob Landley <rob@landley.net>
parents:
1474
diff
changeset
|
15 then |
54db423b7fef
If CPUS isn't set, calculate it. KVM or chroot can have >1.
Rob Landley <rob@landley.net>
parents:
1474
diff
changeset
|
16 export CPUS=$(echo /sys/devices/system/cpu/cpu[0-9]* | wc -w) |
54db423b7fef
If CPUS isn't set, calculate it. KVM or chroot can have >1.
Rob Landley <rob@landley.net>
parents:
1474
diff
changeset
|
17 [ "$CPUS" -lt 1 ] && CPUS=1 |
54db423b7fef
If CPUS isn't set, calculate it. KVM or chroot can have >1.
Rob Landley <rob@landley.net>
parents:
1474
diff
changeset
|
18 fi |
1038
2957c1dd95cb
Update native prompt to show amount of parallelism a build can get (indicating whether distcc is enabled).
Rob Landley <rob@landley.net>
parents:
1008
diff
changeset
|
19 export PS1='($HOST:$CPUS) \w \$ ' |
895
c1ab614da7b9
Change shell prompt in system image to start with ($HOST)
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
20 |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
21 # If we're running under qemu, do some more setup |
570
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
22 if [ $$ -eq 1 ] |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
23 then |
302
eb2aa88277e2
If a second block device exists, mount it on /home.
Rob Landley <rob@landley.net>
parents:
286
diff
changeset
|
24 |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
25 # Note that 10.0.2.2 forwards to 127.0.0.1 on the host. |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
26 |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
27 # Setup networking for QEMU (needs /proc) |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
28 ifconfig eth0 10.0.2.15 |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
29 route add default gw 10.0.2.2 |
190
12b7ecb79ad0
A little init script for mini-native.sh that gets it read to build stuff.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
31 # If we have no RTC, try rdate instead: |
880
b0aeb3446aa5
Some packages build differently as root than as a normal user, so add a "guest" account giving a non-root user option. Tweak mdev so it's vaguely useful. (Thanks to Vladimir Dronnikov for the idea.)
Rob Landley <rob@landley.net>
parents:
863
diff
changeset
|
32 [ "$(date +%s)" -lt 1000 ] && rdate 10.0.2.2 # or time-b.nist.gov |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
33 |
863
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
34 mount -t tmpfs /tmp /tmp |
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
35 |
1728
b89324905ca2
Giant redo to put simple-root-filesystem in initmpfs.
Rob Landley <rob@landley.net>
parents:
1577
diff
changeset
|
36 if [ -b /dev/[hsv]da ] |
b89324905ca2
Giant redo to put simple-root-filesystem in initmpfs.
Rob Landley <rob@landley.net>
parents:
1577
diff
changeset
|
37 then |
b89324905ca2
Giant redo to put simple-root-filesystem in initmpfs.
Rob Landley <rob@landley.net>
parents:
1577
diff
changeset
|
38 mkdir -p /usr/hda |
b89324905ca2
Giant redo to put simple-root-filesystem in initmpfs.
Rob Landley <rob@landley.net>
parents:
1577
diff
changeset
|
39 mount /dev/[hsv]da /usr/hda |
b89324905ca2
Giant redo to put simple-root-filesystem in initmpfs.
Rob Landley <rob@landley.net>
parents:
1577
diff
changeset
|
40 cp -rs /usr/hda/. / |
b89324905ca2
Giant redo to put simple-root-filesystem in initmpfs.
Rob Landley <rob@landley.net>
parents:
1577
diff
changeset
|
41 fi |
b89324905ca2
Giant redo to put simple-root-filesystem in initmpfs.
Rob Landley <rob@landley.net>
parents:
1577
diff
changeset
|
42 |
1440 | 43 # If there's a /dev/hdb or /dev/sdb, mount it on home, else tmpfs |
302
eb2aa88277e2
If a second block device exists, mount it on /home.
Rob Landley <rob@landley.net>
parents:
286
diff
changeset
|
44 |
1440 | 45 [ -b /dev/[hsv]db ] && HOMEDEV=/dev/[hsv]db |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
46 if [ ! -z "$HOMEDEV" ] |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
47 then |
688
78cbd428d60e
Feed noatime flag to init.sh mounts.
Rob Landley <rob@landley.net>
parents:
673
diff
changeset
|
48 mount -o noatime $HOMEDEV /home |
863
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
49 else |
1054
37c7bd84c777
Updates to init.sh: only mount tmpfs on /home if / isn't writeable, and use /proc/cmdline instead of grepping dmesg to get console info.
Rob Landley <rob@landley.net>
parents:
1038
diff
changeset
|
50 # Only mount a tmpfs if / isn't writeable. |
37c7bd84c777
Updates to init.sh: only mount tmpfs on /home if / isn't writeable, and use /proc/cmdline instead of grepping dmesg to get console info.
Rob Landley <rob@landley.net>
parents:
1038
diff
changeset
|
51 touch /.temp 2>/dev/null |
37c7bd84c777
Updates to init.sh: only mount tmpfs on /home if / isn't writeable, and use /proc/cmdline instead of grepping dmesg to get console info.
Rob Landley <rob@landley.net>
parents:
1038
diff
changeset
|
52 [ $? -ne 0 ] && mount -t tmpfs /home /home || rm /.temp |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
53 fi |
863
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
54 cd /home |
570
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
55 |
1440 | 56 # If there's a /dev/hdc mount it on /mnt |
57 | |
58 [ -b /dev/[hsv]dc ] && MNTDEV=/dev/[hsv]dc | |
59 [ ! -z "$MNTDEV" ] && mount -o ro $MNTDEV /mnt | |
833
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
60 |
1217
1a24dc2bb3cb
Make sure PATH and CONSOLE are properly exported even when kernel command line doesn't provide the right data.
Rob Landley <rob@landley.net>
parents:
1215
diff
changeset
|
61 [ -z "$CONSOLE" ] && |
1a24dc2bb3cb
Make sure PATH and CONSOLE are properly exported even when kernel command line doesn't provide the right data.
Rob Landley <rob@landley.net>
parents:
1215
diff
changeset
|
62 CONSOLE="$(sed -n 's@.* console=\(/dev/\)*\([^ ]*\).*@\2@p' /proc/cmdline)" |
1a24dc2bb3cb
Make sure PATH and CONSOLE are properly exported even when kernel command line doesn't provide the right data.
Rob Landley <rob@landley.net>
parents:
1215
diff
changeset
|
63 [ -z "$CONSOLE" ] && CONSOLE=console |
833
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
64 |
863
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
65 if [ -z "$DISTCC_HOSTS" ] |
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
66 then |
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
67 echo "Not using distcc." |
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
68 else |
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
69 echo "Distcc acceleration enabled." |
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
70 fi |
570
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
71 echo Type exit when done. |
833
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
72 |
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
73 HANDOFF=/bin/ash |
980
d424fd68f991
Idea from Johnicholas Hines: add a three second "read" before running hdc's init so the user can press a key to get a command shell instead.
Rob Landley <rob@landley.net>
parents:
895
diff
changeset
|
74 if [ -e /mnt/init ] |
d424fd68f991
Idea from Johnicholas Hines: add a three second "read" before running hdc's init so the user can press a key to get a command shell instead.
Rob Landley <rob@landley.net>
parents:
895
diff
changeset
|
75 then |
d424fd68f991
Idea from Johnicholas Hines: add a three second "read" before running hdc's init so the user can press a key to get a command shell instead.
Rob Landley <rob@landley.net>
parents:
895
diff
changeset
|
76 X=xx |
d424fd68f991
Idea from Johnicholas Hines: add a three second "read" before running hdc's init so the user can press a key to get a command shell instead.
Rob Landley <rob@landley.net>
parents:
895
diff
changeset
|
77 echo "Press any key for command line..." |
d424fd68f991
Idea from Johnicholas Hines: add a three second "read" before running hdc's init so the user can press a key to get a command shell instead.
Rob Landley <rob@landley.net>
parents:
895
diff
changeset
|
78 read -t 3 -n 1 X |
d424fd68f991
Idea from Johnicholas Hines: add a three second "read" before running hdc's init so the user can press a key to get a command shell instead.
Rob Landley <rob@landley.net>
parents:
895
diff
changeset
|
79 if [ "$X" == xx ] |
d424fd68f991
Idea from Johnicholas Hines: add a three second "read" before running hdc's init so the user can press a key to get a command shell instead.
Rob Landley <rob@landley.net>
parents:
895
diff
changeset
|
80 then |
983 | 81 echo "Running automated build." |
980
d424fd68f991
Idea from Johnicholas Hines: add a three second "read" before running hdc's init so the user can press a key to get a command shell instead.
Rob Landley <rob@landley.net>
parents:
895
diff
changeset
|
82 HANDOFF=/mnt/init |
d424fd68f991
Idea from Johnicholas Hines: add a three second "read" before running hdc's init so the user can press a key to get a command shell instead.
Rob Landley <rob@landley.net>
parents:
895
diff
changeset
|
83 fi |
d424fd68f991
Idea from Johnicholas Hines: add a three second "read" before running hdc's init so the user can press a key to get a command shell instead.
Rob Landley <rob@landley.net>
parents:
895
diff
changeset
|
84 fi |
1133
1ad777637d2d
Migrate oneit out of toybox into sources/toys as a standalone program, and fix it so pid 1 has / as its working directory so we can umount /home if necessary.
Rob Landley <rob@landley.net>
parents:
1117
diff
changeset
|
85 exec /sbin/oneit -c /dev/"$CONSOLE" "$HANDOFF" |
570
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
86 |
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
87 # If we're not PID 1, it's probably a chroot. |
425
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
88 else |
883
c48fc63b7df7
Fix a [ -z $test ] that produced multiple words for the $test part, but didn't have "$test" in quotes. I'm not sure how that ever worked.
Rob Landley <rob@landley.net>
parents:
880
diff
changeset
|
89 [ ! -z "$(grep "default for QEMU" /etc/resolv.conf)" ] && |
1117
725e41d66379
Use Google's nameserver, use ntpd to set time for chroot (if necessary), don't umount home if we didn't mount it.
Rob Landley <rob@landley.net>
parents:
1054
diff
changeset
|
90 echo "nameserver 8.8.8.8" > /etc/resolv.conf |
725e41d66379
Use Google's nameserver, use ntpd to set time for chroot (if necessary), don't umount home if we didn't mount it.
Rob Landley <rob@landley.net>
parents:
1054
diff
changeset
|
91 |
725e41d66379
Use Google's nameserver, use ntpd to set time for chroot (if necessary), don't umount home if we didn't mount it.
Rob Landley <rob@landley.net>
parents:
1054
diff
changeset
|
92 # If we have no RTC, try using ntp to set the clock |
725e41d66379
Use Google's nameserver, use ntpd to set time for chroot (if necessary), don't umount home if we didn't mount it.
Rob Landley <rob@landley.net>
parents:
1054
diff
changeset
|
93 [ "$(date +%s)" -lt 10000000 ] && ntpd -nq -p north-america.pool.ntp.org |
302
eb2aa88277e2
If a second block device exists, mount it on /home.
Rob Landley <rob@landley.net>
parents:
286
diff
changeset
|
94 |
570
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
95 # Switch to a shell with command history. |
372
37c8a6c9a493
Teach qemu-setup.sh to use oneit so ctrl-c works under the emulator. Also
Rob Landley <rob@landley.net>
parents:
369
diff
changeset
|
96 |
570
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
97 echo Type exit when done. |
790
188a182b1a7f
Remove some leftover /tools residue.
Rob Landley <rob@landley.net>
parents:
783
diff
changeset
|
98 /bin/ash |
425
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
99 cd / |
1247
84ea1b53b73c
Mounting /dev/pts is useful.
Rob Landley <rob@landley.net>
parents:
1217
diff
changeset
|
100 umount ./dev/pts |
425
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
101 umount ./dev |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
102 umount ./sys |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
103 umount ./proc |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
104 sync |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
105 fi |