Subversion Repositories livecd

Rev

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

Rev 209 Rev 241
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
5
# modified by Urs Beyerle
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
# - to allow LiveCD mounted over CIFS
8
# - to allow LiveCD mounted over CIFS
9
 
9
 
10
export PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin
10
export PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin
11
. liblinuxlive
11
. liblinuxlive
12
 
12
 
13
 
13
 
14
echolog "mounting /proc and /sys filesystems"
14
echolog "mounting /proc and /sys filesystems"
15
mount -t proc proc /proc
15
mount -t proc proc /proc
16
mount -t sysfs sysfs /sys
16
mount -t sysfs sysfs /sys
17
ln -sf /proc/mounts /etc/mtab # this allows us to use umount -a
17
ln -sf /proc/mounts /etc/mtab # this allows us to use umount -a
18
 
18
 
19
# setup DEBUGCMD variable. If debug boot option is present, call debug()
19
# setup DEBUGCMD variable. If debug boot option is present, call debug()
20
# function several times during script's execution
20
# function several times during script's execution
21
if [ "`cmdline_parameter debug`" ]; then DEBUGCMD="debug"; else DEBUGCMD=""; fi
21
if [ "`cmdline_parameter debug`" ]; then DEBUGCMD="debug"; else DEBUGCMD=""; fi
22
 
22
 
23
$DEBUGCMD
23
$DEBUGCMD
24
 
24
 
25
# amount of RAM to store changes
25
# amount of RAM to store changes
26
RAMSIZE="`cmdline_value ramsize`"
26
RAMSIZE="`cmdline_value ramsize`"
27
if [ "$RAMSIZE" = "" ]; then RAMSIZE="70%"; fi
27
if [ "$RAMSIZE" = "" ]; then RAMSIZE="70%"; fi
28
 
28
 
29
# I have to set these variables very carefully
29
# Set these variables very carefully
30
UNION=/union
30
UNION=/union
31
MEMORY=/memory
31
MEMORY=/memory
32
MOUNTDIR=livecd
32
MOUNTDIR=livecd
33
CHANGES=$MEMORY/SL53changes
33
CHANGES=$MEMORY/SL53changes
34
COPY2RAM=$MEMORY/copy2ram
34
COPY2RAM=$MEMORY/copy2ram
35
IMAGES=$MEMORY/images
35
IMAGES=$MEMORY/images
36
INITRAMDISK=$MOUNTDIR/live
36
INITRAMDISK=$MOUNTDIR/live
37
 
37
 
38
# set NFSROOT and NFSOPTS 
38
# set NFSROOT and NFSOPTS 
39
NFSROOT="`cmdline_value nfsroot`"
39
NFSROOT="`cmdline_value nfsroot`"
40
NFSOPTS="`cmdline_value nfsopts`"
40
NFSOPTS="`cmdline_value nfsopts`"
41
if [ "$NFSOPTS" = "" ]; then
-
 
42
    NFSOPTS=nolock,ro,rsize=8192,wsize=8192,hard,intr
41
if [ "$NFSOPTS" = "" ]; then NFSOPTS="nolock,ro,rsize=8192,wsize=8192,hard,intr"; fi
43
fi
-
 
44
 
42
 
45
# set CIFSROOT and CIFSOPTS
43
# set CIFSROOT and CIFSOPTS
46
CIFSROOT="`cmdline_value cifsroot`"
44
CIFSROOT="`cmdline_value cifsroot`"
47
CIFSOPTS="`cmdline_value cifsopts`"
45
CIFSOPTS="`cmdline_value cifsopts`"
48
 
46
 
-
 
47
# set DHCPDELAY (in seconds)
-
 
48
DHCPDELAY="`cmdline_value dhcpdelay`"
-
 
49
if [ "$DHCPDELAY" = "" ]; then DHCPDELAY=8; fi
-
 
50
 
49
# we need cdrom support, isofs support, unionfs/aufs support, etc
51
# we need cdrom support, isofs support, unionfs/aufs support, etc
50
modprobe_essential_modules
52
modprobe_essential_modules
51
 
53
 
52
# disable DMA if nodma parameter is used
54
# disable DMA if nodma parameter is used
53
setup_dma
55
setup_dma
54
 
56
 
55
$DEBUGCMD
57
$DEBUGCMD
56
 
58
 
57
# if NFSROOT is set:
59
# if NFSROOT is set:
58
echolog "check for nfsroot or cifsroot"
60
echolog "check for nfsroot or cifsroot"
59
if [ "$NFSROOT" != "" ]; then
61
if [ "$NFSROOT" != "" ]; then
60
 
62
 
61
   echolog "nfsroot: $NFSROOT"
