#!/bin/sh # # Copyright (C) 2021 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. # trap "echo 3 >${exitcode}" ERR # $1 - Suite names for apt sources # $2 - Additional repos, if any update_apt_sources() { # Add the needed debian sources cat >/etc/apt/sources.list << EOF EOF for source in $1; do cat >>/etc/apt/sources.list </etc/apt/apt.conf.d/90recommends </etc/resolv.conf echo "nameserver 8.8.4.4" >>/etc/resolv.conf } # $1 - Network interface for bridge (or traditional DHCP) # $2 - Bridge name. If not specified, no bridge is configured setup_dynamic_networking() { # So isc-dhcp-client can work with a read-only rootfs.. cat >>/etc/fstab </run/resolvconf/resolv.conf echo "nameserver 8.8.4.4" >>/run/resolvconf/resolv.conf # Set up automatic DHCP for *future* boots if [ -z "$2" ]; then cat >/etc/network/interfaces.d/$1.conf </etc/network/interfaces.d/$2.conf <>/etc/security/limits.conf } # $* - One or more device names for getty spawns create_systemd_getty_symlinks() { for device in $*; do ln -s /lib/systemd/system/serial-getty\@.service \ /etc/systemd/system/getty.target.wants/serial-getty\@"${device}".service done } # $1 - Additional default command line setup_grub() { if [[ "${embed_kernel_initrd_dtb}" = "0" && "${install_grub}" = "0" ]]; then return fi if [[ "${install_grub}" = "1" ]]; then # Mount fstab entry added by stage2 findmnt /boot/efi > /dev/null 2>&1 if [ $? != 0 ]; then mount /boot/efi fi # Install GRUB EFI (removable, for Cloud) apt-get install -y grub-efi grub_arch="$(uname -m)" # Remap some mismatches with uname -m [ "${grub_arch}" = "i686" ] && grub_arch=i386 [ "${grub_arch}" = "aarch64" ] && grub_arch=arm64 grub-install --target "${grub_arch}-efi" --removable else # Install common grub components apt-get install -y grub2-common mkdir /boot/grub fi cat >/etc/default/grub <"${exitcode}" sync && poweroff -f }