altboot: - Allow a basic reconfiguration of non-flash based installations:
authorMatthias Hentges <oe@hentges.net>
Tue, 4 Apr 2006 12:07:29 +0000 (12:07 +0000)
committerOpenEmbedded Project <openembedded-devel@lists.openembedded.org>
Tue, 4 Apr 2006 12:07:29 +0000 (12:07 +0000)
- Move /home from flash into the image
- Remove SD / CF / /home ipkg dests
- Move ipkg package data from RAM into the image
- All of the above is _optional_
- Be a little bit less verbose.
- Yet _again_ change the way we detect wheter we are called by the kernel or the user...this is driving me nuts.

packages/altboot/altboot_0.0.0.bb
packages/altboot/files/akita/altboot-2.6.cfg
packages/altboot/files/altboot-menu/Advanced/40-bootNFS
packages/altboot/files/altboot.func
packages/altboot/files/collie/altboot-2.4.cfg
packages/altboot/files/init.altboot
packages/altboot/files/poodle/altboot-2.4.cfg
packages/altboot/files/spitz/altboot-2.6.cfg
packages/altboot/files/tosa/altboot-2.4.cfg

index 82314a8..2df0e16 100644 (file)
@@ -6,7 +6,7 @@ MAINTAINER = "Matthias 'CoreDump' Hentges  <oe@hentges.net>"
 LICENSE = "GPL"
 IGNORE_STRIP_ERRORS = "1"
 
-PR = "r33"
+PR = "r34"
 
 
 SRC_URI = "file://altboot-menu \
index 69f7c83..c9a030b 100644 (file)
@@ -9,6 +9,7 @@ SH_SHELL="/bin/sh"
 IMAGE_PATH="boot-images"
 IMAGE_TYPE="ext2"
 FSCK_IMAGES="yes"
+ENABLE_IMAGECONF="yes"
 
 SD_DEVICE="/dev/mmcblk0p1"
 SD_KERNEL_MODULE=""