63
   echolog "nfsroot: $NFSROOT"
62
   $DEBUGCMD
64
   $DEBUGCMD
63
   load_network_modules
65
   load_network_modules
64
   $DEBUGCMD
66
   $DEBUGCMD
65
   get_dhcp_lease
67
   get_dhcp_lease
66
   $DEBUGCMD
68
   $DEBUGCMD
67
   modprobe_nfs_modules
69
   modprobe_nfs_modules
68
 
70
 
69
# if CIFSROOT is set
71
# if CIFSROOT is set
70
elif [ "$CIFSROOT" != "" ]; then
72
elif [ "$CIFSROOT" != "" ]; then
71
 
73
 
72
   echolog "cifsroot: $CIFSROOT"
74
   echolog "cifsroot: $CIFSROOT"
73
   $DEBUGCMD
75
   $DEBUGCMD
74
   load_network_modules
76
   load_network_modules
75
   $DEBUGCMD
77
   $DEBUGCMD
76
   get_dhcp_lease
78
   get_dhcp_lease
77
   $DEBUGCMD
79
   $DEBUGCMD
78
   modprobe_cifs_modules
80
   modprobe_cifs_modules
79
 
81
 
80
fi
82
fi
81
 
83
 
82
$DEBUGCMD
84
$DEBUGCMD
83
 
85
 
84
# $UNION will be used as a root directory, livecd modules will be added soon.
86
# $UNION will be used as a root directory, livecd modules will be added soon.
85
echolog "setup union on $UNION"
87
echolog "setup union on $UNION"
86
mkdir -p $UNION
88
mkdir -p $UNION
87
mkdir -p $MEMORY
89
mkdir -p $MEMORY
88
 
90
 
89
# looking for changes= parameter
91
# looking for changes= parameter
90
CHANGESVAL="`cmdline_value changes`"
92
CHANGESVAL="`cmdline_value changes`"
91
if [ "$CHANGESVAL" != "" ]; then 
93
if [ "$CHANGESVAL" != "" ]; then 
92
    # disable kernel warnings
94
    # disable kernel warnings
93
    PRINTK=`cat /proc/sys/kernel/printk`
95
    PRINTK=`cat /proc/sys/kernel/printk`
94
    echo "0" >/proc/sys/kernel/printk
96
    echo "0" >/proc/sys/kernel/printk
95
    find_changes
97
    find_changes
96
    # enable kernel warnings
98
    # enable kernel warnings
97
    echo "$PRINTK" >/proc/sys/kernel/printk
99
    echo "$PRINTK" >/proc/sys/kernel/printk
98
fi
100
fi
99
mkdir -p $MEMORY
101
mkdir -p $MEMORY
100
 
102
 
101
$DEBUGCMD
103
$DEBUGCMD
102
 
104
 
103
# mount tmpfs only in the case when changes= boot parameter was empty
105
# mount tmpfs only in the case when changes= boot parameter was empty
104
if [ "$CHANGESVAL" = "" ]; then 
106
if [ "$CHANGESVAL" = "" ]; then 
105
    echolog "mount tmpfs"
107
    echolog "mount tmpfs"
106
    mount -t tmpfs -o "size=$RAMSIZE" tmpfs $MEMORY
108
    mount -t tmpfs -o "size=$RAMSIZE" tmpfs $MEMORY
107
    $DEBUGCMD
109
    $DEBUGCMD
108
fi
110
fi
109
 
111
 
110
mkdir -p $CHANGES
112
mkdir -p $CHANGES
111
mkdir -p $COPY2RAM
113
mkdir -p $COPY2RAM
112
rm -rf $IMAGES
114
rm -rf $IMAGES
113
mkdir -p $IMAGES
115
mkdir -p $IMAGES
114
 
116
 
115
# mount unionfs or aufs
117
# mount unionfs or aufs
116
lsmod | grep -q ^unionfs
118
lsmod | grep -q ^unionfs
117
if [ $? -eq 0 ]; then  
119
if [ $? -eq 0 ]; then  
118
    mount -t unionfs -o dirs=$CHANGES=rw unionfs $UNION
120
    mount -t unionfs -o dirs=$CHANGES=rw unionfs $UNION
119
    if [ $? -ne 0 ]; then fatal "can't setup union in $UNION directory"; fi
121
    if [ $? -ne 0 ]; then fatal "can't setup union in $UNION directory"; fi
120
    echolog "unionfs mounted"
122
    echolog "unionfs mounted"
121
else
123
else
122
    mount -t aufs -o br:$CHANGES=rw aufs $UNION
124
    mount -t aufs -o br:$CHANGES=rw aufs $UNION
123
    if [ $? -ne 0 ]; then fatal "can't setup union (aufs) in $UNION directory"; fi
