Subversion Repositories livecd

Rev

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

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