1#!/bin/sh 2# 3# Copyright (C) 2018 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 18chroot_sanity_check() { 19 if [ ! -f /var/log/bootstrap.log ]; then 20 echo "Do not run this script directly!" 21 echo "This is supposed to be run from inside a debootstrap chroot!" 22 echo "Aborting." 23 exit 1 24 fi 25} 26 27chroot_cleanup() { 28 # Read-only root breaks booting via init 29 cat >/etc/fstab << EOF 30tmpfs /tmp tmpfs defaults 0 0 31tmpfs /var/log tmpfs defaults 0 0 32tmpfs /var/tmp tmpfs defaults 0 0 33EOF 34 35 # systemd will attempt to re-create this symlink if it does not exist, 36 # which fails if it is booting from a read-only root filesystem (which 37 # is normally the case). The syslink must be relative, not absolute, 38 # and it must point to /proc/self/mounts, not /proc/mounts. 39 ln -sf ../proc/self/mounts /etc/mtab 40 41 # Remove contaminants coming from the debootstrap process 42 echo vm >/etc/hostname 43 echo "nameserver 127.0.0.1" >/etc/resolv.conf 44 45 # Put the helper net_test.sh script into place 46 mv /root/net_test.sh /sbin/net_test.sh 47 48 # Make sure the /host mountpoint exists for net_test.sh 49 mkdir /host 50 51 # Disable the root password 52 passwd -d root 53 54 # Clean up any junk created by the imaging process 55 rm -rf /var/lib/apt/lists/* /var/log/bootstrap.log /root/* /tmp/* 56 find /var/log -type f -exec rm -f '{}' ';' 57} 58