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
92 changes: 92 additions & 0 deletions .github/workflows/gigabyte-ampere-cuttlefish-installer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Workflow for Gigabyte Ampere Server Cuttlefish Installer

on: [push]

jobs:
build-iso:
runs-on: ubuntu-22.04
container:
image: debian@sha256:9258a75a7e4323c9e5562b361effc84ee747920116d8adfc98a465a5cdc9150e # debian:bookworm-20250407 (amd64)
env:
DEBIAN_ISO_URL: "https://deb.debian.org/debian/dists/bookworm/main/installer-arm64/current/images/netboot/mini.iso"
CI_PROJECT_NAME: ${{ github.event.repository.name }}
CI_PIPELINE_ID: ${{ github.run_id }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setting up build environment
run: |
apt-get update
apt-get upgrade -y
apt-get install -y sudo
apt-get install -y wget libarchive-tools
apt-get install -y xorriso
apt-get install -y cpio xz-utils
apt-get install -y fdisk
- name: Build the iso image
run: |
cd gigabyte-ampere-cuttlefish-installer
sed -i "2i CI_PROJECT_NAME=${CI_PROJECT_NAME}" preseed/after_install_1.sh
sed -i "3i CI_PIPELINE_ID=${CI_PIPELINE_ID}" preseed/after_install_1.sh
wget -nv -c ${DEBIAN_ISO_URL}
./addpreseed.sh
xz -9e preseed-mini.iso
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: gigabyte-ampere-cuttlefish-installer-artifacts
path: gigabyte-ampere-cuttlefish-installer/preseed-mini.iso.xz

test-iso:
needs: build-iso
runs-on: ubuntu-22.04
container:
image: debian:trixie # debian:trixie (amd64)
env:
TEST_DISK_SIZE: "10G"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: gigabyte-ampere-cuttlefish-installer-artifacts
- name: Prepare test environment
run: |
apt-get update
apt-get upgrade -y
apt-get install -y sudo
apt-get install -y debconf-utils
echo "tzdata tzdata/Areas select Etc" | debconf-set-selections -v
echo "tzdata tzdata/Zones/Etc select UTC" | debconf-set-selections -v
DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
dpkg-reconfigure --frontend noninteractive tzdata
echo "pbuilder pbuilder/mirrorsite string http://deb.debian.org/debian/" | debconf-set-selections -v
DEBIAN_FRONTEND=noninteractive apt-get install -y pbuilder
dpkg-reconfigure --frontend noninteractive pbuilder
apt-get install -y util-linux util-linux-extra
apt-get install -y xz-utils
apt-get install -y qemu-system-arm
apt-get install -y expect
apt-get install -y e2tools e2fsprogs
apt-get install -y guestfish
apt-get install -y lvm2
apt-get install -y ubuntu-dev-tools
apt-get install -y sshpass
apt-get install -y u-boot-qemu
- name: Run test
run: |
cd gigabyte-ampere-cuttlefish-installer
mv ../preseed-mini.iso.xz .
xz -d preseed-mini.iso.xz
chmod a-w preseed-mini.iso
cp -f tests/installer-iso-* .
./installer-iso-install.expect successful_install sheeFei2
./installer-iso-extract-partitions.sh
e2cp rootfs.img:/home/vsoc-01/successful_install successful_install
echo sheeFei2 > successful_install_compare
cmp successful_install successful_install_compare
e2cp boot.img:/$(e2ls boot.img:/vmlinuz-* | tail -1) .
test -e vmlinuz-
e2ls -l rootfs.img:/usr/bin/cvd_host_orchestrator | grep cvd_host_orchestrator | grep root
test '!' -e home.img
88 changes: 88 additions & 0 deletions gigabyte-ampere-cuttlefish-installer/addpreseed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/sh

BASEDIR=$(dirname $(realpath "$0"))

orig_iso=mini.iso
auto_extract_efi=1
efi_img=efi.img

new_files=iso_unpacked_and_modified
new_iso=preseed-mini.iso

PRESEEDFILE=$(realpath "${BASEDIR}"/preseed/preseed.cfg)
AFTERINSTALLSCRIPT=$(realpath "${BASEDIR}"/preseed/after_install_1.sh)

part_img_ready=1
if test "$auto_extract_efi" = 1; then
start_block=$(/sbin/fdisk -l "$orig_iso" | fgrep "$orig_iso"2 | \
awk '{print $2}')
block_count=$(/sbin/fdisk -l "$orig_iso" | fgrep "$orig_iso"2 | \
awk '{print $4}')
if test "$start_block" -gt 0 -a "$block_count" -gt 0 2>/dev/null
then
dd if="$orig_iso" bs=512 skip="$start_block" count="$block_count" \
of="$efi_img"
else
echo "Cannot read plausible start block and block count from fdisk" >&2
part_img_ready=0
fi
fi

# add preseed
mkdir ${new_files}
bsdtar -C ${new_files} -xf "$orig_iso"
cd ${new_files}
cp -f "${PRESEEDFILE}" preseed.cfg
cp -f "${AFTERINSTALLSCRIPT}" after_install_1.sh
chmod a+rx after_install_1.sh

# add preseed to console based installer
chmod ug+w initrd.gz
gzip -d -f initrd.gz
echo preseed.cfg | cpio -H newc -o -A -F initrd
echo after_install_1.sh | cpio -H newc -o -A -F initrd
gzip -9 initrd
chmod a-w initrd.gz
# add preseed to GTK based installer
chmod ug+w gtk
cd gtk
chmod ug+w initrd.gz
gzip -d -f initrd.gz
cp -f ../preseed.cfg .
cp -f ../after_install_1.sh .
echo preseed.cfg | cpio -H newc -o -A -F initrd
echo after_install_1.sh | cpio -H newc -o -A -F initrd
gzip -9 initrd
chmod a-w initrd.gz
rm -f preseed.cfg after_install_1.sh
cd ..
chmod a-w gtk
# modify Graphical installer to use tty1
chmod ug+w boot
chmod ug+w boot/grub
chmod ug+w boot/grub/grub.cfg
sed -i '0,/menuentry/{s#menuentry#menuentry '\''Ampere Install'\'' {\n set background_color=black\n linux /linux --- quiet console=tty1\n initrd /gtk/initrd.gz\n}\nmenuentry#}' boot/grub/grub.cfg
sed -i '0,/insmod gzio/{s#insmod gzio#set timeout=120\n\ninsmod gzio#}' boot/grub/grub.cfg
chmod a-w boot/grub/grub.cfg
chmod a-w boot/grub
chmod a-w boot
cd ..

rm -f "${new_iso}"

# Create the new ISO image if not partition extraction failed
test "$part_img_ready" = 1 && \
xorriso -as mkisofs \
-r -V 'Debian arm64 n' \
-o "$new_iso" \
-J -joliet-long -cache-inodes \
-e boot/grub/efi.img \
-no-emul-boot \
-append_partition 2 0xef "$efi_img" \
-partition_cyl_align all \
"$new_files"

# clean
rm -f efi.img
chmod ug+w -R "${new_files}"
rm -rf "${new_files}"
126 changes: 126 additions & 0 deletions gigabyte-ampere-cuttlefish-installer/preseed/after_install_1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/bin/sh

apt-get update

# Install necessary packages
apt-get install -y debconf-utils
apt-get install -y ca-certificates
apt-get install -y wget
apt-get install -y git
apt-get install -y python3
apt-get install -y p7zip-full unzip
apt-get install -y iptables ebtables
apt-get install -y curl
apt-get install -y lsb-release
apt-get install -y gpg
apt-get install -y jq

# Adjust user groups
adduser vsoc-01 kvm
adduser vsoc-01 render
adduser vsoc-01 video

# Detect distribution
DEBIAN_DISTRIBUTION="$(lsb_release -c -s)"
DEBIAN_ARCH="$(dpkg --print-architecture)"

apt -o Apt::Get::Assume-Yes=true -o APT::Color=0 -o DPkgPM::Progress-Fancy=0 \
update

# Install kernel
DEBIAN_DISTRIBUTION="$(lsb_release -c -s)"
#apt-get install -y '^linux-image-6.1.*aosp14-linaro.*' '^linux-headers-6.1.*aosp14-linaro.*'
has_backports=$(apt-cache policy | grep "${DEBIAN_DISTRIBUTION}-backports")
if [ x"$has_backports" != x"" ]; then
apt install -y -t "${DEBIAN_DISTRIBUTION}-backports" linux-headers-arm64
apt install -y -t "${DEBIAN_DISTRIBUTION}-backports" linux-image-arm64
fi

# Install nVidia or AMD GPU driver
nvidia_gpu=$(lspci | grep -i nvidia)
amd_gpu=$(lspci | grep VGA | grep AMD)
if [ x"$amd_gpu" != x"" ]; then
# # Install amd firmware
# if [ x"$has_backports" != x"" ]; then
# apt-get install -y -t ${DEBIAN_DISTRIBUTION}-backports firmware-amd-graphics
# else
# apt-get install -y firmware-amd-graphics
# fi
# sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT=\"\(.*\)\"/GRUB_CMDLINE_LINUX_DEFAULT=\"\1 amdgpu.runpm=0 amdgpu.dc=0\"/' /etc/default/grub
# dpkg-reconfigure -fnoninteractive grub-efi-arm64
echo "AMD GPU detected — skipping GPU driver installation."
elif [ x"$nvidia_gpu" != x"" ]; then
# Install nvidia driver
if [ x"$has_backports" != x"" ]; then
DEBIAN_FRONTEND=noninteractive apt-get install -y -t "${DEBIAN_DISTRIBUTION}-backports" -q --force-yes nvidia-kernel-dkms
DEBIAN_FRONTEND=noninteractive apt-get install -y -t "${DEBIAN_DISTRIBUTION}-backports" -q --force-yes nvidia-driver
DEBIAN_FRONTEND=noninteractive apt-get install -y -t "${DEBIAN_DISTRIBUTION}-backports" -q --force-yes firmware-misc-nonfree
else
DEBIAN_FRONTEND=noninteractive apt-get install -y -q --force-yes nvidia-open-kernel-dkms
DEBIAN_FRONTEND=noninteractive apt-get install -y -q --force-yes nvidia-driver
DEBIAN_FRONTEND=noninteractive apt-get install -y -q --force-yes firmware-misc-nonfree
fi
fi
# End of Install kernel

# Install android cuttlefish packages
curl -fsSL --retry 7 --retry-all-errors https://us-apt.pkg.dev/doc/repo-signing-key.gpg -o /etc/apt/trusted.gpg.d/artifact-registry.asc
chmod a+r /etc/apt/trusted.gpg.d/artifact-registry.asc
echo "deb https://us-apt.pkg.dev/projects/android-cuttlefish-artifacts android-cuttlefish main" \
| tee -a /etc/apt/sources.list.d/artifact-registry.list
apt-get update
apt-get install -y cuttlefish-base cuttlefish-user cuttlefish-orchestration -t android-cuttlefish
adduser vsoc-01 cvdnetwork

# Install gigabyte package
apt -o Apt::Get::Assume-Yes=true -o APT::Color=0 -o DPkgPM::Progress-Fancy=0 -o Acquire::Retries=5 install cuttlefish-integration-gigabyte-arm64

# Extra tools
cd /root
git clone https://github.com/matthuisman/gdrivedl.git
cd -

# Use iptables-legacy
update-alternatives --set iptables /usr/sbin/iptables-legacy

# Install network manager
apt-get install -y network-manager

# Network-manager workaround
rm -f '/etc/NetworkManager/system-connections/Wired connection 1'

# Install Docker container
# Add Docker's official GPG key:
apt-get update
curl -fsSL --retry 7 --retry-all-errors https://download.docker.com/linux/debian/gpg -o /etc/apt/trusted.gpg.d/docker.asc
chmod a+r /etc/apt/trusted.gpg.d/docker.asc

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y -q docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
usermod -aG docker vsoc-01

# Inastall nvidia-container-toolkit
curl -fsSL --retry 7 --retry-all-errors https://nvidia.github.io/libnvidia-container/gpgkey | gpg --dearmor -o /etc/apt/trusted.gpg.d/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y -q --force-yes nvidia-container-toolkit

# Install container image
DEBIAN_FRONTEND=noninteractive apt-get install -y -q --force-yes skopeo
ORCHESTRATION_IMAGE="us-docker.pkg.dev/android-cuttlefish-artifacts/cuttlefish-orchestration/cuttlefish-orchestration"
STABLE_DIGEST=$(skopeo inspect docker://${ORCHESTRATION_IMAGE}:stable --format '{{.Digest}}')
CANDIDATES=$(skopeo list-tags docker://${ORCHESTRATION_IMAGE} | jq -r '.Tags[] | select(test("^[0-9]+\\.[0-9]+\\.[0-9]+$"))' | sort -V -r)
ORCHESTRATION_TAG=""
for CANDIDATE in $CANDIDATES; do
DIGEST=$(skopeo inspect docker://${ORCHESTRATION_IMAGE}:${CANDIDATE} --format '{{.Digest}}')
if [ "$DIGEST" = "$STABLE_DIGEST" ]; then
ORCHESTRATION_TAG=${CANDIDATE}
break
fi
done
docker pull ${ORCHESTRATION_IMAGE}:${ORCHESTRATION_TAG}
Loading
Loading