Subversion Repositories livecd

Rev

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

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