Subversion Repositories livecd

Rev

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

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