diff options
author | John Bowler <jbowler@nslu2-linux.org> | 2006-02-01 08:25:30 +0000 |
---|---|---|
committer | OpenEmbedded Project <openembedded-devel@lists.openembedded.org> | 2006-02-01 08:25:30 +0000 |
commit | 9c6194db05ec44fb2f1cf4a0032fc050d35d47b5 (patch) | |
tree | 3daa148dc3353e061cf83cb33316d6b6c8240b3d /packages/slugos-init | |
parent | 594313d9d9a596e54ece19ccda7a4c3602fea55e (diff) |
slugos-init: add init script to handle USB device moving in 0.10
- the init.d script fixfstab uses blkid to build a partition/uuid
mapping table and compares this to the version from the previous
boot, if anything changes /etc/fstab is updated
Diffstat (limited to 'packages/slugos-init')
-rw-r--r-- | packages/slugos-init/files/functions | 14 | ||||
-rw-r--r-- | packages/slugos-init/files/initscripts/fixfstab | 91 | ||||
-rw-r--r-- | packages/slugos-init/files/turnup | 11 | ||||
-rw-r--r-- | packages/slugos-init/slugos-init_0.10.bb | 7 |
4 files changed, 120 insertions, 3 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 } # diff --git a/packages/slugos-init/slugos-init_0.10.bb b/packages/slugos-init/slugos-init_0.10.bb index 179e5a735e..6a31fca367 100644 --- a/packages/slugos-init/slugos-init_0.10.bb +++ b/packages/slugos-init/slugos-init_0.10.bb @@ -4,7 +4,7 @@ PRIORITY = "required" LICENSE = "GPL" DEPENDS = "base-files devio" RDEPENDS = "busybox devio" -PR = "r51" +PR = "r52" SRC_URI = "file://boot/flash \ file://boot/disk \ @@ -12,6 +12,7 @@ SRC_URI = "file://boot/flash \ file://boot/ram \ file://boot/network \ file://boot/udhcpc.script \ + file://initscripts/fixfstab \ file://initscripts/syslog.buffer \ file://initscripts/syslog.file \ file://initscripts/syslog.network \ @@ -35,7 +36,8 @@ CPROGS = "${USRSBINPROGS} ${SBINPROGS}" SCRIPTS = "turnup reflash leds sysconf" BOOTSCRIPTS = "flash disk nfs ram network udhcpc.script" INITSCRIPTS = "syslog.buffer syslog.file syslog.network zleds\ - leds_startup rmrecovery sysconfsetup umountinitrd.sh" + leds_startup rmrecovery sysconfsetup umountinitrd.sh\ + fixfstab" # This just makes things easier... S="${WORKDIR}" @@ -120,6 +122,7 @@ pkg_postinst_slugos-init() { test -n "$D" && opt="-r $D" update-rc.d $opt hwclock.sh start 8 S . start 45 0 6 . update-rc.d $opt umountinitrd.sh start 9 S . + update-rc.d $opt fixfstab start 10 S . update-rc.d $opt syslog.buffer start 11 S . start 49 0 6 . update-rc.d $opt sysconfsetup start 12 S . update-rc.d $opt syslog.file start 39 S . start 47 0 6 . |