Subversion Repositories livecd

Rev

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

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