Subversion Repositories livecd

Rev

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

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