Rebuild mount table (was: Re: Pushing out Cygwin installations)

Ehud Karni ehud@unix.simonwiesel.co.il
Thu Jan 11 10:55:00 GMT 2001


On Thu, 11 Jan 2001 12:14:55 -0500, Christopher Faylor <cgf@redhat.com> wrote:
>
> On Thu, Jan 11, 2001 at 12:01:28PM -0500, Danko, Gary wrote:
> >
> >The NEW installation couldn't find "root" so that made me curious. Where
> >does Cygwin store the information about the location of root?
> >
> >If I install Cygwin on one machine.. How could I copy that installation
> >reliably to another machine?
>
> The mount table is stored in the registry.  You must not have copied
> it correctly.
>
> However, you really should just use "mount" to duplicate the directory
> structure on the other machines.  Copying the registry keys bypasses
> Cygwin and we make no guarantees that the registry keys will remain
> the same between releases.

Here is a bash script I wrote to save the mount table and rebuild it.
It has 2+ known drawbacks:
   1) It can not handle paths with spaces (Windows or Cygwin).
   2) It does not create missing mount points.
  2+) The order of the mounts is the one of the current mount, so
      internal mount may precede external one (e.g. /foo/bar may be
      mounted before /foo). I think it will work on Cygwin (because
      mount on non-existing directories is permitted).

I will value comments and suggestions for improvements.

Ehud.

------------------------- mount-export.sh --------------------------

#! /bin/sh -ex
# Export the current mount into a script to rebuild it
# the script is written into $1 (stdout if none/empty)
# ----------------------------------------------------

dcd_ln ()                                  # decode 1 mount line
{                                          # given as argument

    WINP=`echo $1 | cut "-d " -f1`         # prefix  name
    MNTP=`echo $1 | cut "-d " -f2`         # prefix  name
    U_S=`echo $1 | cut "-d " -f3`          # user / system
    BTX=`echo $1 | cut "-d " -f4`          # binmode / textmode , exec

    FLAGS="-f"
    case "$U_S" in
        "user" )   U_S=u   ;;              # user mount
        "system" ) U_S=s   ;;              # user mount
           *  )    echo "Error, type is $U_S, should be user/system !"
                   exit 1  ;;              # grave error
    esac
    FLAGS="${FLAGS}u"       # user mount

    case "$BTX" in
        *"exec" )  FLAGS="${FLAGS}x" ;;    # mounted with exec[ute]
    esac

    case "$BTX" in
        "bin"* )   BTX=b   ;;              # mounted in binary mode
        "text"* )  BTX=t   ;;              # mounted in text mode
           *  )    echo "Error, flags are $BTX, should be binmode/textmode !"
                   exit 1  ;;              # grave error
    esac
    FLAGS="$FLAGS$U_S$BTX"                 # flags for mount
}
# ----------------------------------------------------------------------

add_mounts ()                              # work on current mounts
{                                          # (output of mount command)
    read MLN                               # ignore 1st line
    read MLN                               # next line
    while [ "$MLN" != "" ]                 # stop on extra empty line
    do
        dcd_ln "$MLN"                      # break into components
        echo "mount $FLAGS $WINP $MNTP"    # write mount command
        read MLN                           # next line
    done
}
# ----------------------------------------------------------------------


if [ "$1" != "" ] ; then
    exec 1>"$1"                            # change stdout to $1
fi

echo "#! /bin/sh -ex
# Rebuild the mount table, Original configuration from:"
HST=`hostname`
date -u "+# $HST at %Y-%m-%d %H:%M"
echo "# ----------------------------------------------------

# 1st remove all currently mount points & prefixes
umount --remove-all-mounts
umount --remove-cygdrive-prefix

# 2nd set Cygwin drive prefix"             # end of echo !

PRFXLN=`mount --show-cygdrive-prefixes | tail -1`
dcd_ln "dummy $PRFXLN"                     # decode prefix
case "$BTX$U_S" in                         # special flags for prefix
    "bs" ) FLAGS="-bs" ;;                  # -bs
    "bu" ) FLAGS="-b"  ;;                  # -b
    "ts" ) FLAGS="-s"  ;;                  # -s
      *  ) FLAGS=""    ;;                  # none (tu)
esac
echo "mount $FLAGS --change-cygdrive-prefix $MNTP"

echo -e "\n# restore mounts, one by one\n"

( mount ; echo ) | add_mounts              # write all mounts

echo "
############################## end of re-mount #############################"

############################## mount-export.sh ##############################


--
 @@@@@@ @@@ @@@@@@ @    @   Ehud Karni  Simon & Wiesel  Insurance agency
     @    @      @  @@  @   Tel: +972-3-6212-757    Fax: +972-3-6292-544
     @    @ @    @ @  @@    (USA)  Fax  and  voice  mail:  1-815-5509341
     @    @ @    @ @    @        Better     Safe     Than     Sorry
 http://www.simonwiesel.co.il    mailto:ehud@unix.simonwiesel.co.il

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list