Magellan Linux

Annotation of /trunk/mkinitrd-magellan/livecd/linuxrc.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (hide annotations) (download) (as text)
Sat Sep 1 22:45:15 2007 UTC (17 years, 2 months ago) by niro
File MIME type: application/x-sh
File size: 3980 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

1 niro 532 #!/bin/sh
2     # $Header: /home/cvsd/magellan-cvs/magellan-src/mkinitrd-magellan/livecd/linuxrc.sh,v 1.1 2007-09-01 22:44:23 niro Exp $
3    
4     # loads given kernel modules
5     load_kernel_modules()
6     {
7     local type="$1"
8     local module
9     local args
10    
11     echo -e "-- Loading ${type} modules:"
12     ( cat /etc/modules.${type}; echo) | while read module args
13     do
14     case "${module}" in
15     \#*|"") continue ;;
16     esac
17    
18     if [ -e /lib/${module}.ko ]
19     then
20     insmod -f /lib/${module}.ko ${args} > /dev/null 2>&1
21     [ $? -eq 0 ] && echo -e "-- ${module}"
22     fi
23     done
24     echo
25     }
26    
27     # check_drives $devices $fstype
28     check_drives()
29     {
30     local devices="$1"
31     local fs="$2"
32    
33     for dev in ${devices}
34     do
35     mount -t ${fs} ${dev} /sysroot/mnt/cdrom >/dev/null 2>&1
36     media_found=$?
37    
38     # if mount was ok check if cdid exists
39     if [ "${media_found}" -eq 0 ]
40     then
41     [ -e /sysroot/mnt/cdrom/livecdrootfs.sqsh ] && media_id_ok=$?
42     umount /sysroot/mnt/cdrom
43    
44     if [ "${media_id_ok}" -eq 0 ]
45     then
46     echo -e "Magellan boot device found."
47     BOOT_DEVICE="${dev}"
48     FSTYPE=${fs}
49     break
50     fi
51     fi
52     done
53     }
54    
55     ## some defaults ##
56     DOSCSI=no
57     DOUSB=no
58     DOSATA=no
59     NOPATA=no
60    
61     ## starts here ##
62    
63     # mount essential filesystems
64     mount -t proc proc /proc
65     mount -t sysfs sysfs /sys
66    
67     # silencio
68     echo 0 > /proc/sys/kernel/printk
69    
70     # check command line for params
71     for i in $(cat /proc/cmdline)
72     do
73     case "${i}" in
74     doscsi)
75     DOSCSI=yes
76     ;;
77     dousb)
78     DOUSB=yes
79     ;;
80     dosata)
81     DOSATA=yes
82     ;;
83     nopata)
84     NOPATA=yes
85     ;;
86     esac
87     done
88    
89     # now load all needed modules
90     load_kernel_modules "generic"
91     [ "${NOPATA}" != "yes" ] && load_kernel_modules "pata"
92     [ "${DOSCSI}" = "yes" ] && load_kernel_modules "scsi"
93     [ "${DOUSB}" = "yes" ] && load_kernel_modules "usb"
94     [ "${DOSATA}" = "yes" ] && load_kernel_modules "sata"
95    
96     # create newroot mount point
97     mkdir -p /sysroot
98     # fake a new filesystem (also needed with an initramfs!!)
99     mount -t tmpfs tmpfs /sysroot
100    
101     mkdir -p /sysroot/mnt/cdrom
102     mkdir -p /sysroot/mnt/cloop
103     mkdir -p /sysroot/mnt/magellan
104    
105    
106     # needed for the usbstick, the timeout maybe to short
107     if [ "${DOUSB}" = "yes" ]; then
108     echo "-- Waiting 8 seconds for possible usb mount ..."
109     sleep 8
110     fi
111    
112     # searching cdrom with cdid
113     BOOT_DEVICE=""
114     FSTYPE=""
115    
116     echo "Searching for a boot device ..."
117    
118     # searching usbstick
119     if [ "${DOUSB}" = "yes" ]; then
120     check_drives "/dev/sd*" "vfat"
121     check_drives "/dev/sg*" "vfat"
122     fi
123    
124     # for cdrom_device in $CDROM_LIST (ide)
125     check_drives "/dev/cdroms/*" iso9660
126     check_drives "/dev/hd*" iso9660
127    
128     # scsi cdroms
129     if [ "${DOSCSI}" = "yes" ] || [ "${DOSATA}" = "yes" ]; then
130     check_drives "/dev/sr*" iso9660
131     check_drives "/dev/sg*" iso9660
132     check_drives "/dev/scd*" iso9660
133     fi
134    
135     # mount our rootfs from cdrom
136     if [ "${BOOT_DEVICE}" = "" ]
137     then
138     echo "No Magellan boot CD/USBStick found!!!"
139     ash
140     exit 1
141     else
142     echo -e "Booting from: $BOOT_DEVICE ..."
143     mount -o ro -t "${FSTYPE}" "${BOOT_DEVICE}" /sysroot/mnt/cdrom >/dev/null 2>&1
144    
145     # write our boot_device to /mnt/.bootdev for later use (mtab)
146     echo "BOOTDEV=${BOOT_DEVICE}" > /sysroot/.bootdev
147     echo "FSTYPE=${FSTYPE}" >> /sysroot/.bootdev
148    
149     # mount squashfs
150     echo -e "Mounting squashfs system image ..."
151     echo
152     [ ! -e /dev/loop0 ] && mknod /dev/loop0 b 7 0
153     mount -o loop,ro -t squashfs /sysroot/mnt/cdrom/livecdrootfs.sqsh /sysroot/mnt/cloop
154    
155     # symlinking cloop rootfs to /mnt as newroot
156     cd /sysroot
157    
158     for x in bin sbin lib boot usr opt
159     do
160     ln -s mnt/cloop/${x} ${x}
161     done
162     mkdir -p initrd proc tmp sys var/tmp dev media
163    
164     # make /sysroot/dev/console & /mnt/dev/null
165     [ ! -e /sysroot/dev/console ] && mknod -m 600 /sysroot/dev/console c 5 1
166     [ ! -e /sysroot/dev/null ] && mknod -m 666 /sysroot/dev/null c 1 3
167    
168     (cd /sysroot/mnt/cloop; cp -a etc root home var /sysroot)
169    
170     # ensure the right permissions
171     chmod 1777 /sysroot/tmp
172     chmod 1777 /sysroot/var/tmp
173     fi
174    
175     cd /
176    
177     # de-silencio
178     echo 3 > /proc/sys/kernel/printk
179    
180     echo "-- Switching to real sysroot ..."
181     umount /sys
182     umount /proc
183    
184     exec run-init /sysroot /sbin/init $@ </sysroot/dev/console >/sysroot/dev/console