Don’t resize dos partition if no free space is available

Signed-off-by: Guillaume Rose <guillaume.rose@docker.com>
This commit is contained in:
Guillaume Rose 2019-06-08 22:57:37 +02:00
parent 518220ee44
commit 0fb16ac8b0

View File

@ -11,6 +11,7 @@ import (
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"syscall"
"time"
@ -87,6 +88,20 @@ func extend(d, fsType string) error {
log.Printf("No free space on device to extend partition")
return nil
}
if f.PartitionTable.Label == "dos" {
out, err := exec.Command("blockdev", "--getsz", d).Output()
if err != nil {
return fmt.Errorf("Unable to get total size of %s: %v", d, err)
}
totalSize, err := strconv.Atoi(strings.TrimSpace(string(out)))
if err != nil {
return fmt.Errorf("Unable to convert total size from string to int: %v", err)
}
if partition.Start+partition.Size == totalSize {
log.Printf("No free space on device to extend partition")
return nil
}
}
switch fsType {
case "ext4":