Subversion Repositories livecd

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 beyerle@PS 1
#!/bin/ash
2
#
3
# Original version from http://www.linux-live.org/
4
#
5
# modified by Urs Beyerle, PSI
6
# - to allow LiveCD mounted over NFS
7
# - add support for LiveCD on SATA devices
8
 
9
export PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin
10
. liblinuxlive
11
 
12
 
13
echolog "mounting /proc and /sys filesystems"
14
mount -t proc proc /proc
15
mount -t sysfs sysfs /sys
16
 
17
# setup DEBUGCMD variable. If debug boot option is present, call debug()
18
# function several times during script's execution
19
if [ "`cmdline_parameter debug`" ]; then DEBUGCMD="debug"; else DEBUGCMD=""; fi
20
 
21
$DEBUGCMD
22
 
23
# I have to set these variables very carefully
24
UNION=/union
25
MEMORY=/memory
26
#MOUNTDIR=mnt
27
MOUNTDIR=livecd
28
CHANGES=$MEMORY/changes
29
COPY2RAM=$MEMORY/copy2ram
30
IMAGES=$MEMORY/images
31
INITRAMDISK=$MOUNTDIR/live
32
 
33
# set NFSROOT if nfsroot= in boot parameter 
34
NFSROOT="`cmdline_value nfsroot`"
35
 
36
# we need cdrom support, isofs support, unionfs support, etc
37
modprobe_essential_modules
38
setup_dma
39
 
40
$DEBUGCMD
41
 
42
# load network modules, if NFSROOT is set
43
echolog "check for nfsroot"
44
if [ "$NFSROOT" != "" ]; then
45
   echolog "nfsroot: $NFSROOT"
46
   # mii maybe need by NIC
47
   echolog "load module mii"
48
   modprobe_module mii
49
 
50
   # detecting network card
51
   PCITABLE=/bin/pcitable
52
   NICS=`lspci -n | awk '/Class 0200/ {print $4}' | tr ':' ' ' \
53
   | while read x y ; do grep "0x$x.*0x$y" $PCITABLE \
54
   | awk '$3 !~ /"unknown"/ {print $3}' | tr -d '"' ; done`
55
   echolog "Found network card(s): $NICS"
56
 
57
   if [ -n "$NICS" ]; then
58
       echo $NICS | while read nic ; do
59
	   echo "Loading module $nic"
60
	   modprobe_module $nic
61
       done
62
   else
63
       echo "ERROR: No network card detected!"
64
       echo "Type in your network card driver (e.g. tg3, e1000). "
65
       echo "Or ask your system administrator for help."
66
       echo -n "Network card driver: "
67
       read nic
68
       echo "Loading module $nic"
69
       modprobe_module $nic
70
   fi
71
fi
72
 
73
$DEBUGCMD
74
 
75
# get DHCP lease
76
if [ "$NFSROOT" != "" ]; then
77
    # create /dev/urandom (needed by udhcpc)
78
    mknod /dev/urandom c 1 9
79
    echolog "Try to get DHCP lease on eth0"
80
    udhcpc --now --quit --interface=eth0 --script=/bin/udhcpc.script
81
    if [ $? -ne 0 ]; then
82
	echo "ERROR: couldn't get DHCP lease, trying again"
83
	udhcpc --now --quit --interface=eth0 --script=/bin/udhcpc.script
84
	if [ $? -ne 0 ]; then
85
	    echo "ERROR: couldn't get DHCP lease, trying eth1"
86
	    udhcpc --now --quit --interface=eth1 --script=/bin/udhcpc.script
87
	    if [ $? -ne 0 ]; then
88
		echo "ERROR: couldn't get DHCP lease, trying again eth1"
89
		udhcpc --now --quit --interface=eth1 --script=/bin/udhcpc.script
90
		if [ $? -ne 0 ]; then
91
		    echo "ERROR: can't get DHCP lease on eth0 and eth1"
92
		fi
93
	    fi
94
	fi
95
    fi
96
fi
97
 
98
$DEBUGCMD
99
 
100
# we need nfs modules loaded, if NFSROOT is set
101
if [ "$NFSROOT" != "" ]; then
102
    modprobe_nfs_modules
103
fi
104
 
105
$DEBUGCMD
106
 
107
# $UNION will be used as a root directory, livecd modules will be added soon.
108
echolog "setup union on $UNION"
109
mkdir -p $UNION
110
mkdir -p $MEMORY
111
 
