Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -315,15 +325,15 @@ 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 {
return err
}
} 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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
29 changes: 24 additions & 5 deletions templates/ubuntu.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -21,18 +26,32 @@ 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 }}

{{ 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\
Expand All @@ -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\
Expand Down