diff --git a/actions/rootio/v1/Dockerfile b/actions/rootio/v1/Dockerfile index e70bda9..1515ca1 100644 --- a/actions/rootio/v1/Dockerfile +++ b/actions/rootio/v1/Dockerfile @@ -34,12 +34,16 @@ WORKDIR /dosfstools/ RUN ./autogen.sh; ./configure RUN make LDFLAGS="--static" +# build lvm2 as static +FROM alpine as lvm +RUN apk update && apk add lvm2-static=2.03.21-r3 + # Build final image -FROM alpine -RUN apk add lvm2 +FROM scratch COPY --from=mke2fs /e2fsprogs-1.45.6/misc/mke2fs.static /sbin/mke2fs COPY --from=swap util-linux/swapon /sbin/swapon COPY --from=swap util-linux/mkswap /sbin/mkswap COPY --from=fattools dosfstools/src/mkfs.fat /sbin/mkfs.fat +COPY --from=lvm /usr/sbin/lvm.static /sbin/lvm COPY --from=rootio /go/src/github.com/thebsdbox/rootio/rootio . ENTRYPOINT ["/rootio"] diff --git a/actions/rootio/v1/cmd/rootio.go b/actions/rootio/v1/cmd/rootio.go index e3dc655..4835a88 100644 --- a/actions/rootio/v1/cmd/rootio.go +++ b/actions/rootio/v1/cmd/rootio.go @@ -113,15 +113,15 @@ var rootioPartition = &cobra.Command{ if err != nil { log.Error(err) } + } - if len(metadata.Instance.Storage.VolumeGroups) > 0 { - log.Infoln("Creating Volume Groups") - } + if len(metadata.Instance.Storage.VolumeGroups) > 0 { + log.Infoln("Creating Volume Groups") + } - for _, vg := range metadata.Instance.Storage.VolumeGroups { - if err := storage.CreateVolumeGroup(vg); err != nil { - log.Error(err) - } + for _, vg := range metadata.Instance.Storage.VolumeGroups { + if err := storage.CreateVolumeGroup(vg); err != nil { + log.Error(err) } } }, diff --git a/actions/rootio/v1/pkg/lvm/lvm.go b/actions/rootio/v1/pkg/lvm/lvm.go index 99f892b..2dc236a 100644 --- a/actions/rootio/v1/pkg/lvm/lvm.go +++ b/actions/rootio/v1/pkg/lvm/lvm.go @@ -20,7 +20,7 @@ type VolumeGroup struct { // CreatePhysicalVolume creates a physical volume of the given device. func CreatePhysicalVolume(dev string) error { - if err := run("pvcreate", dev); err != nil { + if err := run("lvm", "pvcreate", dev); err != nil { return fmt.Errorf("lvm: CreatePhysicalVolume: %v", err) } return nil @@ -30,22 +30,22 @@ func CreatePhysicalVolume(dev string) error { // device at `dev` and adds it to the LVM metadata cache if `lvmetad` // is running. If `dev` is an empty string, it scans all devices. func PVScan(dev string) error { - args := []string{"--cache"} + args := []string{"pvscan", "--cache"} if dev != "" { args = append(args, dev) } - return run("pvscan", args...) + return run("lvm", args...) } // VGScan runs the `vgscan --cache ` command. It scans for the // volume group and adds it to the LVM metadata cache if `lvmetad` // is running. If `name` is an empty string, it scans all volume groups. func VGScan(name string) error { - args := []string{"--cache"} + args := []string{"vgscan", "--cache"} if name != "" { args = append(args, name) } - return run("vgscan", args...) + return run("lvm", args...) } // ValidateVolumeGroupName validates a volume group name. A valid volume group @@ -77,7 +77,7 @@ func ValidateTag(tag string) error { // CreateVolumeGroup creates a new volume group. func CreateVolumeGroup(name string, pvs []string, tags []string) (*VolumeGroup, error) { - var args []string + args := []string{"vgcreate"} if err := ValidateVolumeGroupName(name); err != nil { return nil, err @@ -97,7 +97,7 @@ func CreateVolumeGroup(name string, pvs []string, tags []string) (*VolumeGroup, args = append(args, pv) } - if err := run("vgcreate", args...); err != nil { + if err := run("lvm", args...); err != nil { return nil, err } @@ -137,7 +137,7 @@ func (vg *VolumeGroup) CreateLogicalVolume(name string, sizeInBytes uint64, tags } // Validate the tag. - var args []string + args := []string{"lvcreate"} for _, tag := range tags { if tag != "" { if err := ValidateTag(tag); err != nil { @@ -146,12 +146,18 @@ func (vg *VolumeGroup) CreateLogicalVolume(name string, sizeInBytes uint64, tags args = append(args, "--add-tag="+tag) } } - args = append(args, fmt.Sprintf("--size=%db", sizeInBytes)) + + if sizeInBytes == 0 { + args = append(args, "-l", "100%FREE") + } else { + args = append(args, fmt.Sprintf("--size=%db", sizeInBytes)) + } + args = append(args, "--name="+name) args = append(args, vg.name) args = append(args, opts...) - if err := run("lvcreate", args...); err != nil { + if err := run("lvm", args...); err != nil { if isInsufficientSpace(err) { return fmt.Errorf("lvm: not enough free space") }