summaryrefslogtreecommitdiff
path: root/packages/slugos-init/files
diff options
context:
space:
mode:
authorFlorian Boor <florian.boor@kernelconcepts.de>2006-02-01 13:09:32 +0000
committerOpenEmbedded Project <openembedded-devel@lists.openembedded.org>2006-02-01 13:09:32 +0000
commit57a0ea251c99054f1da88f4ae0233010a7a062e1 (patch)
tree2782d6222bcd0e7ca92724de4d5691dcc6ca791f /packages/slugos-init/files
parent1301f1dfdeeee12f1638386f161b0bac630f8e1c (diff)
parent4f53bb2d58aba4a382057369405e00b165b95f42 (diff)
merge of 6287535c46a3cdb7bc8a84eaeead326756fd3f98
and 99edbe0f3af53904ca2cb45c0849c1580b274a1d
Diffstat (limited to 'packages/slugos-init/files')
-rw-r--r--packages/slugos-init/files/functions14
-rw-r--r--packages/slugos-init/files/initscripts/fixfstab91
-rw-r--r--packages/slugos-init/files/turnup11
3 files changed, 115 insertions, 1 deletions
diff --git a/packages/slugos-init/files/functions b/packages/slugos-init/files/functions
index d631579966..ef10d65fb2 100644
--- a/packages/slugos-init/files/functions
+++ b/packages/slugos-init/files/functions
@@ -372,3 +372,17 @@ umountflash(){
return 0
}
+
+#
+# uuid_by_partition
+# output a list of partitions and their UUIDs
+uuid_by_partition() {
+ blkid -c /dev/null -s UUID | sed -n 's/^\([^:]*\): .*UUID="\([^"]*\)".*$/\1 \2/p'
+}
+
+#
+# partition_of uuid
+# return the partition corresponding to the UUID
+partition_of() {
+ sed -n 's/^\([^ ]*\) '"$1"'$/\1/p'
+}
diff --git a/packages/slugos-init/files/initscripts/fixfstab b/packages/slugos-init/files/initscripts/fixfstab
new file mode 100644
index 0000000000..67116a12fd
--- /dev/null
+++ b/packages/slugos-init/files/initscripts/fixfstab
@@ -0,0 +1,91 @@
+#!/bin/sh
+# validate /etc/fstab against the current UUID list in
+# /etc/uuid_by_partition
+#
+. /etc/default/functions
+pfile=/etc/uuid_by_partition
+
+#
+# use debug to find out what is going on
+test "$1" = start -o "$1" = debug || exit 0
+
+#
+# obtain the current list of parititions with UUIDs
+newlist="$(uuid_by_partition)"
+
+if test -r "$pfile"
+then
+ # read the old list
+ oldlist="$(cat "$pfile")"
+ #
+ # if it hasn't changed nothing need be done
+ test "$newlist" = "$oldlist" && exit 0
+ #
+ # it has changed, but this only matters if
+ # a previously existing uuid has moved, build
+ # a list of old device vs new device for every
+ # uuid which has moved
+ changedlist="$(
+ { echo "$oldlist"
+ echo "$newlist"
+ } | awk 'device[$2] == ""{device[$2] = $1}
+ device[$2] != $1{print device[$2], $1}')"
+
+ if test -n "$changedlist"
+ then
+ # at least one partition has moved, scan the
+ # current fstab to see if it has a reference
+ # to this partition
+ changedfstab="$(
+ { echo "$changedlist"
+ echo '#fstab'
+ cat /etc/fstab
+ } | awk 'BEGIN{list=1}
+ list==1 && $0=="#fstab"{list=0; continue}
+ list==1{new[$1] = $2; continue}
+ new[$1] != ""{print $1, new[$1]}')"
+
+ # if this list is not empty edit the fstab
+ if test -n "$changedfstab"
+ then
+ rm -f /tmp/fstab.$$
+ # if the edit fails then do not overwrite the old
+ # partition list - just exit with an error
+ { echo "$changedlist"
+ echo '#fstab'
+ cat /etc/fstab
+ } | awk 'BEGIN{list=1}
+ list==1 && $0=="#fstab"{list=0; continue}
+ list==1{new[$1] = $2; continue}
+ new[$1] != ""{$1 = new[$1]}
+ {print}' >/tmp/fstab.$$ || {
+ if test "$1" = start
+ then
+ logger -s "/etc/init.d/fixfstab: /tmp/fstab.$$: awk failed"
+ else
+ echo "debug: awk script failed with:" >&2
+ echo "$changedlist" >&2
+ echo "output in /tmp/fstab.$$" >&2
+ fi
+ exit 1
+ }
+
+ if test "$1" = start
+ then
+ mv /tmp/fstab.$$ /etc/fstab || {
+ logger -s "/etc/init.d/fixfstab: /tmp/fstab.$$: update failed"
+ exit 1
+ }
+ else
+ echo "debug: fstab changed:"
+ diff -u /etc/fstab /tmp/fstab.$$
+ fi
+ fi
+ fi
+fi
+
+# write the new list to the file, only if we
+# are doing something...
+test "$1" = start && echo "$newlist" >"$pfile"
+
+exit 0
diff --git a/packages/slugos-init/files/turnup b/packages/slugos-init/files/turnup
index d27648680f..f7fe0e7960 100644
--- a/packages/slugos-init/files/turnup
+++ b/packages/slugos-init/files/turnup
@@ -17,6 +17,10 @@ INRAM_DISK=""
force=
#
+# pfile: the uuid/partition file
+pfile=/etc/uuid_by_partition
+
+#
# fstype new
# The type of the file system mounted on "new" Outputs the last
# piece of information found, which should be the one for the
@@ -312,7 +316,7 @@ setup_rootfs() {
# setup_fstab new fsdev fstype fsoptions
# Alters the /etc/fstab entry for / to refer to the correct device and
# have the correct type and options. Essential for checkroot to remount
-# / with the correct options.
+# / with the correct options. Writes the initial uuid file.
# bad, since sed won't fail even if it changes nothing.
setup_fstab() {
sed -i '\@^[^ ]*[ ][ ]*/[ ]@s@^.*$@'"$2 / $3 $4 1 1"'@' "$1"/etc/fstab
@@ -322,6 +326,11 @@ setup_fstab() {
echo " to ensure that the root partition is mounted correctly" >&2
return 1
}
+ #
+ # build $pfile
+ uuid_by_partition >"$1""$pfile" ||
+ echo "turnup: $pfile: blkid failed (ignored)" >&2
+ return 0
}
#