[Buildd-tools-devel] Bug#395062: add additional bind mount points to chroot

Kees Cook kees at outflux.net
Tue Oct 24 20:16:36 CEST 2006


Package: schroot
Version: 1.0.2-1
Severity: wishlist
Tags: patch

When using schroot, I have a need to bind additional mount points into 
the chroot (for example, I use /scratch for builds, since my /home mount 
is on NFS).  Hopefully my solution for this is appropriate.

The attached patch adds the schroot.conf key "mount-extra", which the 
setup/10mount script uses as a colon-separates list of additional bind 
mounts.  

-- 
Kees Cook                                            @outflux.net
-------------- next part --------------
--- schroot-1.0.2.orig/test/sbuild-chroot.cc
+++ schroot-1.0.2/test/sbuild-chroot.cc
@@ -73,6 +73,7 @@
   CPPUNIT_TEST(test_name);
   CPPUNIT_TEST(test_description);
   CPPUNIT_TEST(test_mount_device);
+  CPPUNIT_TEST(test_mount_extra);
   CPPUNIT_TEST(test_mount_location);
   CPPUNIT_TEST(test_priority);
   CPPUNIT_TEST(test_groups);
@@ -119,6 +120,13 @@
 		   "/dev/device-to-mount/example");
   }
 
+  void test_mount_extra()
+  {
+    chroot->set_mount_extra("/scratch:/testing:/var/lib/example");
+    CPPUNIT_ASSERT(chroot->get_mount_extra() ==
+		   "/scratch:/testing:/var/lib/example");
+  }
+
   void test_priority()
   {
     chroot->set_priority(6);
--- schroot-1.0.2.orig/sbuild/sbuild-chroot.cc
+++ schroot-1.0.2/sbuild/sbuild-chroot.cc
@@ -97,6 +97,7 @@
   mount_location(),
   location(),
   mount_device(),
+  mount_extra(),
   active(false),
   original(true),
   run_setup_scripts(false),
@@ -213,6 +214,18 @@
   this->mount_device = device;
 }
 
+std::string const&
+sbuild::chroot::get_mount_extra () const
+{
+  return this->mount_extra;
+}
+
+void
+sbuild::chroot::set_mount_extra (std::string const& mounts)
+{
+  this->mount_extra = mounts;
+}
+
 unsigned int
 sbuild::chroot::get_priority () const
 {
@@ -367,6 +380,7 @@
   env.add("CHROOT_MOUNT_LOCATION", get_mount_location());
   env.add("CHROOT_PATH", get_path());
   env.add("CHROOT_MOUNT_DEVICE", get_mount_device());
+  env.add("CHROOT_MOUNT_EXTRA", get_mount_extra());
 }
 
 void
@@ -469,6 +483,9 @@
   if (!get_mount_device().empty())
     // TRANSLATORS: The system device node to mount containing the chroot
     detail.add(_("Mount Device"), get_mount_device());
+  if (!get_mount_extra().empty())
+    // TRANSLATORS: The extra system mount points to duplicate inside the chroot
+    detail.add(_("Extra Mounts"), get_mount_extra());
 }
 
 void
@@ -528,6 +545,9 @@
     keyfile::set_object_value(*this, &chroot::get_mount_device,
 			      keyfile, get_name(), "mount-device");
 
+  keyfile::set_object_value(*this, &chroot::get_mount_extra,
+			     keyfile, get_name(), "mount-extra");
+
   keyfile::set_object_list_value(*this, &chroot::get_command_prefix,
 				 keyfile, get_name(), "command-prefix");
 
@@ -595,6 +615,10 @@
 			    keyfile::PRIORITY_OPTIONAL :
 			    keyfile::PRIORITY_DISALLOWED);
 
+  keyfile::get_object_value(*this, &chroot::set_mount_extra,
+			    keyfile, get_name(), "mount-extra",
+			    keyfile::PRIORITY_OPTIONAL);
+
   keyfile::get_object_list_value(*this, &chroot::set_command_prefix,
 				 keyfile, get_name(), "command-prefix",
 				 keyfile::PRIORITY_OPTIONAL);
--- schroot-1.0.2.orig/sbuild/sbuild-chroot.h
+++ schroot-1.0.2/sbuild/sbuild-chroot.h
@@ -211,6 +211,22 @@
     set_mount_device (std::string const& device);
 
     /**
+     * Get the desired extra mount locations within the chroot.
+     *
+     * @returns the mount list, colon separated.
+     */
+    virtual std::string const&
+    get_mount_extra () const;
+
+    /**
+     * Set the desired extra mount locations within the chroot.
+     *
+     * @param mounts the mount list, colon separated.
+     */
+    void
+    set_mount_extra (std::string const& mounts);
+
+    /**
      * Get the priority of the chroot.  This is a number indicating
      * whether than a ditribution is older than another.
      *
@@ -611,6 +627,8 @@
     std::string   location;
     /// Block device to mount (if any).
     std::string   mount_device;
+    /// Extra mounts within the chroot (if any).
+    std::string   mount_extra;
     /// Chroot activity status.
     bool          active;
     /// Was the chroot automatically generated?
--- schroot-1.0.2.orig/schroot/setup/10mount
+++ schroot-1.0.2/schroot/setup/10mount
@@ -81,6 +108,14 @@
 	    do_mount "-t tmpfs"   "tmpfs"    "${CHROOT_PATH}/dev/shm"
 	    do_mount "-o rw,bind" "/home"    "${CHROOT_PATH}/home"
 	    do_mount "-o rw,bind" "/tmp"     "${CHROOT_PATH}/tmp"
+
+	    # Mount user-supplied mount points
+	    if [ -n "$CHROOT_MOUNT_EXTRA" ]; then
+		echo "$CHROOT_MOUNT_EXTRA" | sed -e 's/:/\n/g' |
+		while read mnt; do
+		    do_mount "-o rw,bind" "$mnt" "${CHROOT_PATH}$mnt"
+		done
+	    fi
 	fi
 
     elif [ $1 = "setup-stop" ]; then
--- schroot-1.0.2.orig/schroot/schroot.conf.5.in
+++ schroot-1.0.2/schroot/schroot.conf.5.in
@@ -121,6 +121,10 @@
 \[oq]linux32\[cq] is the option required.  The only valid option for non-Linux
 systems is \[oq]undefined\[cq].  The default value for non-Linux systems is
 \[oq]undefined\[cq].
+.TP
+\f[CBI]mount\-extra=\fP\f[CI]mount1:mount2:...\fP
+A colon-separated list of additional mount points to bind between the host
+and the chroot, in additional to the default /proc, /home, /tmp, etc.
 .SS
 Plain and directory chroots
 .PP


More information about the Buildd-tools-devel mailing list