Skip to content

Commit be364d2

Browse files
committed
Add snapshotter.type flag to build-disk command
When building a disk image we do not specify the snapshotter, which configures the expansion mechanism to set COS_STATE partition filesystem to ext4. The green flavor uses the btrfs snapshotter, which means when it boots and tries to mount the COS_STATE partition it expects a btrfs filesystem, but finds an ext4 one, which errors. In this commit we add the --snapshotter.type flag to the build-disk command and set the snapshotter in the Makefile accordingly. Signed-off-by: Fredrik Lönnegren <[email protected]>
1 parent 0ecba2f commit be364d2

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ BASE_OS_IMAGE?=registry.opensuse.org/opensuse/tumbleweed
1818
BASE_OS_VERSION?=latest
1919
DOCKER_SOCK?=/var/run/docker.sock
2020

21+
SNAPSHOTTER_TYPE?=loopdevice
22+
ifeq ("$(FLAVOR)","green")
23+
SNAPSHOTTER_TYPE=btrfs
24+
endif
25+
2126
GIT_COMMIT?=$(shell git rev-parse HEAD)
2227
GIT_COMMIT_SHORT?=$(shell git rev-parse --short HEAD)
2328
GIT_TAG?=$(shell git describe --candidates=50 --abbrev=0 --tags 2>/dev/null || echo "v0.0.1" )
@@ -98,7 +103,8 @@ build-disk:
98103
mkdir -p $(ROOT_DIR)/build
99104
$(DOCKER) run --rm -v $(DOCKER_SOCK):$(DOCKER_SOCK) -v $(ROOT_DIR)/build:/build -v $(ROOT_DIR)/tests/assets:/assets \
100105
--entrypoint /usr/bin/elemental $(TOOLKIT_REPO):$(VERSION) --debug build-disk --platform $(PLATFORM) \
101-
--expandable -n elemental-$(FLAVOR).$(ARCH) --local --cloud-init /assets/remote_login.yaml -o /build --system $(REPO):$(VERSION)
106+
--expandable -n elemental-$(FLAVOR).$(ARCH) --local --cloud-init /assets/remote_login.yaml -o /build --system $(REPO):$(VERSION) \
107+
--snapshotter.type $(SNAPSHOTTER_TYPE)
102108
qemu-img convert -O qcow2 $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).raw $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).qcow2
103109
qemu-img resize $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).qcow2 $(DISKSIZE)
104110

cmd/build-disk.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func NewBuildDisk(root *cobra.Command, addCheckRoot bool) *cobra.Command {
110110
addLocalImageFlag(c)
111111
addSquashFsCompressionFlags(c)
112112
addCosignFlags(c)
113+
addSnapshotterFlags(c)
113114
return c
114115
}
115116

cmd/flags.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/spf13/cobra"
2626
"github.com/spf13/pflag"
2727

28+
"github.com/rancher/elemental-toolkit/v2/pkg/constants"
2829
"github.com/rancher/elemental-toolkit/v2/pkg/types"
2930
)
3031

@@ -85,6 +86,15 @@ func addLocalImageFlag(cmd *cobra.Command) {
8586
cmd.Flags().Bool("local", false, "Use an image from local cache")
8687
}
8788

89+
func addSnapshotterFlags(cmd *cobra.Command) {
90+
snapshotterType := newEnumFlag(
91+
[]string{constants.LoopDeviceSnapshotterType, constants.BtrfsSnapshotterType},
92+
constants.LoopDeviceSnapshotterType,
93+
)
94+
95+
cmd.Flags().Var(snapshotterType, "snapshotter.type", "Sets the snapshotter type to install")
96+
}
97+
8898
// addVerifyRegistryFlag add local image flag shared between install, pull-image, upgrade
8999
func addTLSVerifyFlag(cmd *cobra.Command) {
90100
cmd.Flags().Bool("tls-verify", true, "Require HTTPS and verify certificates of registries (default: true)")

cmd/install.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ func NewInstallCmd(root *cobra.Command, addCheckRoot bool) *cobra.Command {
9999
}
100100
firmType := newEnumFlag([]string{types.EFI}, types.EFI)
101101
pTableType := newEnumFlag([]string{types.GPT}, types.GPT)
102-
snapshotterType := newEnumFlag(
103-
[]string{constants.LoopDeviceSnapshotterType, constants.BtrfsSnapshotterType},
104-
constants.LoopDeviceSnapshotterType,
105-
)
106102

107103
root.AddCommand(c)
108104
c.Flags().StringSliceP("cloud-init", "c", []string{}, "Cloud-init config files")
@@ -118,11 +114,11 @@ func NewInstallCmd(root *cobra.Command, addCheckRoot bool) *cobra.Command {
118114
c.Flags().Bool("force", false, "Force install")
119115
c.Flags().Bool("eject-cd", false, "Try to eject the cd on reboot, only valid if booting from iso")
120116
c.Flags().Bool("disable-boot-entry", false, "Dont create an EFI entry for the system install.")
121-
c.Flags().Var(snapshotterType, "snapshotter.type", "Sets the snapshotter type to install")
122117
c.Flags().StringSlice("cloud-init-paths", []string{}, "Cloud-init config files to run during install")
123118
addSharedInstallUpgradeFlags(c)
124119
addLocalImageFlag(c)
125120
addPlatformFlags(c)
121+
addSnapshotterFlags(c)
126122
return c
127123
}
128124

pkg/config/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,14 @@ func NewDisk(cfg *types.BuildConfig) *types.DiskSpec {
555555
)+mountSuffix,
556556
)
557557

558+
partitions := NewDiskElementalPartitions(workdir)
559+
560+
if cfg.Snapshotter.Type == constants.BtrfsSnapshotterType {
561+
partitions.State.FS = constants.Btrfs
562+
}
563+
558564
return &types.DiskSpec{
559-
Partitions: NewDiskElementalPartitions(workdir),
565+
Partitions: partitions,
560566
GrubConf: filepath.Join(constants.GrubCfgPath, constants.GrubCfg),
561567
System: types.NewEmptySrc(),
562568
RecoverySystem: recoveryImg,

0 commit comments

Comments
 (0)