Subversion Repositories livecd

Rev

Rev 163 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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