index baa4262..e01af7f 100644 (file)
@@ -20,11 +20,11 @@ run_module() {
        init_rootfs
 
        # Needed for NFS
-       /etc/init.d/portmap start >/dev/tty1 2>&1 || die "/etc/init.d/portmap start failed!"
+       /etc/init.d/portmap start >/dev/null 2>&1 || die "/etc/init.d/portmap start failed!"
        
        # For some reason NFS mounts hang if /e/i/networking is not run.
        # For the time beeing I'm too lazy to investigate ;)
-       /etc/init.d/networking start || die "/etc/init.d/networking start failed!"
+       /etc/init.d/networking start >/dev/null 2>&1 || die "/etc/init.d/networking start failed!"
        
        sleep 2
        
@@ -126,6 +126,15 @@ run_module() {
        mkdir -p /media/nfsroot || die "mkdir -p /media/nfsroot failed!"
        
        echo -n "Mounting NFS root..."
+       
+       if ( mount | grep -q "/media/nfsroot" )
+       then
+               echo "/media/nfsroot already used, tying to umount..."
+               umount /media/image
+               losetup -d /dev/loop0
+               umount /media/nfsroot || die "umount failed!"
+       fi
+               
        mount -t nfs "$selection" /media/nfsroot && echo ok || die "mount -t nfs "$selection" /media/nfsroot failed!"
        
        # Use configured resolv.conf in the pivoted rootfs
index 612a024..0cc5911 100644 (file)
@@ -93,6 +93,8 @@ pivot_realfs() {
 
        mount -o remount,ro / >/dev/null 2>&1
 
+       test "$ENABLE_IMAGECONF" = yes && image_conf $1
+
        do_pivot "$1" "$RL"
 }
 
@@ -152,27 +154,28 @@ pivot_image() {
        
        
        echo ""
-       echo "Using [$IMAGE_NAME]"
 
        mkdir -p /media/image || die "mkdir -p /media/image failed"
 
-       echo "Setting up loopback (/dev/loop0) for $IMAGE_NAME"
        losetup /dev/loop0 $1/$IMAGE_PATH/$IMAGE_NAME || die "losetup /dev/loop0 $1/$IMAGE_PATH/$IMAGE_NAME failed!"
        check_fs /dev/loop0 $IMAGE_TYPE
        
-       echo -e "\n* * * Booting rootfs image * * *\n"
+       echo -e "\n* * * Mounting rootfs image * * *\n"
 
        # Busybox's "mount" doesn't seem to like "-o loop" for some reason
        # It works on collie and b0rks on poodle.
        if [ "$IMAGE_TYPE" = "" ]; then
                IMAGE_TYPE="auto"
        fi
+       
        # If mount fails it has the tendency to spew out a _lot_ of error messages.
        # We direct the output to /dev/null so the user can see which step actually failed.     
        mount /dev/loop0 -t $IMAGE_TYPE /media/image >/dev/null 2>&1 || die "mount -t $IMAGE_TYPE /dev/loop0 /media/image failed!"      
 
        mkdir -p /media/image/media/ROM || die "mkdir -p /media/image/media/ROM failed"
 
+       test "$ENABLE_IMAGECONF" = yes && image_conf /media/image
+       
        do_pivot /media/image "$RL"
 }
 
@@ -214,6 +217,105 @@ do_pivot(){
 
 }
 
+# $1: Path to mounted rootfs
+image_conf(){
+       ! test -d "$1" && die "image_conf: [$1] not found / no directory"       
+       
+       test -e "$1/etc/.image_conf.done" && return
+       
+       echo -e "\n\n* * * rootfs configuration * * *\n"
+       echo -e "This setup lets you reconfigure your new rootfs."
+       echo "Most probably the rootfs is configured with"
+       echo "defaults based on a flash installation."
+       echo "If unsure, go with the defaults by pressing <ENTER>."
+       echo ""
+       
+       if ( cat $1/etc/fstab | grep -v "^#" | grep -q "/home " )               
+       then                                            
+               while true
+               do
+                       echo "Usually your /home directory is located on another flash partition."
+                       echo -n "Do you want me to move /home inside the loop-image? [N|y] "
+                       read junk
+                       
+                       if test "$junk" = "y" -o "$junk" = "Y"
+                       then
+                               cat $1/etc/fstab | sed "/.*\/home.*/s/\/home/\/home.orig/" > $1/etc/fstab_
+                               mv $1/etc/fstab_ $1/etc/fstab
+                               break
+                       fi
+                       
+                       test "$junk" = "" -o "$junk" = n -o "$junk" = N && break
+               done
+               
+       fi      
+
+       echo ""
+                               
+#      if ( cat $1/etc/fstab | grep -v "^#" | grep -q "/var" )         
+#      then                                            
+#              while true
+#              do
+#                      echo "This is mainly for testing purposes."
+#                      echo -n "Do you want to configure /var as a normal non-tmpfs directory? [N|y] "
+#                      read junk
+#                      
+#                      if test "$junk" = "y" -o "$junk" = "Y"
+#                      then
+#                              cat $1/etc/fstab | sed "/.*\/var.*/s/\(.*\)/#\ \1/" > $1/etc/fstab_
+#                              mv $1/etc/fstab_ $1/etc/fstab
+#                              break
+#                      fi
+#                      
+#                      test "$junk" = "" -o "$junk" = n -o "$junk" = N && break
+#              done
+#      fi              
+
+       echo ""
+
+       if ( cat $1/etc/ipkg.conf | grep -q ^lists_dir )                
+       then                                            
+               while true
+               do
+                       echo -e "Wasting RAM is never a good idea.\nOnly say Y if your rootfs is very small in size"
+                       echo -n "Do you want to store ipkg package data in RAM? [N|y] "
+                       read junk
+                       
+                       if test "$junk" = "" -o "$junk" = n -o "$junk" = N
+                       then
+                               cat $1/etc/ipkg.conf | sed "/^lists_dir.*/s/\(.*\)/#\ \1/"> $1/etc/ipkg.conf_                           
+                               mv $1/etc/ipkg.conf_ $1/etc/ipkg.conf
+                               break
+                       fi
+                       
+                       test "$junk" = "y" -o "$junk" = "Y" && break
+               done
+       fi              
+
+       echo ""
+
+       if ( cat $1/etc/ipkg.conf | grep -q "^dest sd" )                
+       then                                            
+               while true
+               do
+                       echo -n "Do you want to keep the SD, CF and /home ipkg install targets? [N|y] "
+                       read junk
+                       
+                       if test "$junk" = "" -o "$junk" = n -o "$junk" = N
+                       then
+                               cat $1/etc/ipkg.conf | sed "/^dest\ \(sd\|cf\|home\).*/s/\(.*\)/#\ \1/" > $1/etc/ipkg.conf_                     
+                               mv $1/etc/ipkg.conf_ $1/etc/ipkg.conf
+                               break
+                       fi
+                       
+                       test "$junk" = "y" -o "$junk" = "Y" && break
+               done
+       fi      
+               
+       
+       touch "$1/etc/.image_conf.done" 
+}
+
 # This functions configures the master password for altboot if none is set
 set_password() {
        mount -o remount,rw /
index 9d2560f..bc0f9ca 100644 (file)
@@ -8,7 +8,9 @@ REAL_INIT="/sbin/init.sysvinit"
 SH_SHELL="/bin/sh"
 IMAGE_PATH="boot-images"
 IMAGE_TYPE="ext2"
-FSCK_IMAGES="no"
+FSCK_IMAGES="yes"
+ENABLE_IMAGECONF="yes"
+
 SD_DEVICE="/dev/mmcda1"
 SD_KERNEL_MODULE="/lib/modules/2.4.18-rmk7-pxa3-embedix/kernel/drivers/block/sharp_mmcsd_m.o"
 INIT_RUNLEVEL="5"
index ed95ce1..22f3e86 100644 (file)
@@ -283,10 +283,12 @@ wait_for_input() {
 }
 
 # * * * * * * This is the main function * * * * * *
-
-if test -f /proc/cmdline -a "$1" != "-force"
+# Note: this is positivly ugly. If someone knows a better way to detect wheter
+# we are already booted into a runlevel _without_ reading /var and / or using `runlevel`
+# PLEASE let me know.
+if test -f /proc/cmdline -a "`ps ax|wc -l|tr -d " "`" -gt 30 -a "$1" != "-force"
 then
-       echo "altboot: Using real init [$REAL_INIT] [$*] *" >/dev/tty1
+       echo "altboot: Using real init [$REAL_INIT] [$*] [`ps ax|wc -l|tr -d " "`] *" >/dev/tty1
        exec $REAL_INIT $*
 #      exec $SH_SHELL </dev/tty0 >/dev/tty0 2>&1
        exit 0
index 9d2560f..c5bd170 100644 (file)
@@ -16,5 +16,7 @@ NO_GUI_RL="2"
 MASTER_PASSWORD=""
 ASK_PW_ON_BOOT="no"
 
+ENABLE_IMAGECONF="yes"
+
 SD_MOUNTPOINT="/media/card"
 CF_MOUNTPOINT="/media/cf"
index 69f7c83..c9a030b 100644 (file)
@@ -9,6 +9,7 @@ SH_SHELL="/bin/sh"
 IMAGE_PATH="boot-images"
 IMAGE_TYPE="ext2"
 FSCK_IMAGES="yes"
+ENABLE_IMAGECONF="yes"
 
 SD_DEVICE="/dev/mmcblk0p1"
 SD_KERNEL_MODULE=""
index edbaff8..c463ca0 100644 (file)
@@ -8,7 +8,8 @@ SH_SHELL="/bin/sh"
 
 IMAGE_PATH="boot-images"
 IMAGE_TYPE="ext2"
-FSCK_IMAGES="no"
+FSCK_IMAGES="yes"
+ENABLE_IMAGECONF="yes"
 
 SD_DEVICE="/dev/mmcda1"
 SD_KERNEL_MODULE="/lib/modules/2.4.18-rmk7-pxa3-embedix/kernel/drivers/block/sharp_mmcsd_m.o"