diff --git a/builder.go b/builder.go index 8c3fb87..b452d4e 100644 --- a/builder.go +++ b/builder.go @@ -280,6 +280,16 @@ func (b *builder) makeImg(ctx context.Context) error { } func (b *builder) mountImg(ctx context.Context) error { + var mkfsExt4Opts []string + r := ctx.Value("release").(OSRelease) + if r.ID == ReleaseUbuntu { + if strings.HasPrefix(r.VersionID, "12.") { + mkfsExt4Opts = append(mkfsExt4Opts, "-O", "^has_journal,^metadata_csum") + } + if strings.HasPrefix(r.VersionID, "14.") { + mkfsExt4Opts = append(mkfsExt4Opts, "-O", "^metadata_csum") + } + } logrus.Infof("mounting raw image") o, _, err := exec.RunOut(ctx, "losetup", "--show", "-f", b.diskRaw) if err != nil { @@ -315,7 +325,7 @@ func (b *builder) mountImg(ctx context.Context) error { b.rootPart = "/dev/mapper/root" b.mappedCryptRoot = filepath.Join("/dev/mapper", b.cryptRoot) logrus.Infof("creating raw image file system") - if err := exec.Run(ctx, "mkfs.ext4", b.mappedCryptRoot); err != nil { + if err := exec.Run(ctx, "mkfs.ext4", append(mkfsExt4Opts, b.mappedCryptRoot)...); err != nil { return err } if err := exec.Run(ctx, "mount", b.mappedCryptRoot, b.mntPoint); err != nil { @@ -323,7 +333,7 @@ func (b *builder) mountImg(ctx context.Context) error { } } else { logrus.Infof("creating raw image file system") - if err := exec.Run(ctx, "mkfs.ext4", b.rootPart); err != nil { + if err := exec.Run(ctx, "mkfs.ext4", append(mkfsExt4Opts, b.rootPart)...); err != nil { return err } if err := exec.Run(ctx, "mount", b.rootPart, b.mntPoint); err != nil { @@ -339,7 +349,7 @@ func (b *builder) mountImg(ctx context.Context) error { if b.bootFS.IsFat() { err = exec.Run(ctx, "mkfs.fat", "-F32", b.bootPart) } else { - err = exec.Run(ctx, "mkfs.ext4", b.bootPart) + err = exec.Run(ctx, "mkfs.ext4", append(mkfsExt4Opts, b.bootPart)...) } if err != nil { return err diff --git a/convert.go b/convert.go index 769de35..7de1ae4 100644 --- a/convert.go +++ b/convert.go @@ -45,7 +45,7 @@ func Convert(ctx context.Context, img string, opts ...ConvertOption) error { if err != nil { return err } - + ctx = context.WithValue(ctx, "release", r) if o.luksPassword != "" && !r.SupportsLUKS() { return fmt.Errorf("luks is not supported for %s %s", r.Name, r.Version) } diff --git a/templates/ubuntu.Dockerfile b/templates/ubuntu.Dockerfile index 1589379..553aacf 100644 --- a/templates/ubuntu.Dockerfile +++ b/templates/ubuntu.Dockerfile @@ -2,13 +2,18 @@ FROM {{ .Image }} USER root +{{ if le .Release.VersionID "14.04" }} +# restore initctl +RUN rm /sbin/initctl && dpkg-divert --rename --remove /sbin/initctl +# setup ttyS0 +RUN cp /etc/init/tty1.conf /etc/init/ttyS0.conf && sed -i s/tty1/ttyS0/g /etc/init/ttyS0.conf +{{ end }} + RUN ARCH="$([ "$(uname -m)" = "x86_64" ] && echo amd64 || echo arm64)"; \ apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ linux-image-virtual \ initramfs-tools \ - systemd-sysv \ - systemd \ {{- if .Grub }} grub-common \ grub2-common \ @@ -21,10 +26,24 @@ RUN ARCH="$([ "$(uname -m)" = "x86_64" ] && echo amd64 || echo arm64)"; \ {{- end }} dbus \ isc-dhcp-client \ - iproute2 \ iputils-ping && \ find /boot -type l -exec rm {} \; +{{ if ge .Release.VersionID "14.04" }} +RUN ARCH="$([ "$(uname -m)" = "x86_64" ] && echo amd64 || echo arm64)"; \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ + iproute2 +{{ end }} + +{{ if ge .Release.VersionID "16.04" }} +RUN ARCH="$([ "$(uname -m)" = "x86_64" ] && echo amd64 || echo arm64)"; \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ + systemd-sysv \ + systemd +{{ end }} + {{ if gt .Release.VersionID "16.04" }} RUN systemctl preset-all {{ end }} @@ -32,7 +51,7 @@ RUN systemctl preset-all {{ if .Password }}RUN echo "root:{{ .Password }}" | chpasswd {{ end }} {{ if eq .NetworkManager "netplan" }} -RUN apt install -y netplan.io +RUN apt-get install -y netplan.io RUN mkdir -p /etc/netplan && printf '\ network:\n\ version: 2\n\ @@ -47,7 +66,7 @@ network:\n\ - 8.8.4.4\n\ ' > /etc/netplan/00-netcfg.yaml {{ else if eq .NetworkManager "ifupdown"}} -RUN if [ -z "$(apt-cache madison ifupdown-ng 2> /dev/nul)" ]; then apt install -y ifupdown; else apt install -y ifupdown-ng; fi +RUN if [ -z "$(apt-cache madison ifupdown-ng 2> /dev/nul)" ]; then apt-get install -y ifupdown; else apt-get install -y ifupdown-ng; fi RUN mkdir -p /etc/network && printf '\ auto eth0\n\ allow-hotplug eth0\n\