fix(host-deployer): add growpart resize partitions (#19252)

This commit is contained in:
wanyaoqi
2024-01-15 12:14:51 +08:00
committed by GitHub
parent a96158ee74
commit b78db4e029
5 changed files with 20 additions and 46 deletions
+1 -8
View File
@@ -1,16 +1,9 @@
FROM registry.cn-beijing.aliyuncs.com/yunionio/yunionos:v3.10.8-20231215.0-vm as yunionos
FROM registry.cn-beijing.aliyuncs.com/yunionio/host-deployer-base:1.4.3
FROM registry.cn-beijing.aliyuncs.com/yunionio/host-deployer-base:1.4.4
MAINTAINER "Yaoqi Wan wanyaoqi@yunionyun.com"
ENV TZ UTC
RUN mkdir -p /opt/yunion/bin
RUN mkdir -p /yunionos/x86_64
RUN mkdir -p /yunionos/aarch64
COPY --from=yunionos /yunionos/x86_64/initramfs /yunionos/x86_64/initramfs
COPY --from=yunionos /yunionos/x86_64/kernel /yunionos/x86_64/kernel
COPY --from=yunionos /yunionos/aarch64/kernel /yunionos/aarch64/kernel
COPY --from=yunionos /yunionos/aarch64/initramfs /yunionos/aarch64/initramfs
ADD ./_output/centos-build/bin/host-deployer /opt/yunion/bin/host-deployer
+4 -20
View File
@@ -18,7 +18,6 @@ import (
"fmt"
"io"
"io/ioutil"
"path"
"regexp"
"strconv"
"strings"
@@ -140,7 +139,6 @@ func ResizeDiskFs(diskPath string, sizeMb int) error {
}
parts, label := ParseDiskPartition(diskPath, strings.Split(string(lines), "\n"))
log.Infof("Parts: %v label: %s", parts, label)
maxSector := GetDevSector512Count(path.Base(diskPath))
if label == "gpt" {
proc := procutils.NewCommand("gdisk", diskPath)
stdin, err := proc.StdinPipe()
@@ -188,26 +186,12 @@ func ResizeDiskFs(diskPath string, sizeMb int) error {
}
if len(parts) > 0 && (label == "gpt" ||
(label == "msdos" && parts[len(parts)-1][5] == "primary")) {
var (
part = parts[len(parts)-1]
end int
)
if sizeMb > 0 {
end = sizeMb * 1024 * 2
} else if label == "gpt" {
end = maxSector - 35
} else {
end = maxSector - 1
}
if label == "msdos" && end >= 4294967296 {
end = 4294967295
}
var part = parts[len(parts)-1]
if IsSupportResizeFs(part[6]) {
cmds := []string{"parted", "-a", "none", "-s", diskPath, "--", "resizepart", part[0], fmt.Sprintf("%ds", end)}
log.Infof("resize disk partition: %s", cmds)
output, err := procutils.NewCommand(cmds[0], cmds[1:]...).Output()
// growpart script replace parted resizepart
output, err := procutils.NewCommand("growpart", diskPath, part[0]).Output()
if err != nil {
return errors.Wrapf(err, "parted failed %s", output)
return errors.Wrapf(err, "growpart failed %s", output)
}
err, _ = ResizePartitionFs(part[7], part[6], false)
if err != nil {
@@ -344,25 +344,21 @@ func (s *SDeployService) PrepareEnv() error {
}
} else {
// prepare for yunionos don't have but necessary files
out, err := procutils.NewCommand("cp", "-rf", "/usr/bin/chntpw.static", "/opt/yunion/bin/chntpw.static").Output()
out, err := procutils.NewCommand("mkdir", "-p", "/opt/yunion/bin/bundles").Output()
if err != nil {
return errors.Wrapf(err, "cp files failed %s", out)
}
out, err = procutils.NewCommand("cp", "-rf", "/usr/bin/.chntpw.static.bin", "/opt/yunion/bin/.chntpw.static.bin").Output()
if err != nil {
return errors.Wrapf(err, "cp files failed %s", out)
}
out, err = procutils.NewCommand("mkdir", "-p", "/opt/yunion/bin/bundles").Output()
if err != nil {
return errors.Wrapf(err, "cp files failed %s", out)
}
out, err = procutils.NewCommand("cp", "-rf", "/usr/bin/bundles/chntpw.static", "/opt/yunion/bin/bundles/chntpw.static").Output()
if err != nil {
return errors.Wrapf(err, "cp files failed %s", out)
}
out, err = procutils.NewCommand("cp", "-rf", "/usr/sbin/zerofree", "/opt/yunion/bin/zerofree").Output()
if err != nil {
return errors.Wrapf(err, "cp files failed %s", out)
for k, v := range map[string]string{
"/usr/bin/chntpw.static": "/opt/yunion/bin/chntpw.static",
"/usr/bin/.chntpw.static.bin": "/opt/yunion/bin/.chntpw.static.bin",
"/usr/bin/bundles/chntpw.static": "/opt/yunion/bin/bundles/chntpw.static",
"/usr/bin/growpart": "/opt/yunion/bin/growpart",
"/usr/sbin/zerofree": "/opt/yunion/bin/zerofree",
} {
out, err = procutils.NewCommand("cp", "-rf", k, v).Output()
if err != nil {
return errors.Wrapf(err, "cp files failed %s", out)
}
}
{
@@ -106,7 +106,7 @@ func LocalInitEnv() error {
"/sbin",
"/usr/bin",
"/usr/sbin",
"/opt/yunion/bin", // for zerofree command
"/opt/yunion/bin", // for zerofree and growpart command
}
err := os.Setenv("PATH", strings.Join(paths, ":"))
if err != nil {
+2 -1
View File
@@ -133,7 +133,8 @@ func (d *SRBDDisk) Resize(ctx context.Context, params interface{}) (jsonutils.JS
Path: d.GetPath(),
}
if err := d.ResizeFs(resizeFsInfo); err != nil {
return nil, errors.Wrapf(err, "resize fs %s", d.GetPath())
log.Errorf("Resize fs %s fail %s", d.GetPath(), err)
// return nil, errors.Wrapf(err, "resize fs %s", d.GetPath())
}
return d.GetDiskDesc(), nil