Subversion Repositories livecd

Rev

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

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