xref: /aosp_15_r20/external/crosvm/e2e_tests/guest_under_test/initramfs/Containerfile (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1# Copyright 2023 The ChromiumOS Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5FROM docker.io/debian:bookworm as builder
6
7RUN echo "\ndeb-src http://deb.debian.org/debian bookworm main non-free-firmware\n" >> /etc/apt/sources.list
8
9RUN apt-get update
10RUN apt-get install -y bash-static git meson linux-headers-amd64 wget bison gettext
11
12# Download rust static coreutils
13WORKDIR /root
14RUN wget https://github.com/uutils/coreutils/releases/download/0.0.20/coreutils-0.0.20-x86_64-unknown-linux-musl.tar.gz -O coreutils.tar.gz
15RUN tar -zxvf coreutils.tar.gz
16
17# Download source code and build util-linux
18RUN git clone https://github.com/util-linux/util-linux.git
19WORKDIR /root/util-linux
20RUN git checkout v2.39.1
21RUN apt-get build-dep -y util-linux
22RUN meson setup build -D static-programs="losetup, mount, umount" -D build-python=disabled -D cryptsetup=disabled -D build-chfn-chsh=disabled -D build-su=disabled -D build-runuser=disabled
23RUN ninja -C build
24
25FROM scratch
26
27# Create /bin directory manually to avoid potential problems caused by implicit directory creation with COPY
28COPY --from=builder /root/coreutils-0.0.20-x86_64-unknown-linux-musl/coreutils /coreutils
29RUN ["/coreutils", "mkdir", "/bin"]
30
31# Start populating /bin directory with bash and coreutils
32COPY --from=builder /bin/bash-static /bin/bash
33COPY --from=builder /root/coreutils-0.0.20-x86_64-unknown-linux-musl/coreutils /bin/coreutils
34
35# Link /bin/bash to /bin/sh so podman can accept shell style RUN statements
36RUN ["/coreutils", "ln", "-s", "/bin/bash", "/bin/sh"]
37
38# Cleanup initially copied coreutils binary as it now lives in /bin
39RUN coreutils rm /coreutils
40
41# Coreutils multirun binary provides following sub-commands
42RUN coreutils ln -s /bin/coreutils /bin/arch \
43    && coreutils ln -s /bin/coreutils /bin/b2sum \
44    && coreutils ln -s /bin/coreutils /bin/b3sum \
45    && coreutils ln -s /bin/coreutils /bin/base32 \
46    && coreutils ln -s /bin/coreutils /bin/base64 \
47    && coreutils ln -s /bin/coreutils /bin/basename \
48    && coreutils ln -s /bin/coreutils /bin/basenc \
49    && coreutils ln -s /bin/coreutils /bin/cat \
50    && coreutils ln -s /bin/coreutils /bin/chgrp \
51    && coreutils ln -s /bin/coreutils /bin/chmod \
52    && coreutils ln -s /bin/coreutils /bin/chown \
53    && coreutils ln -s /bin/coreutils /bin/chroot \
54    && coreutils ln -s /bin/coreutils /bin/cksum \
55    && coreutils ln -s /bin/coreutils /bin/comm \
56    && coreutils ln -s /bin/coreutils /bin/cp \
57    && coreutils ln -s /bin/coreutils /bin/csplit \
58    && coreutils ln -s /bin/coreutils /bin/cut \
59    && coreutils ln -s /bin/coreutils /bin/date \
60    && coreutils ln -s /bin/coreutils /bin/dd \
61    && coreutils ln -s /bin/coreutils /bin/df \
62    && coreutils ln -s /bin/coreutils /bin/dir \
63    && coreutils ln -s /bin/coreutils /bin/dircolors \
64    && coreutils ln -s /bin/coreutils /bin/dirname \
65    && coreutils ln -s /bin/coreutils /bin/du \
66    && coreutils ln -s /bin/coreutils /bin/echo \
67    && coreutils ln -s /bin/coreutils /bin/env \
68    && coreutils ln -s /bin/coreutils /bin/expand \
69    && coreutils ln -s /bin/coreutils /bin/expr \
70    && coreutils ln -s /bin/coreutils /bin/factor \
71    && coreutils ln -s /bin/coreutils /bin/false \
72    && coreutils ln -s /bin/coreutils /bin/fmt \
73    && coreutils ln -s /bin/coreutils /bin/fold \
74    && coreutils ln -s /bin/coreutils /bin/groups \
75    && coreutils ln -s /bin/coreutils /bin/hashsum \
76    && coreutils ln -s /bin/coreutils /bin/head \
77    && coreutils ln -s /bin/coreutils /bin/hostid \
78    && coreutils ln -s /bin/coreutils /bin/hostname \
79    && coreutils ln -s /bin/coreutils /bin/id \
80    && coreutils ln -s /bin/coreutils /bin/install \
81    && coreutils ln -s /bin/coreutils /bin/join \
82    && coreutils ln -s /bin/coreutils /bin/kill \
83    && coreutils ln -s /bin/coreutils /bin/link \
84    && coreutils ln -s /bin/coreutils /bin/ln \
85    && coreutils ln -s /bin/coreutils /bin/logname \
86    && coreutils ln -s /bin/coreutils /bin/ls \
87    && coreutils ln -s /bin/coreutils /bin/md5sum \
88    && coreutils ln -s /bin/coreutils /bin/mkdir \
89    && coreutils ln -s /bin/coreutils /bin/mkfifo \
90    && coreutils ln -s /bin/coreutils /bin/mknod \
91    && coreutils ln -s /bin/coreutils /bin/mktemp \
92    && coreutils ln -s /bin/coreutils /bin/more \
93    && coreutils ln -s /bin/coreutils /bin/mv \
94    && coreutils ln -s /bin/coreutils /bin/nice \
95    && coreutils ln -s /bin/coreutils /bin/nl \
96    && coreutils ln -s /bin/coreutils /bin/nohup \
97    && coreutils ln -s /bin/coreutils /bin/nproc \
98    && coreutils ln -s /bin/coreutils /bin/numfmt \
99    && coreutils ln -s /bin/coreutils /bin/od \
100    && coreutils ln -s /bin/coreutils /bin/paste \
101    && coreutils ln -s /bin/coreutils /bin/pathchk \
102    && coreutils ln -s /bin/coreutils /bin/pr \
103    && coreutils ln -s /bin/coreutils /bin/printenv \
104    && coreutils ln -s /bin/coreutils /bin/printf \
105    && coreutils ln -s /bin/coreutils /bin/ptx \
106    && coreutils ln -s /bin/coreutils /bin/pwd \
107    && coreutils ln -s /bin/coreutils /bin/readlink \
108    && coreutils ln -s /bin/coreutils /bin/realpath \
109    && coreutils ln -s /bin/coreutils /bin/relpath \
110    && coreutils ln -s /bin/coreutils /bin/rm \
111    && coreutils ln -s /bin/coreutils /bin/rmdir \
112    && coreutils ln -s /bin/coreutils /bin/seq \
113    && coreutils ln -s /bin/coreutils /bin/sha1sum \
114    && coreutils ln -s /bin/coreutils /bin/sha224sum \
115    && coreutils ln -s /bin/coreutils /bin/sha256sum \
116    && coreutils ln -s /bin/coreutils /bin/sha3-224sum \
117    && coreutils ln -s /bin/coreutils /bin/sha3-256sum \
118    && coreutils ln -s /bin/coreutils /bin/sha3-384sum \
119    && coreutils ln -s /bin/coreutils /bin/sha3-512sum \
120    && coreutils ln -s /bin/coreutils /bin/sha384sum \
121    && coreutils ln -s /bin/coreutils /bin/sha3sum \
122    && coreutils ln -s /bin/coreutils /bin/sha512sum \
123    && coreutils ln -s /bin/coreutils /bin/shake128sum \
124    && coreutils ln -s /bin/coreutils /bin/shake256sum \
125    && coreutils ln -s /bin/coreutils /bin/shred \
126    && coreutils ln -s /bin/coreutils /bin/shuf \
127    && coreutils ln -s /bin/coreutils /bin/sleep \
128    && coreutils ln -s /bin/coreutils /bin/sort \
129    && coreutils ln -s /bin/coreutils /bin/split \
130    && coreutils ln -s /bin/coreutils /bin/stat \
131    && coreutils ln -s /bin/coreutils /bin/stty \
132    && coreutils ln -s /bin/coreutils /bin/sum \
133    && coreutils ln -s /bin/coreutils /bin/sync \
134    && coreutils ln -s /bin/coreutils /bin/tac \
135    && coreutils ln -s /bin/coreutils /bin/tail \
136    && coreutils ln -s /bin/coreutils /bin/tee \
137    && coreutils ln -s /bin/coreutils /bin/test \
138    && coreutils ln -s /bin/coreutils /bin/timeout \
139    && coreutils ln -s /bin/coreutils /bin/touch \
140    && coreutils ln -s /bin/coreutils /bin/tr \
141    && coreutils ln -s /bin/coreutils /bin/true \
142    && coreutils ln -s /bin/coreutils /bin/truncate \
143    && coreutils ln -s /bin/coreutils /bin/tsort \
144    && coreutils ln -s /bin/coreutils /bin/tty \
145    && coreutils ln -s /bin/coreutils /bin/uname \
146    && coreutils ln -s /bin/coreutils /bin/unexpand \
147    && coreutils ln -s /bin/coreutils /bin/uniq \
148    && coreutils ln -s /bin/coreutils /bin/unlink \
149    && coreutils ln -s /bin/coreutils /bin/vdir \
150    && coreutils ln -s /bin/coreutils /bin/wc \
151    && coreutils ln -s /bin/coreutils /bin/whoami \
152    && coreutils ln -s /bin/coreutils /bin/yes
153
154# Install statically linked util-linux tools
155COPY --from=builder /root/util-linux/build/mount.static /bin/mount
156COPY --from=builder /root/util-linux/build/umount.static /bin/umount
157COPY --from=builder /root/util-linux/build/losetup.static /bin/losetup
158
159# Install delegate
160COPY ./delegate /bin/delegate
161
162# Populate root directory with other empty folders
163WORKDIR /
164RUN mkdir -p usr dev etc lib lib64 mnt proc root sbin sys newroot; exit 0
165
166COPY ./init.sh /init
167
168RUN chmod +x /init
169
170CMD /bin/bash
171