Snap for 8554636 from 0dfb926ca0a2c37347c1a2794a6082a122c6d1de to sdk-release

Change-Id: I90d1722066a612a586c8d48acb58eaf02b1c9e26
diff --git a/net/test/build_rootfs.sh b/net/test/build_rootfs.sh
index e631fe8..2080826 100755
--- a/net/test/build_rootfs.sh
+++ b/net/test/build_rootfs.sh
@@ -21,7 +21,7 @@
 SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
 
 usage() {
-  echo -n "usage: $0 [-h] [-s bullseye|bullseye-cuttlefish|bullseye-rockpi] "
+  echo -n "usage: $0 [-h] [-s bullseye|bullseye-cuttlefish|bullseye-rockpi|bullseye-server] "
   echo -n "[-a i386|amd64|armhf|arm64] -k /path/to/kernel "
   echo -n "-i /path/to/initramfs.gz [-d /path/to/dtb:subdir] "
   echo "[-m http://mirror/debian] [-n rootfs] [-r initrd] [-e]"
diff --git a/net/test/rootfs/bullseye-server.list b/net/test/rootfs/bullseye-server.list
new file mode 100644
index 0000000..f6a6f41
--- /dev/null
+++ b/net/test/rootfs/bullseye-server.list
@@ -0,0 +1,9 @@
+#include "bullseye-cuttlefish.list"
+aapt
+bzip2
+gcc
+make
+openjdk-11-jre
+screen
+software-properties-common
+unzip
diff --git a/net/test/rootfs/bullseye-server.sh b/net/test/rootfs/bullseye-server.sh
new file mode 100755
index 0000000..d7a52bc
--- /dev/null
+++ b/net/test/rootfs/bullseye-server.sh
@@ -0,0 +1,85 @@
+#!/bin/bash
+#
+# Copyright (C) 2022 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+set -e
+set -u
+
+SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
+
+. $SCRIPT_DIR/bullseye-common.sh
+
+arch=$(uname -m)
+[ "${arch}" = "x86_64" ] && arch=amd64
+
+setup_dynamic_networking "en*" ""
+
+if [ "${arch}" = "amd64" ]; then
+  # Install apt-key for packages.cloud.google.com
+  curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
+
+  # Enable cloud-sdk repository
+  cat >/etc/apt/sources.list.d/google-cloud-sdk.list <<EOF
+deb https://packages.cloud.google.com/apt cloud-sdk main
+EOF
+fi
+
+update_apt_sources "bullseye bullseye-backports"
+
+if [ "${arch}" = "amd64" ]; then
+  # Enable non-free for the NVIDIA driver
+  add-apt-repository non-free
+  apt-get update
+fi
+
+setup_cuttlefish_user
+
+# Get kernel and QEMU from backports
+for package in linux-image-cloud-${arch} qemu-system-arm qemu-system-x86; do
+  apt-get install -y -t bullseye-backports ${package}
+done
+
+# Compute the linux-image-cloud version installed
+kver=$(dpkg -s linux-image-cloud-${arch} | \
+       grep ^Version: | cut -d: -f2 | tr -d ' ')
+ksrcver=$(echo ${kernel_version} | cut -d. -f-2)
+
+# Get kernel headers and sources from backports
+for package in linux-headers-${kver}-${arch} linux-source-${ksrcver}; do
+  apt-get install -y -t bullseye-backports ${package}
+done
+
+if [ "${arch}" = "amd64" ]; then
+  # Get NVIDIA driver and dependencies from backports/non-free
+  for package in firmware-misc-nonfree libglvnd-dev libvulkan1 nvidia-driver; do
+    apt-get install -y -t bullseye-backports ${package}
+  done
+fi
+
+get_installed_packages >/root/originally-installed
+
+setup_and_build_cuttlefish
+
+get_installed_packages >/root/installed
+
+remove_installed_packages /root/originally-installed /root/installed
+
+install_and_cleanup_cuttlefish
+
+create_systemd_getty_symlinks ttyS0 hvc1
+
+apt-get purge -y vim-tiny
+bullseye_cleanup
diff --git a/net/test/rootfs/common.sh b/net/test/rootfs/common.sh
index c86c39c..a722155 100644
--- a/net/test/rootfs/common.sh
+++ b/net/test/rootfs/common.sh
@@ -17,13 +17,17 @@
 
 trap "echo 3 >${exitcode}" ERR
 
-# $1 - Suite name for apt sources
+# $1 - Suite names for apt sources
 update_apt_sources() {
   # Add the needed debian sources
-  cat >/etc/apt/sources.list <<EOF
-deb http://ftp.debian.org/debian bullseye main
-deb-src http://ftp.debian.org/debian bullseye main
+  cat >/etc/apt/sources.list << EOF
 EOF
+  for source in $1; do
+    cat >/etc/apt/sources.list <<EOF
+deb http://ftp.debian.org/debian $source main
+deb-src http://ftp.debian.org/debian $source main
+EOF
+  done
 
   # Disable the automatic installation of recommended packages
   cat >/etc/apt/apt.conf.d/90recommends <<EOF
@@ -103,6 +107,10 @@
   useradd -m -G cvdnetwork,kvm,render,sudo,video \
     -d /home/vsoc-01 --shell /bin/bash vsoc-01
   echo -e "cuttlefish\ncuttlefish" | passwd vsoc-01
+
+  # Enable unlimited memory locking for vsoc-01, which is needed by protected
+  # KVM, which is enabled by default on arm64 devices
+  echo "vsoc-01 - memlock unlimited" >>/etc/security/limits.conf
 }
 
 # $* - One or more device names for getty spawns