Skip to content

Commit

Permalink
allow creation of lvs with all remaining free space (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 authored Sep 10, 2021
1 parent 509806c commit f66e2ab
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
35 changes: 35 additions & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func (h *Hammer) install(prefix string, machine *models.ModelsV1MachineResponse,
return nil, fmt.Errorf("writing userdata failed %w", err)
}

err = h.writeLVMLocalConf()
if err != nil {
return nil, err
}

log.Info("running /install.sh on", "prefix", prefix)
err = os.Chdir(prefix)
if err != nil {
Expand Down Expand Up @@ -159,6 +164,36 @@ func (h *Hammer) install(prefix string, machine *models.ModelsV1MachineResponse,
return info, nil
}

// writeLVMLocalConf to make lvm more compatible with os without udevd
// will only be written if lvm is installed in the target image
func (h *Hammer) writeLVMLocalConf() error {
srclvmlocal := "/etc/lvm/lvmlocal.conf"
dstlvm := path.Join(h.ChrootPrefix, "/etc/lvm")
dstlvmlocal := path.Join(h.ChrootPrefix, srclvmlocal)

_, err := os.Stat(srclvmlocal)
if os.IsNotExist(err) {
log.Info("src lvmlocal.conf not present, not creating lvmlocal.conf")
return nil
}
_, err = os.Stat(dstlvm)
if os.IsNotExist(err) {
log.Info("dst /etc/lvm not present, not creating lvmlocal.conf")
return nil
}

input, err := os.ReadFile(srclvmlocal)
if err != nil {
return fmt.Errorf("unable to read lvmlocal.conf %w", err)
}

err = os.WriteFile(dstlvmlocal, input, 0600)
if err != nil {
return fmt.Errorf("unable to write lvmlocal.conf %w", err)
}
return nil
}

func (h *Hammer) writeUserData(machine *models.ModelsV1MachineResponse) error {
configdir := path.Join(h.ChrootPrefix, "etc", "metal")
destination := path.Join(configdir, "userdata")
Expand Down
14 changes: 12 additions & 2 deletions cmd/storage/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,21 @@ func (f *Filesystem) createLogicalVolumes() error {
if lvExists(*lv.Volumegroup, *lv.Name) {
continue
}
if lv.Size == nil {
continue
}

args := []string{
"lvcreate",
"--verbose",
"--name", *lv.Name,
"--wipesignatures", "y",
"--size", fmt.Sprintf("%dm", *lv.Size),
}

if *lv.Size > int64(0) {
args = append(args, "--size", fmt.Sprintf("%dm", *lv.Size))
} else {
args = append(args, "--extents", "100%FREE")
}

lvmtype := "linear"
Expand All @@ -252,6 +260,7 @@ func (f *Filesystem) createLogicalVolumes() error {
}
args = append(args, *lv.Volumegroup)

log.Info("lvcreate", "args", args)
err := os.ExecuteCommand(command.LVM, args...)
if err != nil {
log.Error("lvcreate", "error", err)
Expand Down Expand Up @@ -384,7 +393,8 @@ var (
{source: "sys", target: "/sys", fstype: "sysfs", flags: 0, data: ""},
{source: "efivarfs", target: "/sys/firmware/efi/efivars", fstype: "efivarfs", flags: 0, data: ""},
{source: "tmpfs", target: "/tmp", fstype: "tmpfs", flags: 0, data: ""},
// /dev is a bind mount, a bind mount must have MS_BIND flags set see man 2 mount
// /dev and /run are bind mounts, a bind mount must have MS_BIND flags set see man 2 mount
{source: "/run", target: "/run", fstype: "", flags: syscall.MS_BIND, data: ""},
{source: "/dev", target: "/dev", fstype: "", flags: syscall.MS_BIND, data: ""},
}
)
Expand Down

0 comments on commit f66e2ab

Please sign in to comment.