Permalink
Browse files

Setup file system using RO/RW bind mounts on non-Ubuntu systems

  • Loading branch information...
1 parent c8bb68f commit dc271e52955585082b00806c2c6e40cf1292216d Dmitriy Kalinin and Pieter Noordhuis committed Mar 15, 2013
Showing with 43 additions and 1 deletion.
  1. +43 −1 warden/root/linux/skeleton/lib/common.sh
@@ -17,7 +17,40 @@ function get_distrib_codename() {
fi
}
-function setup_fs() {
+function overlay_directory_in_rootfs() {
+ # Skip if exists
+ if [ ! -d tmp/rootfs/$1 ]
+ then
+ if [ -d mnt/$1 ]
+ then
+ cp -r mnt/$1 tmp/rootfs/
+ else
+ mkdir -p tmp/rootfs/$1
+ fi
+ fi
+
+ mount -n --bind tmp/rootfs/$1 mnt/$1
+ mount -n --bind -o remount,$2 tmp/rootfs/$1 mnt/$1
+}
+
+function setup_fs_other() {
+ mkdir -p tmp/rootfs mnt
+ mkdir -p $rootfs_path/proc
+
+ mount -n --bind $rootfs_path mnt
+ mount -n --bind -o remount,ro $rootfs_path mnt
+
+ overlay_directory_in_rootfs /dev rw
+ overlay_directory_in_rootfs /etc rw
+ overlay_directory_in_rootfs /home rw
+ overlay_directory_in_rootfs /sbin rw
+
+ mkdir -p tmp/rootfs/tmp
+ chmod 777 tmp/rootfs/tmp
+ overlay_directory_in_rootfs /tmp rw
+}
+
+function setup_fs_ubuntu() {
mkdir -p tmp/rootfs mnt
distrib_codename=$(get_distrib_codename)
@@ -36,6 +69,15 @@ function setup_fs() {
esac
}
+function setup_fs() {
+ if grep -q -i ubuntu /etc/issue
+ then
+ setup_fs_ubuntu
+ else
+ setup_fs_other
+ fi
+}
+
function teardown_fs() {
umount mnt
}

0 comments on commit dc271e5

Please sign in to comment.