diff --git a/builder.go b/builder.go index 2aefb03..4e56cde 100644 --- a/builder.go +++ b/builder.go @@ -44,25 +44,25 @@ ff02::3 ip6-allhosts SAY Now booting the kernel from SYSLINUX... LABEL linux KERNEL /boot/vmlinuz - APPEND ro root=UUID=%s initrd=/boot/initrd.img net.ifnames=0 console=tty0 console=ttyS0,115200n8 + APPEND ro root=UUID=%s initrd=/boot/initrd.img net.ifnames=0 console=tty0 console=ttyS0,115200n8 %s ` syslinuxCfgDebian = `DEFAULT linux SAY Now booting the kernel from SYSLINUX... LABEL linux KERNEL /vmlinuz - APPEND ro root=UUID=%s initrd=/initrd.img net.ifnames=0 console=tty0 console=ttyS0,115200n8 + APPEND ro root=UUID=%s initrd=/initrd.img net.ifnames=0 console=tty0 console=ttyS0,115200n8 %s ` syslinuxCfgAlpine = `DEFAULT linux SAY Now booting the kernel from SYSLINUX... LABEL linux KERNEL /boot/vmlinuz-virt - APPEND ro root=UUID=%s rootfstype=ext4 initrd=/boot/initramfs-virt console=ttyS0,115200 + APPEND ro root=UUID=%s rootfstype=ext4 initrd=/boot/initramfs-virt console=ttyS0,115200 %s ` syslinuxCfgCentOS = `DEFAULT linux SAY Now booting the kernel from SYSLINUX... LABEL linux KERNEL /boot/vmlinuz - APPEND ro root=UUID=%s initrd=/boot/initrd.img net.ifnames=0 console=tty0 console=ttyS0,115200n8 + APPEND ro root=UUID=%s initrd=/boot/initrd.img net.ifnames=0 console=tty0 console=ttyS0,115200n8 %s ` ) @@ -119,12 +119,13 @@ type builder struct { mbrPath string - loDevice string - loPart string - diskUUD string + loDevice string + loPart string + diskUUD string + cmdLineExtra string } -func NewBuilder(ctx context.Context, workdir, imgTag, disk string, size int64, osRelease OSRelease, format string) (*builder, error) { +func NewBuilder(ctx context.Context, workdir, imgTag, disk string, size int64, osRelease OSRelease, format string, cmdLineExtra string) (*builder, error) { if err := checkDependencies(); err != nil { return nil, err } @@ -169,14 +170,15 @@ func NewBuilder(ctx context.Context, workdir, imgTag, disk string, size int64, o // size = int64(s) // } b := &builder{ - osRelease: osRelease, - img: img, - diskRaw: filepath.Join(workdir, disk+".d2vm.raw"), - diskOut: filepath.Join(workdir, disk+"."+format), - format: f, - size: size, - mbrPath: mbrBin, - mntPoint: filepath.Join(workdir, "/mnt"), + osRelease: osRelease, + img: img, + diskRaw: filepath.Join(workdir, disk+".d2vm.raw"), + diskOut: filepath.Join(workdir, disk+"."+format), + format: f, + size: size, + mbrPath: mbrBin, + mntPoint: filepath.Join(workdir, "/mnt"), + cmdLineExtra: cmdLineExtra, } if err := os.MkdirAll(b.mntPoint, os.ModePerm); err != nil { return nil, err @@ -343,7 +345,7 @@ func (b *builder) installKernel(ctx context.Context) error { if err != nil { return err } - if err := b.chWriteFile("/boot/syslinux.cfg", fmt.Sprintf(sysconfig, b.diskUUD), perm); err != nil { + if err := b.chWriteFile("/boot/syslinux.cfg", fmt.Sprintf(sysconfig, b.diskUUD, b.cmdLineExtra), perm); err != nil { return err } return nil diff --git a/cmd/d2vm/build.go b/cmd/d2vm/build.go index b44c997..a1daa35 100644 --- a/cmd/d2vm/build.go +++ b/cmd/d2vm/build.go @@ -47,14 +47,14 @@ var ( return err } exec.SetDebug(debug) - logrus.Infof("building docker image from %s", file) if file == "" { file = filepath.Join(args[0], "Dockerfile") } + logrus.Infof("building docker image from %s", file) if err := docker.Build(cmd.Context(), tag, file, args[0], buildArgs...); err != nil { return err } - return d2vm.Convert(cmd.Context(), tag, size, password, output) + return d2vm.Convert(cmd.Context(), tag, size, password, output, cmdLineExtra) }, } ) @@ -70,4 +70,5 @@ func init() { buildCmd.Flags().StringVarP(&size, "size", "s", "10G", "The output image size") buildCmd.Flags().BoolVarP(&debug, "debug", "d", false, "Enable Debug output") buildCmd.Flags().BoolVar(&force, "force", false, "Override output image") + buildCmd.Flags().StringVar(&cmdLineExtra, "append-to-cmdline", "", "Extra kernel cmdline arguments to append to the generated one") } diff --git a/cmd/d2vm/convert.go b/cmd/d2vm/convert.go index 9f9e057..a645020 100644 --- a/cmd/d2vm/convert.go +++ b/cmd/d2vm/convert.go @@ -30,7 +30,8 @@ import ( ) var ( - pull = false + pull = false + cmdLineExtra = "" convertCmd = &cobra.Command{ Use: "convert [docker image]", @@ -78,7 +79,7 @@ var ( return err } } - return d2vm.Convert(cmd.Context(), img, size, password, output) + return d2vm.Convert(cmd.Context(), img, size, password, output, cmdLineExtra) }, } ) @@ -98,5 +99,6 @@ func init() { convertCmd.Flags().StringVarP(&size, "size", "s", "10G", "The output image size") convertCmd.Flags().BoolVarP(&debug, "debug", "d", false, "Enable Debug output") convertCmd.Flags().BoolVarP(&force, "force", "f", false, "Override output qcow2 image") + convertCmd.Flags().StringVar(&cmdLineExtra, "append-to-cmdline", "", "Extra kernel cmdline arguments to append to the generated one") rootCmd.AddCommand(convertCmd) } diff --git a/convert.go b/convert.go index 378a734..c67daef 100644 --- a/convert.go +++ b/convert.go @@ -28,7 +28,7 @@ import ( "go.linka.cloud/d2vm/pkg/docker" ) -func Convert(ctx context.Context, img string, size int64, password string, output string) error { +func Convert(ctx context.Context, img string, size int64, password string, output string, cmdLineExtra string) error { imgUUID := uuid.New().String() tmpPath := filepath.Join(os.TempDir(), "d2vm", imgUUID) if err := os.MkdirAll(tmpPath, os.ModePerm); err != nil { @@ -67,7 +67,7 @@ func Convert(ctx context.Context, img string, size int64, password string, outpu if format == "" { format = "raw" } - b, err := NewBuilder(ctx, tmpPath, imgUUID, "", size, r, format) + b, err := NewBuilder(ctx, tmpPath, imgUUID, "", size, r, format, cmdLineExtra) if err != nil { return err }