fix partition resize
Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
parent
616b356754
commit
81de7a1151
@ -41,6 +41,17 @@ func ResizeRootFS() error {
|
|||||||
partstart := "2048"
|
partstart := "2048"
|
||||||
device := mountpoint[:len(mountpoint)-1]
|
device := mountpoint[:len(mountpoint)-1]
|
||||||
partition := mountpoint[len(mountpoint)-1:]
|
partition := mountpoint[len(mountpoint)-1:]
|
||||||
|
mbr := make([]byte, 446)
|
||||||
|
|
||||||
|
f, err := os.OpenFile(device, os.O_RDONLY, os.FileMode(0400))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = io.ReadFull(f, mbr)
|
||||||
|
f.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
cmd := exec.Command("fdisk", "-l", "-u", device)
|
cmd := exec.Command("fdisk", "-l", "-u", device)
|
||||||
stdout, err = cmd.StdoutPipe()
|
stdout, err = cmd.StdoutPipe()
|
||||||
@ -82,14 +93,17 @@ func ResizeRootFS() error {
|
|||||||
stdin.Reset()
|
stdin.Reset()
|
||||||
|
|
||||||
w, err := os.OpenFile(device, os.O_WRONLY, 0600)
|
w, err := os.OpenFile(device, os.O_WRONLY, 0600)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
defer w.Close()
|
return err
|
||||||
err = ioctl.BlkRRPart(w.Fd())
|
|
||||||
if err == nil {
|
|
||||||
return exec.Command("resize2fs", device+partition).Run()
|
|
||||||
}
|
}
|
||||||
|
_, err = w.Write(mbr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = ioctl.BlkRRPart(w.Fd())
|
||||||
|
w.Close()
|
||||||
|
if err != nil {
|
||||||
args := []string{}
|
args := []string{}
|
||||||
for _, name := range []string{"partx", "partprobe", "kpartx"} {
|
for _, name := range []string{"partx", "partprobe", "kpartx"} {
|
||||||
if _, err = exec.LookPath(name); err == nil {
|
if _, err = exec.LookPath(name); err == nil {
|
||||||
@ -100,7 +114,10 @@ func ResizeRootFS() error {
|
|||||||
args = []string{device}
|
args = []string{device}
|
||||||
}
|
}
|
||||||
log.Printf("update partition table via %s %s", name, strings.Join(args, " "))
|
log.Printf("update partition table via %s %s", name, strings.Join(args, " "))
|
||||||
exec.Command(name, args...).Run()
|
if err = exec.Command(name, args...).Run(); err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Printf("resize filesystem via %s %s", "resize2fs", device+partition)
|
log.Printf("resize filesystem via %s %s", "resize2fs", device+partition)
|
||||||
@ -108,10 +125,5 @@ func ResizeRootFS() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, name := range []string{"grub-install", "grub2-install"} {
|
return nil
|
||||||
if _, err = exec.LookPath(name); err == nil {
|
|
||||||
log.Printf("reinstall grub %s %s", name, device)
|
|
||||||
exec.Command(name, device).Run()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user