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,25 +93,31 @@ 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 {
|
_, err = w.Write(mbr)
|
||||||
return exec.Command("resize2fs", device+partition).Run()
|
if err != nil {
|
||||||
}
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{}
|
err = ioctl.BlkRRPart(w.Fd())
|
||||||
for _, name := range []string{"partx", "partprobe", "kpartx"} {
|
w.Close()
|
||||||
if _, err = exec.LookPath(name); err == nil {
|
if err != nil {
|
||||||
switch name {
|
args := []string{}
|
||||||
case "partx":
|
for _, name := range []string{"partx", "partprobe", "kpartx"} {
|
||||||
args = []string{"-u", device}
|
if _, err = exec.LookPath(name); err == nil {
|
||||||
default:
|
switch name {
|
||||||
args = []string{device}
|
case "partx":
|
||||||
|
args = []string{"-u", device}
|
||||||
|
default:
|
||||||
|
args = []string{device}
|
||||||
|
}
|
||||||
|
log.Printf("update partition table via %s %s", name, strings.Join(args, " "))
|
||||||
|
if err = exec.Command(name, args...).Run(); err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.Printf("update partition table via %s %s", name, strings.Join(args, " "))
|
|
||||||
exec.Command(name, args...).Run()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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