fix for various fdisk versions

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
Василий Толстов 2015-07-13 15:47:20 +03:00
parent 28db10bbf3
commit 732ff09ccd

View File

@ -111,7 +111,7 @@ func ResizeRootFS() error {
if err = syscall.Mknod(device, uint32(os.ModeDevice|syscall.S_IFBLK|0600), devBlk.Int()); err != nil { if err = syscall.Mknod(device, uint32(os.ModeDevice|syscall.S_IFBLK|0600), devBlk.Int()); err != nil {
return err return err
} }
defer os.Remove(device) // defer os.Remove(device)
// mbr := make([]byte, 446) // mbr := make([]byte, 446)
/* /*
@ -151,30 +151,47 @@ func ResizeRootFS() error {
if ps[1] == "*" { if ps[1] == "*" {
active = true active = true
partstart, _ = strconv.Atoi(ps[2]) partstart, _ = strconv.Atoi(ps[2])
if len(ps) > 7 {
parttype = ps[6] parttype = ps[6]
if ps[7] == "Extended" { if ps[7] == "Extended" {
extended = true extended = true
} }
} else { } else {
active = false
partstart, _ = strconv.Atoi(ps[1])
parttype = ps[5] parttype = ps[5]
if ps[6] == "Extended" { if ps[6] == "Extended" {
extended = true extended = true
} }
} }
} else {
active = false
partstart, _ = strconv.Atoi(ps[1])
if len(ps) > 6 {
parttype = ps[5]
if ps[6] == "Extended" {
extended = true
}
} else {
parttype = ps[4]
if ps[5] == "Extended" {
extended = true
}
}
}
} }
} }
if err = cmd.Wait(); err != nil || partstart == 0 { if err = cmd.Wait(); err != nil || partstart == 0 {
return fmt.Errorf("failed to open %s via fdisk 4\n", device) return fmt.Errorf("failed to open %s via fdisk 4\n", device)
} }
if partnum > 1 {
stdin.Write([]byte("d\n" + fmt.Sprintf("%d", partnum) + "\n")) stdin.Write([]byte("d\n" + fmt.Sprintf("%d", partnum) + "\n"))
} else {
stdin.Write([]byte("d\n"))
}
if extended { if extended {
stdin.Write([]byte("n\nl\n" + fmt.Sprintf("%d", partnum) + "\n" + fmt.Sprintf("%d", partstart) + "\n\n")) stdin.Write([]byte("n\nl\n" + fmt.Sprintf("%d", partnum) + "\n" + fmt.Sprintf("%d", partstart) + "\n\n"))
} else { } else {
stdin.Write([]byte("n\np\n" + fmt.Sprintf("%d", partnum) + "\n\n")) stdin.Write([]byte("n\np\n" + fmt.Sprintf("%d", partnum) + "\n" + fmt.Sprintf("%d", partstart) + "\n\n"))
} }
if active { if active {
stdin.Write([]byte("a\n" + fmt.Sprintf("%d", partnum) + "\n")) stdin.Write([]byte("a\n" + fmt.Sprintf("%d", partnum) + "\n"))
@ -225,7 +242,7 @@ func ResizeRootFS() error {
if err = syscall.Mknod(partition, uint32(os.ModeDevice|syscall.S_IFBLK|0600), devFs.Int()); err != nil { if err = syscall.Mknod(partition, uint32(os.ModeDevice|syscall.S_IFBLK|0600), devFs.Int()); err != nil {
return err return err
} }
defer os.Remove(partition) // defer os.Remove(partition)
log.Printf("resize filesystem via %s %s", "resize2fs", partition) log.Printf("resize filesystem via %s %s", "resize2fs", partition)
buf, err := exec.Command("resize2fs", partition).CombinedOutput() buf, err := exec.Command("resize2fs", partition).CombinedOutput()
if err != nil { if err != nil {