112
CHANGESDEV="`cmdline_value changes`"
113
if [ "$CHANGESDEV" != "" ]; then
114
   echo "mounting $CHANGESDEV to $MEMORY"
115
   mount_device $CHANGESDEV $MEMORY
116
else false; fi
117
 
118
# mount tmpfs only in the case when changes= boot parameter was empty
119
# or we were not able to mount the storage device
120
if [ $? -ne 0 ]; then mount -t tmpfs -o "size=80%" tmpfs $MEMORY; fi
121
 
122
mkdir -p $CHANGES
123
mkdir -p $COPY2RAM
124
mkdir -p $IMAGES
125
mount -t unionfs -o dirs=$CHANGES=rw unionfs $UNION
126
if [ $? -ne 0 ]; then fatal "can't setup union in /union directory"; fi
127
 
128
$DEBUGCMD
129
 
130
# try to find livecd data directory. If not found, try modprobing
131
# USB and SATA kernel modules and repeat the find procedure again
132
echolog "looking for data modules"
133
DATA="`find_live_data_dir $MOUNTDIR`";
134
# if [ "$DATA" = "" ]; then modprobe_usb_modules; DATA="`find_live_data_dir $MOUNTDIR`"; fi
135
if [ "$DATA" = "" ]; then modprobe_usb_sata_modules; DATA="`find_live_data_dir $MOUNTDIR`"; fi
136
if [ "$DATA" = "" ]; then fatal "Data for LiveCD not found. Are you using SCSI?"; fi
137
echolog "LiveCD found in: $DATA"
138
 
139
$DEBUGCMD
140
 
141
# If toram or copy2ram boot parameter is present, copy all .mo modules to RAM.
142
# (skip modules from /optional/ which are not listed in load= boot option)
143
# Finaly modify DATA variable so it will point to correct directory
144
if [ "`cmdline_parameter toram`" != "" -o "`cmdline_parameter copy2ram`" != "" ]; then
145
   echolog "copying modules to RAM, this may take some time"
146
   copy_to_ram $DATA $COPY2RAM
147
   cd_autoeject 1
148
   umount $DATA 2>/dev/null
149
   if [ $? -ne 0 ]; then umount `dirname $DATA` 2>/dev/null; fi
150
   DATA=$COPY2RAM
151
   cd_autoeject 0
152
fi
153
 
154
mkdir -p $UNION/boot
155
mount -o bind $DATA $UNION/boot
156
 
157
$DEBUGCMD
158
 
159
# DATA contains path to the base directory of all .mo images which need
160
# to be mounted and inserted into live filesystem. Do it now.
161
echolog "inserting all modules and creating live filesystem"
162
union_insert_modules $UNION $DATA $IMAGES
163
 
164
$DEBUGCMD
165
 
166
echo "copying rootchanges"
167
copy_rootchanges $DATA $UNION
168
 
169
$DEBUGCMD
170
 
171
echo "creating /etc/fstab"
172
activate_fstab $UNION
173
 
174
# More likely these directories aren't there.
175
# Even if they are, this won't hurt.
176
mkdir -p $UNION/proc
177
mkdir -p $UNION/sys
178
mkdir -p $UNION/tmp
179
mkdir -p $UNION/dev
180
 
181
$DEBUGCMD
182
 
183
# Union contains all the files and directories unioned from all modules.
184
# Change root directory to it, and move initrd's root to /livecd/live/initramdisk
185
# Finaly execute /sbin/init to start the distribution.
186
echolog "changing root directory..."
187
cd $UNION
188
mkdir -p $INITRAMDISK
189
 
190
umount /sys # we won't need it anymore
191
if [ ! -e $UNION/dev/console ]; then mknod $UNION/dev/console c 5 1; fi
192
 
193
if [ -x $UNION/usr/sbin/chroot ];
194
  then CHROOT=/usr/sbin/chroot
195
  else CHROOT=/usr/bin/chroot
196
fi
197
 
198
echolog "End of linux live scripts"
199
 
200
# pure magic ;-)
201
cat $UNION/bin/true >/dev/null
202
 
203
$DEBUGCMD
204
 
205
pivot_root . $INITRAMDISK
206
exec $CHROOT . sbin/init <dev/console >dev/console 2>&1; fi
207
 
208
header "ERROR!"
209
echolog "You are not supposed to be here, something went wrong!"
210
echolog "Even Ctrl+Alt+Del won't help you in kernel panic."
211