Subversion Repositories livecd

Rev

Rev 1 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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