Subversion Repositories livecd

Rev

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

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