From cc13e6690cc642ddcb37796a704a7f4de1a51823 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 19 Nov 2013 12:50:33 -0800 Subject: [PATCH] builder/amazon/chroot: don't choose partition mount point if taken [GH-635] --- CHANGELOG.md | 2 ++ builder/amazon/chroot/device.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b83c4f5e..2e67b03e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ BUG FIXES: * builder/amazon/chroot: Copying empty directories works. [GH-588] * builder/amazon/chroot: Chroot commands work with shell provisioners. [GH-581] +* builder/amazon/chroot: Don't choose a mount point that is a partition of + an already mounted device. [GH-635] * builder/virtualbox: Ctrl-C interrupts during waiting for boot. [GH-618] * builder/vmware: VMX modifications are now case-insensitive. [GH-608] * builder/vmware: VMware Fusion won't ask for VM upgrade. diff --git a/builder/amazon/chroot/device.go b/builder/amazon/chroot/device.go index ed5be6194..77b7b444a 100644 --- a/builder/amazon/chroot/device.go +++ b/builder/amazon/chroot/device.go @@ -19,6 +19,14 @@ func AvailableDevice() (string, error) { letters := "fghijklmnop" for _, letter := range letters { + device := fmt.Sprintf("/dev/%s%c", prefix, letter) + + // If the block device itself, i.e. /dev/sf, exists, then we + // can't use any of the numbers either. + if _, err := os.Stat(device); err == nil { + continue + } + for i := 1; i < 16; i++ { device := fmt.Sprintf("/dev/%s%c%d", prefix, letter, i) if _, err := os.Stat(device); err != nil {