diff --git a/builder/amazon/chroot/builder.go b/builder/amazon/chroot/builder.go index c940a7bfb..6647b769e 100644 --- a/builder/amazon/chroot/builder.go +++ b/builder/amazon/chroot/builder.go @@ -30,6 +30,7 @@ type Config struct { CopyFiles []string `mapstructure:"copy_files"` DevicePath string `mapstructure:"device_path"` MountCommand string `mapstructure:"mount_command"` + ChrootCommand string `mapstructure:"chroot_command"` MountPath string `mapstructure:"mount_path"` SourceAmi string `mapstructure:"source_ami"` UnmountCommand string `mapstructure:"unmount_command"` @@ -82,6 +83,10 @@ func (b *Builder) Prepare(raws ...interface{}) error { b.config.MountCommand = "mount" } + if b.config.ChrootCommand == "" { + b.config.ChrootCommand = "chroot" + } + if b.config.MountPath == "" { b.config.MountPath = "packer-amazon-chroot-volumes/{{.Device}}" } @@ -129,6 +134,7 @@ func (b *Builder) Prepare(raws ...interface{}) error { templates := map[string]*string{ "device_path": &b.config.DevicePath, "mount_command": &b.config.MountCommand, + "chroot_command": &b.config.ChrootCommand, "source_ami": &b.config.SourceAmi, "unmount_command": &b.config.UnmountCommand, } diff --git a/builder/amazon/chroot/communicator.go b/builder/amazon/chroot/communicator.go index 111adb42e..3e1e8deda 100644 --- a/builder/amazon/chroot/communicator.go +++ b/builder/amazon/chroot/communicator.go @@ -14,15 +14,12 @@ import ( // commands locally but within a chroot. type Communicator struct { Chroot string + ChrootCommand string } func (c *Communicator) Start(cmd *packer.RemoteCmd) error { - chrootCmdPath, err := exec.LookPath("chroot") - if err != nil { - return err - } - localCmd := exec.Command(chrootCmdPath, c.Chroot, "/bin/sh", "-c", cmd.Command) + localCmd := exec.Command(c.ChrootCommand, c.Chroot, "/bin/sh", "-c", cmd.Command) localCmd.Stdin = cmd.Stdin localCmd.Stdout = cmd.Stdout localCmd.Stderr = cmd.Stderr diff --git a/builder/amazon/chroot/step_chroot_provision.go b/builder/amazon/chroot/step_chroot_provision.go index 5ad87836d..b1a156216 100644 --- a/builder/amazon/chroot/step_chroot_provision.go +++ b/builder/amazon/chroot/step_chroot_provision.go @@ -14,11 +14,13 @@ type StepChrootProvision struct { func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction { hook := state.Get("hook").(packer.Hook) mountPath := state.Get("mount_path").(string) + chrootCommand := state.Get("chroot_command").(string) ui := state.Get("ui").(packer.Ui) // Create our communicator comm := &Communicator{ Chroot: mountPath, + ChrootCommand: chrootCommand, } // Provision