From 2ae84fcc514f0462c62ef197853a7a91efc1d737 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 2 Feb 2018 16:02:17 -0500 Subject: [PATCH] Revert tmpfs mount removal To fix #406, I reverted the tmpfs mount we add at boot time. As we can see in #455, it was a bad idea. In addition to bringing back that mount, I've also added a `tmpfs_mount_size` config that allows to change the size of the mount from its default `2G`. It's also possible to disable the mount altogether. fixes #455 --- lib/vagrant-lxc/action.rb | 4 ---- lib/vagrant-lxc/action/boot.rb | 5 ++++ .../action/remove_temporary_files.rb | 23 ------------------- lib/vagrant-lxc/config.rb | 6 +++++ 4 files changed, 11 insertions(+), 27 deletions(-) delete mode 100644 lib/vagrant-lxc/action/remove_temporary_files.rb diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index 21f8e3a..38d08ac 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -12,7 +12,6 @@ require 'vagrant-lxc/action/handle_box_metadata' require 'vagrant-lxc/action/prepare_nfs_settings' require 'vagrant-lxc/action/prepare_nfs_valid_ids' require 'vagrant-lxc/action/private_networks' -require 'vagrant-lxc/action/remove_temporary_files' require 'vagrant-lxc/action/setup_package_files' require 'vagrant-lxc/action/warn_networks' @@ -125,9 +124,6 @@ module Vagrant end b2.use ClearForwardedPorts - if env[:machine].state.id == :running - b2.use RemoveTemporaryFiles - end b2.use GcPrivateNetworkBridges b2.use Builtin::Call, Builtin::GracefulHalt, :stopped, :running do |env2, b3| if !env2[:result] diff --git a/lib/vagrant-lxc/action/boot.rb b/lib/vagrant-lxc/action/boot.rb index 90b783f..9741304 100644 --- a/lib/vagrant-lxc/action/boot.rb +++ b/lib/vagrant-lxc/action/boot.rb @@ -26,6 +26,11 @@ module Vagrant config.customize 'mount.entry', '/sys/fs/selinux sys/fs/selinux none bind,ro 0 0' end + if config.tmpfs_mount_size && !config.tmpfs_mount_size.empty? + # Make /tmp a tmpfs to prevent init scripts from nuking synced folders mounted in here + config.customize 'mount.entry', "tmpfs tmp tmpfs nodev,nosuid,size=#{config.tmpfs_mount_size} 0 0" + end + env[:ui].info I18n.t("vagrant_lxc.messages.starting") env[:machine].provider.driver.start(config.customizations) diff --git a/lib/vagrant-lxc/action/remove_temporary_files.rb b/lib/vagrant-lxc/action/remove_temporary_files.rb deleted file mode 100644 index 9fb0cc2..0000000 --- a/lib/vagrant-lxc/action/remove_temporary_files.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Vagrant - module LXC - module Action - class RemoveTemporaryFiles - def initialize(app, env) - @app = app - @logger = Log4r::Logger.new("vagrant::lxc::action::remove_tmp_files") - end - - def call(env) - @logger.debug 'Removing temporary files' - driver = env[:machine].provider.driver - # To prevent host-side data loss, it's important that all mounts under /tmp are unmounted - # before we proceed with the `rm -rf` operation. See #68 and #360. - driver.attach("findmnt -R /tmp -o TARGET --list --noheadings | xargs -L 1 --no-run-if-empty umount") - driver.attach("rm -rf /tmp/*") - - @app.call env - end - end - end - end -end diff --git a/lib/vagrant-lxc/config.rb b/lib/vagrant-lxc/config.rb index 7a387a3..2c45b73 100644 --- a/lib/vagrant-lxc/config.rb +++ b/lib/vagrant-lxc/config.rb @@ -18,6 +18,10 @@ module Vagrant # machine name, set this to :machine attr_accessor :container_name + # Size (as a string like '400M') of the tmpfs to mount at /tmp on boot. + # Set to false or nil to disable the tmpfs mount altogether. Defaults to '2G'. + attr_accessor :tmpfs_mount_size + attr_accessor :fetch_ip_tries def initialize @@ -25,6 +29,7 @@ module Vagrant @backingstore = UNSET_VALUE @backingstore_options = [] @container_name = UNSET_VALUE + @tmpfs_mount_size = UNSET_VALUE @fetch_ip_tries = UNSET_VALUE end @@ -52,6 +57,7 @@ module Vagrant @container_name = nil if @container_name == UNSET_VALUE @backingstore = "best" if @backingstore == UNSET_VALUE @existing_container_name = nil if @existing_container_name == UNSET_VALUE + @tmpfs_mount_size = '2G' if @tmpfs_mount_size == UNSET_VALUE @fetch_ip_tries = 10 if @fetch_ip_tries == UNSET_VALUE end end