initdiskless patch

From: Jose M Rodriguez <josemi_at_freebsd.jazztel.es>
Date: Thu, 11 Nov 2004 20:18:46 +0100
Hi,
This is an absolute _NOT_ tested patch, but an idea that can be even MFC 
to RELENG_4

comments welcome,
--
  josemi

----- patch-initdiskless
--- /etc/rc.d/initdiskless Tue Oct 26 18:16:19 2004
+++ initdiskless Thu Oct 28 13:42:29 2004
_at__at_ -91,10 +91,15 _at__at_
 #  initialize it from a template, it is preferrable to specify
 #  it in fstab e.g. as  "md /tmp mfs -s=30m,rw 0 0"
 #
+# /conf/T/SUBDIR.pax
+#  The file is expanded into /SUBDIR (and a memory filesystem
+#  is created for /SUBDIR if necessary). The presence of this
+#  file prevents the copy from other sources
+#
 # /conf/T/SUBDIR.cpio.gz
-#  The file is cpio'd into /SUBDIR (and a memory filesystem is
-#  created for /SUBDIR if necessary). The presence of this file
-#  prevents the copy from /conf/T/SUBDIR/
+#  The file is expanded into /SUBDIR (and a memory filesystem
+#  is created for /SUBDIR if necessary). The presence of this
+#  file prevents the copy from /conf/T/SUBDIR/
 #
 # /conf/T/SUBDIR.remove
 #  The list of paths contained in the file are rm -rf'd
_at__at_ -250,6 +255,7 _at__at_
 #   it before attemping to the remount.  This allows the root to be
 #   relocated without needing to change the remount files.
 #
+
 for i in ${templates} ; do
     for j in /conf/$i/* ; do
  # memory filesystem size specification
_at__at_ -291,27 +297,56 _at__at_
 # so if the cpio archive is present, it prevents the files from dir/
 # from being copied.
 
+# a valid gzip
+if [ -x /bin/gzip ]; then
+ use_gunzip="/bin/gzip -d"
+elif [ -x /rescue/gzip ]; then
+ use_gunzip="/rescue/gzip -d"
+elif [ -x /stand/gzip ]; then
+ use_gunzip="/stand/gzip -d"
+else
+ use_gunzip=""
+fi
+
 for i in ${templates} ; do
-    for j in /conf/$i/* ; do
- subdir=${j##*/}
- if [ -d $j -a ! -f $j.cpio.gz  ]; then
+    for j in /conf/$i/*.pax ; do
+ subdir=${j%*.pax}
+ subdir=${subdir##*/}
+ eval _from=\$md_from_${subdir}_${i}
+ if [ -r $j -a ! -n "${_from}" ]; then
      create_md $subdir
-     cp -Rp $j/* /$subdir
+     echo "Loading /$subdir from pax archive $j"
+     (cd / ; /bin/pax -r -pe ${busbir} < $j )
+     eval md_from_${subdir}_${i}="$j"
  fi
     done
-    for j in /conf/$i/*.cpio.gz ; do
- subdir=${j%*.cpio.gz}
- subdir=${subdir##*/}
- if [ -f $j ]; then
+    if [ -n "${use_gunzip}" ]; then
+ for j in /conf/$i/*.cpio.gz ; do
+     subdir=${j%*.cpio.gz}
+     subdir=${subdir##*/}
+     eval _from=\$md_from_${subdir}_${i}
+     if [ -r $j -a ! -n "${_from}" ]; then
+  create_md $subdir
+  echo "Loading /$subdir from cpio archive $j"
+  (cd / ; ${use_gunzip} < $j | /bin/pax -r -pe ${subdir} )
+  eval md_from_${subdir}_${i}="$j"
+     fi
+ done
+    fi
+    for j in /conf/$i/* ; do
+ subdir=${j##*/}
+ eval _from=\$md_from_${subdir}_${i}
+ if [ -d $j -a ! -n "${_from}" ]; then
      create_md $subdir
-     echo "Loading /$subdir from cpio archive $j"
-     (cd / ; /stand/gzip -d < $j | /stand/cpio --extract -d )
+     echo "Copying /$subdir from $j"
+     cp -Rp $j/* /$subdir
+     eval md_from_${subdir}_${i}="$j"
  fi
     done
     for j in /conf/$i/*.remove ; do
  subdir=${j%*.remove}
  subdir=${subdir##*/}
- if [ -f $j ]; then
+ if [ -r $j ]; then
      # doubly sure it is a memory disk before rm -rf'ing
      create_md $subdir
      (cd /$subdir; rm -rf `/bin/cat $j`)
Received on Thu Nov 11 2004 - 18:18:53 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:21 UTC