Subversion Repositories livecd

Rev

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

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