allow user to mount entire block device in chroot builder

This commit is contained in:
Megan Marsh 2018-04-25 10:47:52 -07:00
parent 148f7d39e4
commit 59e3ec722d
3 changed files with 13 additions and 10 deletions

View File

@ -35,7 +35,7 @@ type Config struct {
DevicePath string `mapstructure:"device_path"` DevicePath string `mapstructure:"device_path"`
FromScratch bool `mapstructure:"from_scratch"` FromScratch bool `mapstructure:"from_scratch"`
MountOptions []string `mapstructure:"mount_options"` MountOptions []string `mapstructure:"mount_options"`
MountPartition int `mapstructure:"mount_partition"` MountPartition string `mapstructure:"mount_partition"`
MountPath string `mapstructure:"mount_path"` MountPath string `mapstructure:"mount_path"`
PostMountCommands []string `mapstructure:"post_mount_commands"` PostMountCommands []string `mapstructure:"post_mount_commands"`
PreMountCommands []string `mapstructure:"pre_mount_commands"` PreMountCommands []string `mapstructure:"pre_mount_commands"`
@ -112,8 +112,8 @@ 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 { if b.config.MountPartition == "" {
b.config.MountPartition = 1 b.config.MountPartition = "1"
} }
// Accumulate any errors or warnings // Accumulate any errors or warnings

View File

@ -26,7 +26,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 MountPartition string
mountPath string mountPath string
} }
@ -75,8 +75,9 @@ func (s *StepMountDevice) Run(_ context.Context, state multistep.StateBag) multi
} }
deviceMount := device deviceMount := device
if virtualizationType == "hvm" {
deviceMount = fmt.Sprintf("%s%d", device, s.MountPartition) if virtualizationType == "hvm" && s.MountPartition != "0" {
deviceMount = fmt.Sprintf("%s%s", device, s.MountPartition)
} }
state.Put("deviceMount", deviceMount) state.Put("deviceMount", deviceMount)

View File

@ -213,8 +213,10 @@ each category, the available configuration keys are alphabetized.
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` (number) - The partition number containing the - `mount_partition` (string) - The partition number containing the
/ partition. By default this is the first partition of the volume. / partition. By default this is the first partition of the volume, (for
example, `xvda1`) but you can designate the entire block device by setting
`"mount_partition": "0"` in your config, which will mount `xvda` instead.
- `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