125
    if [ $? -ne 0 ]; then fatal "can't setup union (aufs) in $UNION directory"; fi
124
    echolog "aufs mounted"
126
    echolog "aufs mounted"
125
fi
127
fi
126
 
128
 
127
$DEBUGCMD
129
$DEBUGCMD
128
 
130
 
129
# try to find livecd data directory. If not found, try modprobing
131
# try to find livecd data directory. If not found, try modprobing
130
# USB and SATA kernel modules and repeat the find procedure again
132
# USB and SATA kernel modules and repeat the find procedure again
131
echolog "looking for data modules"
133
echolog "looking for data modules"
132
 
134
 
133
# disable kernel warnings
135
# disable kernel warnings
134
PRINTK=`cat /proc/sys/kernel/printk`
136
PRINTK=`cat /proc/sys/kernel/printk`
135
echo "0" >/proc/sys/kernel/printk
137
echo "0" >/proc/sys/kernel/printk
136
DATA="`find_live_data_dir $MOUNTDIR`"
138
DATA="`find_live_data_dir $MOUNTDIR`"
137
# enable kernel warnings
139
# enable kernel warnings
138
echo "$PRINTK" >/proc/sys/kernel/printk
140
echo "$PRINTK" >/proc/sys/kernel/printk
139
 
141
 
140
if [ "$DATA" = "" ]; then modprobe_usb_sata_modules; DATA="`find_live_data_dir $MOUNTDIR`"; fi
142
if [ "$DATA" = "" ]; then modprobe_usb_sata_modules; DATA="`find_live_data_dir $MOUNTDIR`"; fi
141
if [ "$DATA" = "" ]; then fatal "Data for LiveCD not found."; fi
143
if [ "$DATA" = "" ]; then fatal "Data for LiveCD not found."; fi
142
echolog "LiveCD found in: $DATA"
144
echolog "LiveCD found in: $DATA"
143
 
145
 
144
$DEBUGCMD
146
$DEBUGCMD
145
 
147
 
146
# If toram or copy2ram boot parameter is present, copy all .mo modules to RAM.
148
# If toram or copy2ram boot parameter is present, copy all .mo modules to RAM.
147
# (skip modules from /optional/ which are not listed in load= boot option)
149
# (skip modules from /optional/ which are not listed in load= boot option)
148
# Finaly modify DATA variable so it will point to correct directory
150
# Finaly modify DATA variable so it will point to correct directory
149
if [ "`cmdline_parameter toram`" != "" -o "`cmdline_parameter copy2ram`" != "" ]; then
151
if [ "`cmdline_parameter toram`" != "" -o "`cmdline_parameter copy2ram`" != "" ]; then
150
   echolog "copying modules to RAM, this may take some time"
152
   echolog "copying modules to RAM, this may take some time"
151
   copy_to_ram $DATA $COPY2RAM
153
   copy_to_ram $DATA $COPY2RAM
152
   cd_autoeject 1
154
   cd_autoeject 1
153
   umount $DATA 2>/dev/null
155
   umount $DATA 2>/dev/null
154
   if [ $? -ne 0 ]; then umount `dirname $DATA` 2>/dev/null; fi
156
   if [ $? -ne 0 ]; then umount `dirname $DATA` 2>/dev/null; fi
155
   DATA=$COPY2RAM
157
   DATA=$COPY2RAM
156
   cd_autoeject 0
158
   cd_autoeject 0
157
fi
159
fi
158
 
160
 
159
mkdir -p $UNION/boot
161
mkdir -p $UNION/boot
160
mount -o bind $DATA $UNION/boot
162
mount -o bind $DATA $UNION/boot
161
 
163
 
162
$DEBUGCMD
164
$DEBUGCMD
163
 
165
 
164
# DATA contains path to the base directory of all .mo images which need
166
# DATA contains path to the base directory of all .mo images which need
165
# to be mounted and inserted into live filesystem. Do it now.
167
# to be mounted and inserted into live filesystem. Do it now.
166
echolog "inserting all modules and creating live filesystem"
168
echolog "inserting all modules and creating live filesystem"
167
union_insert_modules $UNION $DATA $IMAGES
169
union_insert_modules $UNION $DATA $IMAGES
168
 
170
 
169
$DEBUGCMD
171
$DEBUGCMD
170
 
172
 
171
echo "copying rootchanges"
173
echo "copying rootchanges"
172
copy_rootchanges $DATA $UNION
174
copy_rootchanges $DATA $UNION
173
 
175
 
174
$DEBUGCMD
176
$DEBUGCMD
175
 
177
 
