Skip to content

Commit 088583b

Browse files
committed
Use embed instead of direct inclusion.
This makes it a little more digestible to read, update, and potentially add new scripts.
1 parent c3e057a commit 088583b

File tree

8 files changed

+402
-287
lines changed

8 files changed

+402
-287
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (C) 2025 The Android Open Source Project
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit -o nounset -o pipefail
18+
19+
sudo apt-get update
20+
sudo apt-get upgrade -y
21+
22+
# Avoids blocking "Default mirror not found" popup prompt when pbuilder is installed.
23+
echo "pbuilder pbuilder/mirrorsite string https://deb.debian.org/debian" | sudo debconf-set-selections
24+
25+
# Resize
26+
sudo apt install -y cloud-utils
27+
sudo apt install -y cloud-guest-utils
28+
sudo apt install -y fdisk
29+
sudo growpart /dev/sdb 1 || /bin/true
30+
sudo e2fsck -f -y /dev/sdb1 || /bin/true
31+
sudo resize2fs /dev/sdb1
32+
33+
./mount_attached_disk.sh
34+
35+
kmodver_begin=$(sudo chroot /mnt/image/ /usr/bin/dpkg -s linux-image-cloud-amd64 | grep ^Depends: | \
36+
cut -d: -f2 | cut -d" " -f2 | sed 's/linux-image-//')
37+
echo "IMAGE STARTS WITH KERNEL: ${kmodver_begin}"
38+
39+
sudo chroot /mnt/image /usr/bin/apt update
40+
sudo chroot /mnt/image /usr/bin/apt upgrade -y
41+
42+
# Disable systemd mounting tmpfs at /tmp due backwards compatibility issues.
43+
# TODO(b/458388172): Remove line if cvd no longer stores artifacts
44+
# in /tmp by default.
45+
sudo chroot /mnt/image /usr/bin/systemctl mask tmp.mount
46+
47+
# Avoid automatic updates during tests.
48+
# https://manpages.debian.org/trixie/unattended-upgrades/unattended-upgrade.8.en.html
49+
sudo chroot /mnt/image /usr/bin/apt purge -y unattended-upgrades
50+
51+
# Install JDK.
52+
#
53+
# JDK it's not required to launch a CF device. It's required to run
54+
# some of Tradefed tests that are run from the CF host side like
55+
# some CF gfx tests, adb tests, etc.
56+
sudo chroot /mnt/image /usr/bin/wget -P /usr/java https://download.java.net/java/GA/jdk21.0.2/f2283984656d49d69e91c558476027ac/13/GPL/openjdk-21.0.2_linux-x64_bin.tar.gz
57+
# https://download.java.net/java/GA/jdk21.0.2/f2283984656d49d69e91c558476027ac/13/GPL/openjdk-21.0.2_linux-x64_bin.tar.gz.sha256
58+
export JDK21_SHA256SUM=a2def047a73941e01a73739f92755f86b895811afb1f91243db214cff5bdac3f
59+
if ! echo "$JDK21_SHA256SUM /usr/java/openjdk-21.0.2_linux-x64_bin.tar.gz" | sudo chroot /mnt/image /usr/bin/sha256sum -c ; then
60+
echo "** ERROR: KEY MISMATCH **"; popd >/dev/null; exit 1;
61+
fi
62+
sudo chroot /mnt/image /usr/bin/tar xvzf /usr/java/openjdk-21.0.2_linux-x64_bin.tar.gz -C /usr/java
63+
sudo chroot /mnt/image /usr/bin/rm /usr/java/openjdk-21.0.2_linux-x64_bin.tar.gz
64+
ENV_JAVA_HOME='/usr/java/jdk-21.0.2'
65+
echo "JAVA_HOME=$ENV_JAVA_HOME" | sudo chroot /mnt/image /usr/bin/tee -a /etc/environment >/dev/null
66+
echo "JAVA_HOME=$ENV_JAVA_HOME" | sudo chroot /mnt/image /usr/bin/tee -a /etc/profile >/dev/null
67+
echo 'PATH=$JAVA_HOME/bin:$PATH' | sudo chroot /mnt/image /usr/bin/tee -a /etc/profile >/dev/null
68+
echo "PATH=$ENV_JAVA_HOME/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" | sudo chroot /mnt/image /usr/bin/tee -a /etc/environment >/dev/null
69+
70+
# install tools dependencies
71+
sudo chroot /mnt/image /usr/bin/apt install -y unzip bzip2 lzop
72+
sudo chroot /mnt/image /usr/bin/apt install -y aapt
73+
sudo chroot /mnt/image /usr/bin/apt install -y screen # needed by tradefed
74+
75+
sudo chroot /mnt/image /usr/bin/find /home -ls
76+
77+
# update QEMU version to most recent backport
78+
sudo chroot /mnt/image /usr/bin/apt install -y --only-upgrade qemu-system-x86
79+
sudo chroot /mnt/image /usr/bin/apt install -y --only-upgrade qemu-system-arm
80+
sudo chroot /mnt/image /usr/bin/apt install -y --only-upgrade qemu-system-misc
81+
82+
# Install GPU driver dependencies
83+
sudo cp install_nvidia.sh /mnt/image/
84+
sudo chroot /mnt/image /usr/bin/bash install_nvidia.sh
85+
sudo rm /mnt/image/install_nvidia.sh
86+
87+
# Vulkan loader
88+
sudo chroot /mnt/image /usr/bin/apt install -y libvulkan1
89+
90+
# Wayland-server needed to have Nvidia driver fail gracefully when attempting to
91+
# use the EGL API on GCE instances without a GPU.
92+
sudo chroot /mnt/image /usr/bin/apt install -y libwayland-server0
93+
94+
# Clean up the builder's version of resolv.conf
95+
sudo rm /mnt/image/etc/resolv.conf
96+
97+
# Make sure the image has /var/empty, and allow unprivileged_userns_clone for
98+
# minijail process sandboxing
99+
sudo chroot /mnt/image /usr/bin/mkdir -p /var/empty
100+
sudo tee /mnt/image/etc/sysctl.d/80-nsjail.conf >/dev/null <<EOF
101+
kernel.unprivileged_userns_clone=1
102+
EOF
103+
104+
kmodver_end=$(sudo chroot /mnt/image/ /usr/bin/dpkg -s linux-image-cloud-amd64 | grep ^Depends: | \
105+
cut -d: -f2 | cut -d" " -f2 | sed 's/linux-image-//')
106+
echo "IMAGE ENDS WITH KERNEL: ${kmodver_end}"
107+
108+
if [ "${kmodver_begin}" != "${kmodver_end}" ]; then
109+
echo "KERNEL UPDATE DETECTED!!! ${kmodver_begin} -> ${kmodver_end}"
110+
echo "Use source image with kernel ${kmodver_end} installed."
111+
exit 1
112+
fi
113+
114+
# Skip unmounting:
115+
# Sometimes systemd starts, making it hard to unmount
116+
# In any case we'll unmount cleanly when the instance shuts down
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (C) 2025 The Android Open Source Project
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit -o nounset -o pipefail
18+
19+
sudo apt update
20+
21+
sudo apt install -y cloud-utils
22+
sudo apt install -y cloud-guest-utils
23+
sudo apt install -y fdisk
24+
sudo growpart /dev/sdb 1 || /bin/true
25+
sudo e2fsck -f -y /dev/sdb1 || /bin/true
26+
sudo resize2fs /dev/sdb1
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (C) 2025 The Android Open Source Project
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit -o nounset -o pipefail
18+
19+
if [[ $# -eq 0 ]] ; then
20+
echo "usage: $0 /path/to/deb1 /path/to/deb2 /path/to/deb3"
21+
exit 1
22+
fi
23+
24+
./fill_available_disk_space.sh
25+
26+
./mount_attached_disk.sh
27+
28+
kmodver_begin=$(sudo chroot /mnt/image/ /usr/bin/dpkg -s linux-image-cloud-amd64 | grep ^Depends: | \
29+
cut -d: -f2 | cut -d" " -f2 | sed 's/linux-image-//')
30+
echo "IMAGE STARTS WITH KERNEL: ${kmodver_begin}"
31+
32+
sudo chroot /mnt/image /usr/bin/apt update
33+
sudo chroot /mnt/image /usr/bin/apt upgrade -y
34+
35+
rm -rf /mnt/image/tmp/install
36+
mkdir /mnt/image/tmp/install
37+
38+
# Install packages
39+
for src in "$@"
40+
do
41+
echo "Installing: ${src}"
42+
name=$(basename "${src}")
43+
cp "${src}" "/mnt/image/tmp/install/${name}"
44+
sudo chroot /mnt/image /usr/bin/apt install -y "/tmp/install/${name}"
45+
done
46+
47+
kmodver_end=$(sudo chroot /mnt/image/ /usr/bin/dpkg -s linux-image-cloud-amd64 | grep ^Depends: | \
48+
cut -d: -f2 | cut -d" " -f2 | sed 's/linux-image-//')
49+
echo "IMAGE ENDS WITH KERNEL: ${kmodver_end}"
50+
51+
if [ "${kmodver_begin}" != "${kmodver_end}" ]; then
52+
echo "KERNEL UPDATE DETECTED!!! ${kmodver_begin} -> ${kmodver_end}"
53+
echo "Use source image with kernel ${kmodver_end} installed."
54+
exit 1
55+
fi
56+
57+
# Skip unmounting:
58+
# Sometimes systemd starts, making it hard to unmount
59+
# In any case we'll unmount cleanly when the instance shuts down
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (C) 2025 The Android Open Source Project
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit -o nounset -o pipefail
18+
19+
if [[ $# -eq 0 ]] ; then
20+
echo "usage: $0 <linux-image-deb>"
21+
exit 1
22+
fi
23+
24+
linux_image_deb=$1
25+
26+
sudo apt-get update
27+
sudo apt-get upgrade -y
28+
29+
./mount_attached_disk.sh
30+
31+
version=$(sudo chroot /mnt/image/ /usr/bin/dpkg -s linux-image-cloud-amd64 | grep ^Depends: | \
32+
cut -d: -f2 | cut -d" " -f2 )
33+
echo "START VERSION: ${version}"
34+
35+
sudo chroot /mnt/image /usr/bin/apt-get update
36+
sudo chroot /mnt/image /usr/bin/apt-get upgrade -y
37+
38+
version=$(sudo chroot /mnt/image/ /usr/bin/dpkg -s linux-image-cloud-amd64 | grep ^Depends: | \
39+
cut -d: -f2 | cut -d" " -f2 )
40+
echo "AFTER UPGRADE VERSION: ${version}"
41+
42+
sudo chroot /mnt/image /usr/bin/apt-get install -y ${linux_image_deb}
43+
44+
version=$(sudo chroot /mnt/image/ /usr/bin/dpkg -s linux-image-cloud-amd64 | grep ^Depends: | \
45+
cut -d: -f2 | cut -d" " -f2)
46+
echo "END VERSION: ${version}"
47+
48+
if [ "${version}" != "${linux_image_deb}" ]; then
49+
echo "CREATE IMAGE FAILED!!!"
50+
echo "Expected ${linux_image_deb}, got: ${version}"
51+
exit 1
52+
fi
53+
54+
# Skip unmounting:
55+
# Sometimes systemd starts, making it hard to unmount
56+
# In any case we'll unmount cleanly when the instance shuts down
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (C) 2025 The Android Open Source Project
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -x
18+
set -o errexit
19+
20+
arch=$(uname -m)
21+
nvidia_arch=${arch}
22+
[ "${arch}" = "x86_64" ] && arch=amd64
23+
[ "${arch}" = "aarch64" ] && arch=arm64
24+
25+
# NVIDIA driver needs dkms which requires /dev/fd
26+
if [ ! -d /dev/fd ]; then
27+
ln -s /proc/self/fd /dev/fd
28+
fi
29+
30+
# Using "Depends:" is more reliable than "Version:", because it works for
31+
# backported ("bpo") kernels as well. NOTE: "Package" can be used instead
32+
# if we don't install the metapackage ("linux-image-cloud-${arch}") but a
33+
# specific version in the future
34+
kmodver=$(dpkg -s linux-image-cloud-${arch} | grep ^Depends: | \
35+
cut -d: -f2 | cut -d" " -f2 | sed 's/linux-image-//')
36+
37+
apt-get install -y wget
38+
39+
# Dependencies for nvidia-installer
40+
apt-get install -y \
41+
$(echo linux-headers-${kmodver}) \
42+
dkms \
43+
libglvnd-dev \
44+
libc6-dev \
45+
pkg-config
46+
47+
nvidia_version=570.158.01
48+
49+
wget -q https://us.download.nvidia.com/tesla/${nvidia_version}/NVIDIA-Linux-${nvidia_arch}-${nvidia_version}.run
50+
chmod a+x NVIDIA-Linux-${nvidia_arch}-${nvidia_version}.run
51+
./NVIDIA-Linux-${nvidia_arch}-${nvidia_version}.run -x
52+
NVIDIA-Linux-${nvidia_arch}-${nvidia_version}/nvidia-installer --silent --no-install-compat32-libs --no-backup --no-wine-files --install-libglvnd --dkms -k "${kmodver}"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (C) 2025 The Android Open Source Project
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Mount attached disk `/dev/sdb1` at `/mnt/image`.
18+
set -o errexit -o nounset -o pipefail
19+
20+
sudo mkdir -p /mnt/image
21+
sudo mount /dev/sdb1 /mnt/image
22+
sudo mount -t sysfs none /mnt/image/sys
23+
sudo mount -t proc none /mnt/image/proc
24+
sudo mount --bind /boot/efi /mnt/image/boot/efi
25+
sudo mount --bind /dev/ /mnt/image/dev
26+
sudo mount --bind /dev/pts /mnt/image/dev/pts
27+
sudo mount --bind /run /mnt/image/run
28+
# resolv.conf is needed on Debian but not Ubuntu
29+
if [ ! -f /mnt/image/etc/resolv.conf ]; then
30+
sudo cp /etc/resolv.conf /mnt/image/etc/
31+
fi
32+
`

0 commit comments

Comments
 (0)