Skip to content

Commit

Permalink
luks: fix ubuntu <22.04 support
Browse files Browse the repository at this point in the history
Signed-off-by: Adphi <[email protected]>
  • Loading branch information
Adphi committed Mar 1, 2023
1 parent bfa5f0d commit f75b0c7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
5 changes: 4 additions & 1 deletion builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,10 @@ func (b *builder) installKernel(ctx context.Context) error {
case ReleaseCentOS:
cfg = fmt.Sprintf(sysconfig, b.rootUUID, fmt.Sprintf("%s rd.luks.name=UUID=%s rd.luks.uuid=%s rd.luks.crypttab=0", b.cmdLineExtra, b.rootUUID, b.cryptUUID))
default:
cfg = fmt.Sprintf(sysconfig, b.rootUUID, fmt.Sprintf("%s root=/dev/mapper/root cryptopts=target=root,source=UUID=%s", b.cmdLineExtra, b.cryptUUID))
// for some versions of debian, the cryptopts parameter MUST contain all the following: target,srouce,key,opts...
// see https://salsa.debian.org/cryptsetup-team/cryptsetup/-/blob/debian/buster/debian/functions
// and https://cryptsetup-team.pages.debian.net/cryptsetup/README.initramfs.html
cfg = fmt.Sprintf(sysconfig, b.rootUUID, fmt.Sprintf("%s root=/dev/mapper/root cryptopts=target=root,source=UUID=%s,key=none,luks", b.cmdLineExtra, b.cryptUUID))
cfg = strings.Replace(cfg, "root=UUID="+b.rootUUID, "", 1)
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ type img struct {

var images = []img{
{name: "alpine:3.17", luks: "Enter passphrase for /dev/sda2:"},
{name: "ubuntu:20.04", luks: "Please unlock disk root:"},
{name: "ubuntu:18.04", luks: "Please unlock disk root:"},
{name: "ubuntu:22.04", luks: "Please unlock disk root:"},
{name: "debian:11", luks: "Please unlock disk root:"},
{name: "centos:8", luks: "Please enter passphrase for disk"},
}
Expand All @@ -68,7 +69,7 @@ func TestConvert(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// t.Parallel()

dir := filepath.Join("/tmp", "d2vm-e2e", tt.name)
require.NoError(os.MkdirAll(dir, os.ModePerm))

Expand All @@ -78,15 +79,14 @@ func TestConvert(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// t.Parallel()
require := require2.New(t)

out := filepath.Join(dir, strings.NewReplacer(":", "-", ".", "-").Replace(img.name)+".qcow2")

if _, err := os.Stat(out); err == nil {
require.NoError(os.Remove(out))
}

require.NoError(docker.RunD2VM(ctx, d2vm.Image, d2vm.Version, dir, dir, "convert", append([]string{"-p", "root", "-o", "/out/" + filepath.Base(out), "-v", "--keep-cache", img.name}, tt.args...)...))

inr, inw := io.Pipe()
Expand Down
6 changes: 2 additions & 4 deletions templates/alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ RUN apk update --no-cache && \
apk add \
util-linux \
linux-virt \
{{- if .Luks }}
cryptsetup \
{{- end }}
{{- if ge .Release.VersionID "3.17" }}
busybox-openrc \
busybox-mdev-openrc \
Expand All @@ -34,7 +31,8 @@ iface eth0 inet dhcp\n\
{{ end }}

{{- if .Luks }}
RUN source /etc/mkinitfs/mkinitfs.conf && \
RUN apk add --no-cache cryptsetup && \
source /etc/mkinitfs/mkinitfs.conf && \
echo "features=\"${features} cryptsetup\"" > /etc/mkinitfs/mkinitfs.conf && \
mkinitfs $(ls /lib/modules)
{{- end }}
14 changes: 8 additions & 6 deletions templates/centos.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ RUN yum install -y \
systemd \
NetworkManager \
e2fsprogs \
{{- if .Luks }}
cryptsetup \
{{- end }}
sudo && \
systemctl enable NetworkManager && \
systemctl unmask systemd-remount-fs.service && \
systemctl unmask getty.target

RUN dracut --no-hostonly --regenerate-all --force {{ if .Luks }}--install="/usr/sbin/cryptsetup"{{ end }}&& \
systemctl unmask getty.target && \
cd /boot && \
ln -s $(find . -name 'vmlinuz-*') vmlinuz && \
ln -s $(find . -name 'initramfs-*.img') initrd.img

{{ if .Luks }}
RUN yum install -y cryptsetup && \
dracut --no-hostonly --regenerate-all --force --install="/usr/sbin/cryptsetup" && \
{{ else }}
RUN dracut --no-hostonly --regenerate-all --force
{{ end }}

{{ if .Password }}RUN echo "root:{{ .Password }}" | chpasswd {{ end }}
6 changes: 2 additions & 4 deletions templates/debian.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ USER root

RUN apt-get -y update && \
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \
{{- if .Luks }}
cryptsetup-initramfs \
{{- end }}
linux-image-amd64

RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
Expand Down Expand Up @@ -47,5 +44,6 @@ iface eth0 inet dhcp\n\


{{- if .Luks }}
RUN update-initramfs -u -v
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cryptsetup-initramfs && \
update-initramfs -u -v
{{- end }}
6 changes: 2 additions & 4 deletions templates/ubuntu.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \
linux-image-virtual \
initramfs-tools \
{{- if .Luks }}
cryptsetup-initramfs \
{{- end }}
systemd-sysv \
systemd \
dbus \
Expand Down Expand Up @@ -45,5 +42,6 @@ iface eth0 inet dhcp\n\
{{ end }}

{{- if .Luks }}
RUN update-initramfs -u -v
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cryptsetup-initramfs && \
update-initramfs -u -v
{{- end }}

0 comments on commit f75b0c7

Please sign in to comment.