Add mount_partition to amazon-chroot builder to specify a partition other than 1

This commit is contained in:
Kimo Rosenbaum 2016-01-06 11:35:01 -08:00
parent d507b18eb4
commit 09543fc4e7
3 changed files with 13 additions and 3 deletions

View File

@ -37,6 +37,7 @@ type Config struct {
SourceAmi string `mapstructure:"source_ami"` SourceAmi string `mapstructure:"source_ami"`
RootVolumeSize int64 `mapstructure:"root_volume_size"` RootVolumeSize int64 `mapstructure:"root_volume_size"`
MountOptions []string `mapstructure:"mount_options"` MountOptions []string `mapstructure:"mount_options"`
MountPartition int `mapstructure:"mount_partition"`
ctx interpolate.Context ctx interpolate.Context
} }
@ -97,6 +98,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.MountPath = "/mnt/packer-amazon-chroot-volumes/{{.Device}}" b.config.MountPath = "/mnt/packer-amazon-chroot-volumes/{{.Device}}"
} }
if b.config.MountPartition == 0 {
b.config.MountPartition = 1
}
// Accumulate any errors // Accumulate any errors
var errs *packer.MultiError var errs *packer.MultiError
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(&b.config.ctx)...) errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(&b.config.ctx)...)
@ -170,6 +175,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&StepEarlyUnflock{}, &StepEarlyUnflock{},
&StepMountDevice{ &StepMountDevice{
MountOptions: b.config.MountOptions, MountOptions: b.config.MountOptions,
MountPartition: b.config.MountPartition,
}, },
&StepMountExtra{}, &StepMountExtra{},
&StepCopyFiles{}, &StepCopyFiles{},

View File

@ -25,6 +25,7 @@ type mountPathData struct {
// mount_device_cleanup CleanupFunc - To perform early cleanup // mount_device_cleanup CleanupFunc - To perform early cleanup
type StepMountDevice struct { type StepMountDevice struct {
MountOptions []string MountOptions []string
MountPartition int
mountPath string mountPath string
} }
@ -67,7 +68,7 @@ func (s *StepMountDevice) Run(state multistep.StateBag) multistep.StepAction {
log.Printf("Source image virtualization type is: %s", *image.VirtualizationType) log.Printf("Source image virtualization type is: %s", *image.VirtualizationType)
deviceMount := device deviceMount := device
if *image.VirtualizationType == "hvm" { if *image.VirtualizationType == "hvm" {
deviceMount = fmt.Sprintf("%s%d", device, 1) deviceMount = fmt.Sprintf("%s%d", device, s.MountPartition)
} }
state.Put("deviceMount", deviceMount) state.Put("deviceMount", deviceMount)

View File

@ -133,6 +133,9 @@ builder.
where the `.Device` variable is replaced with the name of the device where where the `.Device` variable is replaced with the name of the device where
the volume is attached. the volume is attached.
- `mount_partition` (integer) - The partition number containing the /
partition. By default this is the first partition of the volume.
- `mount_options` (array of strings) - Options to supply the `mount` command - `mount_options` (array of strings) - Options to supply the `mount` command
when mounting devices. Each option will be prefixed with `-o` and supplied 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 to the `mount` command ran by Packer. Because this command is ran in a