Subversion Repositories livecd

Rev

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

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