176
echo "creating /etc/fstab"
178
echo "creating /etc/fstab"
177
activate_fstab $UNION
179
activate_fstab $UNION
178
 
180
 
179
# More likely these directories aren't there.
181
# More likely these directories aren't there.
180
# Even if they are, this won't hurt.
182
# Even if they are, this won't hurt.
181
mkdir -p $UNION/proc
183
mkdir -p $UNION/proc
182
mkdir -p $UNION/sys
184
mkdir -p $UNION/sys
183
mkdir -p $UNION/tmp
185
mkdir -p $UNION/tmp
184
chmod 1777 $UNION/tmp
186
chmod 1777 $UNION/tmp
185
mkdir -p $UNION/dev
187
mkdir -p $UNION/dev
186
mkdir -p $UNION/initrd
188
mkdir -p $UNION/initrd
187
 
189
 
188
$DEBUGCMD
190
$DEBUGCMD
189
 
191
 
190
# no X? (set runlevel to 3)
192
# no X? (set runlevel to 3)
191
if [ "`cmdline_parameter nox`" ]; then
193
if [ "`cmdline_parameter nox`" ]; then
192
  echo "set runlevel to 3"
194
  echo "set runlevel to 3"
193
  sed -i "s/id:.:initdefault:/id:3:initdefault:/" $UNION/etc/inittab
195
  sed -i "s/id:.:initdefault:/id:3:initdefault:/" $UNION/etc/inittab
194
fi
196
fi
195
 
197
 
196
$DEBUGCMD
198
$DEBUGCMD
197
 
199
 
198
# Union contains all the files and directories unioned from all modules.
200
# Union contains all the files and directories unioned from all modules.
199
# Change root directory to it, and move initrd's root to /livecd/live/initramdisk
201
# Change root directory to it, and move initrd's root to /livecd/live/initramdisk
200
# Finaly execute /sbin/init to start the distribution.
202
# Finaly execute /sbin/init to start the distribution.
201
echolog "changing root directory..."
203
echolog "changing root directory..."
202
cd $UNION
204
cd $UNION
203
mkdir -p $INITRAMDISK
205
mkdir -p $INITRAMDISK
204
 
206
 
205
umount /sys # we won't need it anymore
207
umount /sys # we won't need it anymore
206
 
208
 
207
# if [ ! -e $UNION/dev/console ]; then mknod $UNION/dev/console c 5 1; fi
209
# if [ ! -e $UNION/dev/console ]; then mknod $UNION/dev/console c 5 1; fi
208
 
210
 
209
# Copy all dev files (found by mdev) to unioned dev directory
211
# Copy all dev files (found by mdev) to unioned dev directory
210
# so at least disk devices exist (your Linux may need them).
212
# so at least disk devices exist (your Linux may need them).
211
# Two exceptions, do not copy pty* and tty* devs.
213
# Two exceptions, do not copy pty* and tty* devs.
212
if [ ! -e /dev/console ]; then mknod /dev/console c 5 1; fi
214
if [ ! -e /dev/console ]; then mknod /dev/console c 5 1; fi
213
cp -fdR /dev . 2>/dev/null
215
cp -fdR /dev . 2>/dev/null
214
 
216
 
215
if [ -x $UNION/usr/sbin/chroot ];
217
if [ -x $UNION/usr/sbin/chroot ];
216
  then CHROOT=/usr/sbin/chroot
218
  then CHROOT=/usr/sbin/chroot
217
  else CHROOT=/usr/bin/chroot
219
  else CHROOT=/usr/bin/chroot
218
fi
220
fi
219
 
221
 
220
echolog "End of linux live scripts"
222
echolog "End of linux live scripts"
221
 
223
 
222
# pure magic ;-)
224
# pure magic ;-)
223
cat $UNION/bin/true >/dev/null
225
cat $UNION/bin/true >/dev/null
224
 
226
 
225
$DEBUGCMD
227
$DEBUGCMD
226
 
228
 
227
pivot_root . $INITRAMDISK
229
pivot_root . $INITRAMDISK
228
exec $CHROOT . sbin/init <dev/console >dev/console 2>&1
230
exec $CHROOT . sbin/init <dev/console >dev/console 2>&1
229
 
231
 
230
header "ERROR!"
232
header "ERROR!"
231
echolog "You are not supposed to be here, something went wrong!"
233
echolog "You are not supposed to be here, something went wrong!"
232
echolog "Even Ctrl+Alt+Del won't help you in kernel panic."
234
echolog "Even Ctrl+Alt+Del won't help you in kernel panic."
233
echolog "Try to boot with 'linux failsafe' or 'linux all_generic_ide'"
235
echolog "Try to boot with 'linux failsafe' or 'linux all_generic_ide'"
234
 
236