#!/bin/sh
#为了几十个虚拟机共享一个母根文件系统,更新母机,几十个虚拟机自动更新!
if [ -b /dev/vdc ]; then
  BASE=/fsprotect
  [ -d $BASE ] || ( mkdir -m 700 $BASE || mkdir $BASE )
  [ -d $BASE/system ] || mkdir $BASE/system
  [ -d $BASE/tmp ] || mkdir $BASE/tmp
  [ -d $BASE/aufs ] || mkdir $BASE/aufs

  mount -n -t ext4 /dev/vdc $BASE/tmp ||exit
  echo -n Mounting aufs filesystem ...

  mount -n -o bind ${rootmnt} $BASE/system # 挂载共享的根文件系统
  mount -n -t aufs -o dirs=$BASE/tmp=rw:$BASE/system=ro none $BASE/aufs   # 创建aufs
  umount ${rootmnt}         # 当掉共享的根文件系统
  mount -n -o move $BASE/aufs ${rootmnt}  # 使aufs成为根
  mount -n -o move $BASE/system ${rootmnt}$BASE/system    # 移动到新根
  mount -n -o move $BASE/tmp ${rootmnt}$BASE/tmp
  echo done.
fi

 

posted on 2012-12-16 10:44  taohong  阅读(803)  评论(0)    收藏  举报