2 # This function checks for the presence of a real filesystem and loop-images on the target
3 # $1 = folder of rootfs, $2 = runlevel (defaults to 5)
5 # Check if there is a /sbin/init or /sbin/init.sysvinit on the card
6 if test -x $1/sbin/init -o -x $1/$REAL_INIT
10 echo -e "Note: No INIT [$REAL_INIT] found on target"
13 # Check for loop-images
14 if (ls $1/$IMAGE_PATH/*rootfs.bin) >/dev/null 2>&1
18 echo "Note: No boot-images found in [$1/$IMAGE_PATH]"
21 # Check if we have both, a real fs and boot-images. If so, ask the user what to boot
22 if test "$real_fs_found" = 1 -a "$image_found" = 1
24 echo -e "\nI have found a real filesystem and boot-images on the target"
25 echo -e "What do you want to boot?\n"
27 echo -e "\t[1] The real filesystem"
28 echo -e "\t[2] A loop-image"
33 echo -n "Your choice: "
36 if test "$junk" = 1 -o "$junk" = 2
43 1) pivot_realfs "$1" "$2">/dev/tty0;;
44 2) pivot_image "$1" "$2">/dev/tty0;;
50 # Boot a real filesystem
51 test "$real_fs_found" = 1 && pivot_realfs "$1" >/dev/tty0
54 test "$image_found" = 1 && pivot_image "$1" >/dev/tty0
56 if test "$real_fs_found" != 1 -a "$image_found" != 1
62 # This function pivot_root's into a real filesystem calling $newrootfs/sbin/init
65 test -z "$2" && RL="5" || RL="$2"
66 mkdir -p $1/media/ROM || die "mkdir -p $1/media/ROM failed"
68 mount -o remount,ro / >/dev/null 2>&1
73 # This function loop-mounts an image-file and pivot_root's into it
76 test -z "$2" && RL="5" || RL="$2"
79 # Check for rootfs images on the card
80 if test "`ls *rootfs.bin | wc -l | tr -d " "`" -gt 1
82 echo -e "\n\nPlease select a rootfs:\n"
84 # Show all available images
86 for file in `ls *rootfs.bin`
89 echo -e "\t\t[$x] $file"
95 while test -z "$IMAGE_NAME"
97 echo -en "Please choose one of the above: "
101 for file in `ls *rootfs.bin`
104 if test "$x" = "$junk"
111 IMAGE_NAME="`ls *rootfs.bin`"
112 test -z "$IMAGE_NAME" && die "No rootfs found (*rootfs.bin) in $1/$IMAGE_PATH"
115 echo "Using [$IMAGE_NAME]"
117 mkdir -p /media/image || die "mkdir -p /media/image failed"
119 echo "Setting up loopback (/dev/loop0) for $IMAGE_NAME"
120 losetup /dev/loop0 $1/$IMAGE_PATH/$IMAGE_NAME || die "losetup /dev/loop0 $1/$IMAGE_PATH/$IMAGE_NAME failed!"
121 check_fs /dev/loop0 $IMAGE_TYPE
123 echo -e "\n* * * Booting rootfs image * * *\n"
125 # Busybox's "mount" doesn't seem to like "-o loop" for some reason
126 # It works on collie and b0rks on poodle.
127 if [ "$IMAGE_TYPE" = "" ]; then
130 # If mount fails it has the tendency to spew out a _lot_ of error messages.
131 # We direct the output to /dev/null so the user can see which step actually failed.
132 mount /dev/loop0 -t $IMAGE_TYPE /media/image >/dev/null 2>&1 || die "mount -t $IMAGE_TYPE /dev/loop0 /media/image failed!"
134 mkdir -p /media/image/media/ROM || die "mkdir -p /media/image/media/ROM failed"
136 do_pivot /media/image "$RL"
139 #$1=mountpoint of the soon-to-be rootfs, $2=Runlevel
141 echo -n "Pivoting root..."
142 if (/sbin/pivot_root "$1" "$1/media/ROM")
146 # This is important since we are still cd'ed into the old root
149 ! test -d "$1" && mkdir -p "$1"
151 # Move mountpoints from the old rootfs into the new one.
152 # The *real* mount is kinda touchy feely about that
153 /bin/busybox mount -o move /media/ROM/proc /proc >/dev/null 2>&1
155 for mpt in ` mount | grep "/media/ROM/" | awk '{print $3}'`
157 new_mpt="`echo "$mpt" | sed -n "s/\/media\/ROM//p"`"
159 echo "Moving mountpoint [$mpt] -> [$new_mpt]" >/dev/tty0 2>&1
161 ! test -d "$new_mpt" && mkdir -p "$new_mpt"
162 /bin/busybox mount -o move "$mpt" "$new_mpt"
169 exec /usr/sbin/chroot . /sbin/init $2 >/dev/tty0 2>&1
172 die "* * * pivot_root failed! * * *"
177 # This functions configures the master password for altboot if none is set
179 mount -o remount,rw /
180 if test -z "$MASTER_PASSWORD"
182 echo -e "\nAltboot is a boot-manager which allows to boot from SD,\nCF, USB-Storage and NFS"
183 echo -e "\nFor security reasons altboot requires a password\nto boot into init=/bin/sh."
184 echo -e "${C_RED}This is *not* your root password!\nIt is used by altboot alone!${C_RESET}\n"
188 echo -en "\nNew password: "
191 read junk1 < /dev/tty0
194 if ! test -z "$junk1"
196 echo -en "\nRepeat: "
199 read junk2 < /dev/tty0
203 if test "$junk1" = "$junk2"
205 crypt_pw="`echo "$junk1" | md5sum | awk '{print $1}'`"
207 if test -e "${ALTBOOT_CFG_FILE}"
209 sed "/^MASTER_PASSWORD/s/\(.*\=\).*/\1\"$crypt_pw\"/" "${ALTBOOT_CFG_FILE}" > ${ALTBOOT_CFG_FILE}_
210 mv ${ALTBOOT_CFG_FILE}_ ${ALTBOOT_CFG_FILE}
211 MASTER_PASSWORD="$crypt_pw"
212 echo "Password changed."
214 echo "${ALTBOOT_CFG_FILE} is missing, no password saved"
219 echo -e "Passwords didn't match, try again\n"
227 # This function asks for altboots master password. It only returns if the correct password was supplied
229 if ! test -z "$MASTER_PASSWORD"
233 echo "Please enter your altboot master password"
238 let cnt=$cnt+$auth_timeout
240 read junk < /dev/tty0
242 if test "`echo "$junk" | md5sum | awk '{print $1}'`" = "$MASTER_PASSWORD"
246 echo "[`echo "$junk" | md5sum | awk '{print $1}'`]"
247 echo "[$MASTER_PASSWORD]"
248 echo "Wrong password, sleeping $cnt seconds..."
251 # if test "$cnt" -gt 10
262 if [ "$FSCK_IMAGES" = "yes" ]
265 if [ "$2" = "" ]; then
272 if [ -e /sbin/fsck.ext3 ]; then
273 FSCK="/sbin/fsck.ext3"
274 elif [ -e /sbin/e3fsck ]; then
276 elif [ -e /sbin/fsck.ext2 ]; then
277 FSCK="/sbin/fsck.ext2"
278 elif [ -e /sbin/e2fsck ]; then
281 test -n "$FSCK" && FSCK="$FSCK -p"
284 if [ -e /sbin/dosfsck ]; then
285 FSCK="/sbin/dosfsck -a"
289 if [ "$FSCK" = "" ]; then
290 echo "Could not find fsck for $FSTYPE!"
292 echo "Checking file system on $1"
298 # Make the initial rootfs a bit more usable
300 echo -n "Mounting rootfs rw..." >/dev/tty0
301 mount -o remount,rw / >/dev/tty0 2>&1 && echo ok >/dev/tty0|| die "mount -o remount,rw / failed"
303 mount | grep -q "/proc " >/dev/null 2>&1 && echo "Note: /proc is already mounted" || mount proc -t proc /proc >/dev/tty0 2>&1
305 if ( uname -r | grep -q "2.6." )
307 mount | grep -q "/sys " >/dev/null 2>&1 && echo "Note: /sys is already mounted" || mount sys -t sysfs /sys >/dev/tty0 2>&1
310 echo -n "Generating device files..." >/dev/tty0
311 /etc/init.d/devices start && echo ok >/dev/tty0 || die "FAILED"
315 if mount | grep -q "/media/card"
317 echo "Note: /media/card is already mounted"
319 # We can't trust that the SD device file is there when running kernel 2.6 w/ udev
320 # and starting udev at this point may not be the best idea...
321 if `uname -r | grep -q "2.6"`
323 #Let's just assume the device file name never changes...
324 dev_no="`echo "$SD_DEVICE" | sed -n "s/\/dev\/mmcblk\(.*\)p\(.*\)/\1/p"`"
325 part_no="`echo "$SD_DEVICE" | sed -n "s/\/dev\/mmcblk\(.*\)p\(.*\)/\2/p"`"
326 ! test -e /dev/mmcblk${dev_no} && mknod /dev/mmcblk${dev_no} b 254 0
327 ! test -e /dev/mmcblk${dev_no}p${part_no} && mknod /dev/mmcblk${dev_no}p${part_no} b 254 $part_no
330 # Kernel 2.6 has the SD driver compiled into the kernel
331 if test -n "$SD_KERNEL_MODULE"
333 echo -n "Loading SD kernel module..."
334 /sbin/insmod $SD_KERNEL_MODULE >/dev/null 2>&1 && echo ok || die "insmod failed"
336 echo "No SD kernel module configured, assuming it's build-in"
339 check_fs "$SD_DEVICE"
341 echo -n "Mounting $SD_MOUNTPOINT..." >/dev/tty0
342 /bin/mount -t auto -o defaults,noatime $SD_DEVICE $SD_MOUNTPOINT >/dev/null 2>&1 && echo ok >/dev/tty0|| die "/bin/mount -t auto -o defaults,noatime $SD_DEVICE $SD_MOUNTPOINT failed"
346 # Give the SD and CF mounting some time. This is a must for SD
351 if mount | grep -q "/media/cf "
353 echo "Note: /media/cf is already mounted"
355 /etc/init.d/pcmcia status | grep -q running || /etc/init.d/pcmcia start && echo "Note: cardmgr is already active"
359 # Give the SD and CF mounting some time. This is a must for SD
362 mount | grep -q "/media/cf " || mount /media/cf
367 if mount | grep -q "/home "
369 echo "Note: /home is already mounted"
372 if ( cat /etc/fstab | grep -v "^#" | grep "/home " )
374 echo "Mounting /home"
375 home_fstab="`grep "/home " /etc/fstab`"
376 home_dev="`echo "$home_fstab" | awk '{print $1}'`"
377 home_fs="`echo "$home_fstab" | awk '{print $3}'`"
378 home_options="`echo "$home_fstab" | awk '{print $4}'`"
380 mount -t "$home_fs" -o $home_options "$home_dev" /home