From 29cef0eae41f33e3d3b40a54b533768aee1c99be Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Tue, 23 Jun 2015 11:26:13 -0500 Subject: [PATCH 1/3] builder/amazon-chroot: add mount_options configuration option --- builder/amazon/chroot/builder.go | 5 ++++- builder/amazon/chroot/step_mount_device.go | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/builder/amazon/chroot/builder.go b/builder/amazon/chroot/builder.go index c5449a60a..636de8df7 100644 --- a/builder/amazon/chroot/builder.go +++ b/builder/amazon/chroot/builder.go @@ -35,6 +35,7 @@ type Config struct { MountPath string `mapstructure:"mount_path"` SourceAmi string `mapstructure:"source_ami"` RootVolumeSize int64 `mapstructure:"root_volume_size"` + MountOptions []string `mapstructure:"mount_options"` ctx interpolate.Context } @@ -165,7 +166,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe }, &StepAttachVolume{}, &StepEarlyUnflock{}, - &StepMountDevice{}, + &StepMountDevice{ + MountOptions: b.config.MountOptions, + }, &StepMountExtra{}, &StepCopyFiles{}, &StepChrootProvision{}, diff --git a/builder/amazon/chroot/step_mount_device.go b/builder/amazon/chroot/step_mount_device.go index cf10535df..8f7d27485 100644 --- a/builder/amazon/chroot/step_mount_device.go +++ b/builder/amazon/chroot/step_mount_device.go @@ -6,6 +6,7 @@ import ( "log" "os" "path/filepath" + "strings" "github.com/aws/aws-sdk-go/service/ec2" "github.com/mitchellh/multistep" @@ -23,7 +24,8 @@ type mountPathData struct { // mount_path string - The location where the volume was mounted. // mount_device_cleanup CleanupFunc - To perform early cleanup type StepMountDevice struct { - mountPath string + mountPath string + MountOptions []string } func (s *StepMountDevice) Run(state multistep.StateBag) multistep.StepAction { @@ -70,8 +72,15 @@ func (s *StepMountDevice) Run(state multistep.StateBag) multistep.StepAction { ui.Say("Mounting the root device...") stderr := new(bytes.Buffer) + + // build mount options from mount_options config, usefull for nouuid options + // or other specific device type settings for mount + opts := "" + if len(s.MountOptions) > 0 { + opts = "-o " + strings.Join(s.MountOptions, " -o ") + } mountCommand, err := wrappedCommand( - fmt.Sprintf("mount %s %s", deviceMount, mountPath)) + fmt.Sprintf("mount %s %s %s", opts, deviceMount, mountPath)) if err != nil { err := fmt.Errorf("Error creating mount command: %s", err) state.Put("error", err) From 24106de3780ddb1dddf8b4a76809460329dcde54 Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Tue, 23 Jun 2015 11:31:43 -0500 Subject: [PATCH 2/3] builder/amazon-chroot: document mount_options config --- website/source/docs/builders/amazon-chroot.html.markdown | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/website/source/docs/builders/amazon-chroot.html.markdown b/website/source/docs/builders/amazon-chroot.html.markdown index 60b6eb008..e0553ef7a 100644 --- a/website/source/docs/builders/amazon-chroot.html.markdown +++ b/website/source/docs/builders/amazon-chroot.html.markdown @@ -133,6 +133,12 @@ AMI if one with the same name already exists. Default `false`. template where the `.Device` variable is replaced with the name of the device where the volume is attached. +* `mount_options` (array of strings) – Options to supply the `mount` command +when mounting devices. Each option will be prefixed with `-o ` and supplied to +the `mount` command ran by Packer. Because this command is ran in a shell, user +discrestion is advised. See [this manual page for the mount command][1] for valid +file system specific options + * `root_volume_size` (integer) – The size of the root volume for the chroot environment, and the resulting AMI @@ -225,3 +231,6 @@ prevent packages installed by your provisioners from starting services: ] } ``` + + +[1]: http://linuxcommand.org/man_pages/mount8.html From 3a54e6899ded7f6db6ff5bce27f44e2f472d5cf3 Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Tue, 23 Jun 2015 11:34:42 -0500 Subject: [PATCH 3/3] code cleanup --- builder/amazon/chroot/step_mount_device.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builder/amazon/chroot/step_mount_device.go b/builder/amazon/chroot/step_mount_device.go index 8f7d27485..cb022e36c 100644 --- a/builder/amazon/chroot/step_mount_device.go +++ b/builder/amazon/chroot/step_mount_device.go @@ -24,8 +24,9 @@ type mountPathData struct { // mount_path string - The location where the volume was mounted. // mount_device_cleanup CleanupFunc - To perform early cleanup type StepMountDevice struct { - mountPath string MountOptions []string + + mountPath string } func (s *StepMountDevice) Run(state multistep.StateBag) multistep.StepAction {