Modify customize_rootfs.sh to run outside of the target rootfs and to use

only host-based tools. This is a requirement in order to be able to build
a cross-compiled image where the target rootfs is a different arch than
the host.

Review URL: http://codereview.chromium.org/500014
This commit is contained in:
tedbo 2009-12-16 13:27:31 -08:00
parent 962d1ec49a
commit 9db99b88c1
2 changed files with 141 additions and 93 deletions

View File

@ -184,7 +184,6 @@ sudo mount --bind "$GCLIENT_ROOT" "$ROOT_FS_DIR/trunk"
mkdir -p "$SETUP_DIR" mkdir -p "$SETUP_DIR"
mkdir -p "${SETUP_DIR}/local_packages" mkdir -p "${SETUP_DIR}/local_packages"
cp "${SCRIPTS_DIR}/${ROOTFS_PACKAGE_INSTALL_SCRIPT}" "$SETUP_DIR" cp "${SCRIPTS_DIR}/${ROOTFS_PACKAGE_INSTALL_SCRIPT}" "$SETUP_DIR"
cp "${SCRIPTS_DIR}/${ROOTFS_CUSTOMIZE_SCRIPT}" "$SETUP_DIR"
cp -r "$ROOTFS_STATIC_DATA" "$SETUP_DIR" cp -r "$ROOTFS_STATIC_DATA" "$SETUP_DIR"
cp "$FLAGS_pkglist" "${SETUP_DIR}/package-list-prod.txt" cp "$FLAGS_pkglist" "${SETUP_DIR}/package-list-prod.txt"
cp "${FLAGS_build_root}/x86/local_packages"/* "${SETUP_DIR}/local_packages" cp "${FLAGS_build_root}/x86/local_packages"/* "${SETUP_DIR}/local_packages"
@ -224,7 +223,7 @@ sudo chroot "$ROOT_FS_DIR" \
"${ROOTFS_SETUP_DIR}/${ROOTFS_PACKAGE_INSTALL_SCRIPT}" "${ROOTFS_SETUP_DIR}/${ROOTFS_PACKAGE_INSTALL_SCRIPT}"
# Run the script to customize the resulting root file system. # Run the script to customize the resulting root file system.
sudo chroot "$ROOT_FS_DIR" "${ROOTFS_SETUP_DIR}/${ROOTFS_CUSTOMIZE_SCRIPT}" "${SCRIPTS_DIR}/${ROOTFS_CUSTOMIZE_SCRIPT}" --root="${ROOT_FS_DIR}"
# No longer need the setup directory in the rootfs. # No longer need the setup directory in the rootfs.
rm -rf "$SETUP_DIR" rm -rf "$SETUP_DIR"

View File

@ -1,33 +1,53 @@
#!/bin/sh #!/bin/bash
# Copyright (c) 2009 The Chromium OS Authors. All rights reserved. # Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
# Customizes the root file system of a chromium-based os. # Script to customize the root file system after packages have been installed.
#
# NOTE: This script should be called by build_image.sh. Do not run this # NOTE: This script should be called by build_image.sh. Do not run this
# on your own unless you know what you are doing. # on your own unless you know what you are doing.
# Load common constants. This should be the first executable line.
# The path to common.sh should be relative to your script's location.
. "$(dirname "$0")/common.sh"
# Script must be run inside the chroot
assert_inside_chroot
# Flags
DEFINE_string target "x86" \
"The target architecture to build for. One of { x86, arm }."
DEFINE_string root "" \
"The root file system to customize."
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on any errors.
set -e set -e
SETUP_DIR=$(dirname $0) ROOT_FS_DIR="$FLAGS_root"
if [[ -z "$ROOT_FS_DIR" ]]; then
# Read options from the config file created by build_image.sh. echo "Error: --root is required."
echo "Reading options..." exit 1
cat "${SETUP_DIR}/customize_opts.sh" fi
. "${SETUP_DIR}/customize_opts.sh" if [[ ! -d "$ROOT_FS_DIR" ]]; then
echo "Error: Root FS does not exist? ($ROOT_FS_DIR)"
exit 1
fi
# Determine default user full username.
if [ ${CHROMEOS_OFFICIAL:-0} = 1 ]; then if [ ${CHROMEOS_OFFICIAL:-0} = 1 ]; then
FULLNAME="Google Chrome OS User" FULLNAME="Google Chrome OS User"
else else
FULLNAME="Chromium OS User" FULLNAME="Chromium OS User"
fi fi
USERNAME="chronos"
ADMIN_GROUP="admin"
DEFGROUPS="adm,dialout,cdrom,floppy,audio,dip,video"
ADMIN_USERNAME="chronosdev"
CRYPTED_PASSWD_FILE="/trunk/src/scripts/shared_user_passwd.txt" # Determine what password to use for the default user.
CRYPTED_PASSWD_FILE="${SCRIPTS_DIR}/shared_user_passwd.txt"
if [ -f $CRYPTED_PASSWD_FILE ]; then if [ -f $CRYPTED_PASSWD_FILE ]; then
echo "Using password from $CRYPTED_PASSWD_FILE" echo "Using password from $CRYPTED_PASSWD_FILE"
CRYPTED_PASSWD=$(cat $CRYPTED_PASSWD_FILE) CRYPTED_PASSWD=$(cat $CRYPTED_PASSWD_FILE)
@ -39,11 +59,33 @@ else
PASSWORD="gone now" PASSWORD="gone now"
fi fi
# Set up a default user and add to sudo and the required groups.
USERNAME="chronos"
SHELL="/bin/sh"
if [[ -x "${ROOT_FS_DIR}/bin/bash" ]] ; then
SHELL="/bin/bash"
fi
echo "${USERNAME}:x:1000:1000:${FULLNAME}:/home/${USERNAME}/:${SHELL}" | \
sudo dd of="${ROOT_FS_DIR}/etc/passwd" conv=notrunc oflag=append
echo "${USERNAME}:${CRYPTED_PASSWD}:14500:0:99999::::" | \
sudo dd of="${ROOT_FS_DIR}/etc/shadow" conv=notrunc oflag=append
echo "${USERNAME}:x:1000:" | \
sudo dd of="${ROOT_FS_DIR}/etc/group" conv=notrunc oflag=append
# TODO: Add USERNAME to adm,dialout,cdrom,floppy,audio,dip,video groups?
sudo mkdir -p "${ROOT_FS_DIR}/home/${USERNAME}"
sudo chown 1000.1000 "${ROOT_FS_DIR}/home/${USERNAME}"
cat <<EOF | sudo dd of="${ROOT_FS_DIR}/etc/sudoers" conv=notrunc oflag=append
%adm ALL=(ALL) ALL
$USERNAME ALL=(ALL) ALL
EOF
sudo chmod 0440 "${ROOT_FS_DIR}/etc/sudoers"
# Set CHROMEOS_VERSION_DESCRIPTION here (uses vars set in chromeos_version.sh) # Set CHROMEOS_VERSION_DESCRIPTION here (uses vars set in chromeos_version.sh)
# Was removed from chromeos_version.sh which can also be run outside of chroot # Was removed from chromeos_version.sh which can also be run outside of chroot
# where CHROMEOS_REVISION is set # where CHROMEOS_REVISION is set
# We have to set (in build_image.sh) and use REAL_USER due to many nested # We have to set (in build_image.sh) and use REAL_USER due to many nested
# chroots which lose $USER state. # chroots which lose $USER state.
. "${SCRIPTS_DIR}/chromeos_version.sh"
if [ ${CHROMEOS_OFFICIAL:-0} = 1 ]; then if [ ${CHROMEOS_OFFICIAL:-0} = 1 ]; then
export CHROMEOS_VERSION_DESCRIPTION="${CHROMEOS_VERSION_STRING} (Official Build ${CHROMEOS_REVISION:?})" export CHROMEOS_VERSION_DESCRIPTION="${CHROMEOS_VERSION_STRING} (Official Build ${CHROMEOS_REVISION:?})"
elif [ "$REAL_USER" = "chrome-bot" ] elif [ "$REAL_USER" = "chrome-bot" ]
@ -63,7 +105,7 @@ fi
# update service. # update service.
# TODO(skrul): Remove GOOGLE_RELEASE once Chromium is updated to look at # TODO(skrul): Remove GOOGLE_RELEASE once Chromium is updated to look at
# CHROMEOS_RELEASE_VERSION for UserAgent data. # CHROMEOS_RELEASE_VERSION for UserAgent data.
cat <<EOF >> /etc/lsb-release cat <<EOF | sudo dd of="${ROOT_FS_DIR}/etc/lsb-release"
CHROMEOS_RELEASE_CODENAME=$CHROMEOS_VERSION_CODENAME CHROMEOS_RELEASE_CODENAME=$CHROMEOS_VERSION_CODENAME
CHROMEOS_RELEASE_DESCRIPTION=$CHROMEOS_VERSION_DESCRIPTION CHROMEOS_RELEASE_DESCRIPTION=$CHROMEOS_VERSION_DESCRIPTION
CHROMEOS_RELEASE_NAME=$CHROMEOS_VERSION_NAME CHROMEOS_RELEASE_NAME=$CHROMEOS_VERSION_NAME
@ -76,126 +118,133 @@ EOF
# Turn user metrics logging on for official builds only. # Turn user metrics logging on for official builds only.
if [ ${CHROMEOS_OFFICIAL:-0} -eq 1 ]; then if [ ${CHROMEOS_OFFICIAL:-0} -eq 1 ]; then
touch /etc/send_metrics sudo touch "${ROOT_FS_DIR}/etc/send_metrics"
fi fi
# Create the admin group and a chronos user that can act as admin.
groupadd ${ADMIN_GROUP}
echo "%admin ALL=(ALL) ALL" >> /etc/sudoers
useradd -G "${ADMIN_GROUP},${DEFGROUPS}" -g ${ADMIN_GROUP} -s /bin/bash -m \
-c "${FULLNAME}" -p ${CRYPTED_PASSWD} ${USERNAME}
# Set timezone symlink # Set timezone symlink
rm -f /etc/localtime sudo rm -f "${ROOT_FS_DIR}/etc/localtime"
ln -s /mnt/stateful_partition/etc/localtime /etc/localtime sudo ln -s /mnt/stateful_partition/etc/localtime "${ROOT_FS_DIR}/etc/localtime"
# make a mountpoint for stateful partition # make a mountpoint for stateful partition
sudo mkdir -p "$ROOTFS_DIR"/mnt/stateful_partition sudo mkdir -p "$ROOT_FS_DIR"/mnt/stateful_partition
sudo chmod 0755 "$ROOTFS_DIR"/mnt sudo chmod 0755 "$ROOT_FS_DIR"/mnt
sudo chmod 0755 "$ROOTFS_DIR"/mnt/stateful_partition sudo chmod 0755 "$ROOT_FS_DIR"/mnt/stateful_partition
# Copy everything from the rootfs_static_data directory to the corresponding # Copy everything from the rootfs_static_data directory to the corresponding
# place on the filesystem. Note that this step has to occur after we've # place on the filesystem. Note that this step has to occur after we've
# installed all of the packages but before we remove the setup dir. # installed all of the packages.
chmod -R a+rX "${SETUP_DIR}/rootfs_static_data/." TMP_STATIC=$(mktemp -d)
cp -r "${SETUP_DIR}/rootfs_static_data/common/." / sudo cp -r "${SRC_ROOT}/rootfs_static_data/common/." "$TMP_STATIC"
# TODO: Copy additional target-platform-specific subdirectories. # TODO: Copy additional target-platform-specific subdirectories.
sudo chmod -R a+rX "$TMP_STATIC/."
sudo cp -r "$TMP_STATIC/." "$ROOT_FS_DIR"
sudo rm -rf "$TMP_STATIC"
# Fix issue where alsa-base (dependency of alsa-utils) is messing up our sound # Fix issue where alsa-base (dependency of alsa-utils) is messing up our sound
# drivers. The stock modprobe settings worked fine. # drivers. The stock modprobe settings worked fine.
# TODO: Revisit when we have decided on how sound will work on chromeos. # TODO: Revisit when we have decided on how sound will work on chromeos.
rm /etc/modprobe.d/alsa-base.conf sudo rm "${ROOT_FS_DIR}/etc/modprobe.d/alsa-base.conf"
# Remove unneeded fonts. # Remove unneeded fonts.
rm -rf /usr/share/fonts/X11 sudo rm -rf "${ROOT_FS_DIR}/usr/share/fonts/X11"
# The udev daemon takes a long time to start up and settle so we defer it until # The udev daemon takes a long time to start up and settle so we defer it until
# after X11 has been started. In order to be able to mount the root file system # after X11 has been started. In order to be able to mount the root file system
# and start X we pre-populate some devices. These are copied into /dev by the # and start X we pre-populate some devices. These are copied into /dev by the
# chromeos_startup script. # chromeos_startup script.
UDEV_DEVICES=/lib/udev/devices # TODO: There is no good reason to put this in /lib/udev/devices. Move it.
mkdir "$UDEV_DEVICES"/dri # TODO: Hopefully some of this can be taken care of by devtmpfs.
mkdir "$UDEV_DEVICES"/input UDEV_DEVICES="${ROOT_FS_DIR}/lib/udev/devices"
mknod --mode=0600 "$UDEV_DEVICES"/initctl p sudo mkdir -p "$UDEV_DEVICES"/dri
mknod --mode=0660 "$UDEV_DEVICES"/tty0 c 4 0 sudo mkdir -p "$UDEV_DEVICES"/input
mknod --mode=0660 "$UDEV_DEVICES"/tty1 c 4 1 sudo mkdir -p "$UDEV_DEVICES"/pts
mknod --mode=0660 "$UDEV_DEVICES"/tty2 c 4 2 sudo mkdir -p "$UDEV_DEVICES"/shm
mknod --mode=0666 "$UDEV_DEVICES"/tty c 5 0 sudo ln -sf /proc/self/fd/0 "$UDEV_DEVICES"/stdin
mknod --mode=0666 "$UDEV_DEVICES"/ptmx c 5 2 sudo ln -sf /proc/self/fd/0 "$UDEV_DEVICES"/stdout
mknod --mode=0640 "$UDEV_DEVICES"/mem c 1 1 sudo ln -sf /proc/self/fd/0 "$UDEV_DEVICES"/stderr
mknod --mode=0666 "$UDEV_DEVICES"/zero c 1 5 sudo mknod --mode=0600 "$UDEV_DEVICES"/initctl p
mknod --mode=0666 "$UDEV_DEVICES"/random c 1 8 sudo mknod --mode=0660 "$UDEV_DEVICES"/tty0 c 4 0
mknod --mode=0666 "$UDEV_DEVICES"/urandom c 1 9 sudo mknod --mode=0660 "$UDEV_DEVICES"/tty1 c 4 1
mknod --mode=0660 "$UDEV_DEVICES"/sda b 8 0 sudo mknod --mode=0660 "$UDEV_DEVICES"/tty2 c 4 2
mknod --mode=0660 "$UDEV_DEVICES"/sda1 b 8 1 sudo mknod --mode=0666 "$UDEV_DEVICES"/tty c 5 0
mknod --mode=0660 "$UDEV_DEVICES"/sda2 b 8 2 sudo mknod --mode=0660 "$UDEV_DEVICES"/ttyMSM2 c 252 2
mknod --mode=0660 "$UDEV_DEVICES"/sda3 b 8 3 if [ ! -c "$UDEV_DEVICES"/console ]; then
mknod --mode=0660 "$UDEV_DEVICES"/sda4 b 8 4 sudo mknod --mode=0600 "$UDEV_DEVICES"/console c 5 1
mknod --mode=0660 "$UDEV_DEVICES"/sdb b 8 16 fi
mknod --mode=0660 "$UDEV_DEVICES"/sdb1 b 8 17 sudo mknod --mode=0666 "$UDEV_DEVICES"/ptmx c 5 2
mknod --mode=0660 "$UDEV_DEVICES"/sdb2 b 8 18 sudo mknod --mode=0640 "$UDEV_DEVICES"/mem c 1 1
mknod --mode=0660 "$UDEV_DEVICES"/sdb3 b 8 19 if [ ! -c "$UDEV_DEVICES"/null ]; then
mknod --mode=0660 "$UDEV_DEVICES"/sdb4 b 8 20 sudo mknod --mode=0666 "$UDEV_DEVICES"/null c 1 3
mknod --mode=0660 "$UDEV_DEVICES"/fb0 c 29 0 fi
mknod --mode=0660 "$UDEV_DEVICES"/dri/card0 c 226 0 sudo mknod --mode=0666 "$UDEV_DEVICES"/zero c 1 5
mknod --mode=0640 "$UDEV_DEVICES"/input/mouse0 c 13 32 sudo mknod --mode=0666 "$UDEV_DEVICES"/random c 1 8
mknod --mode=0640 "$UDEV_DEVICES"/input/mice c 13 63 sudo mknod --mode=0666 "$UDEV_DEVICES"/urandom c 1 9
mknod --mode=0640 "$UDEV_DEVICES"/input/event0 c 13 64 sudo mknod --mode=0660 "$UDEV_DEVICES"/sda b 8 0
mknod --mode=0640 "$UDEV_DEVICES"/input/event1 c 13 65 sudo mknod --mode=0660 "$UDEV_DEVICES"/sda1 b 8 1
mknod --mode=0640 "$UDEV_DEVICES"/input/event2 c 13 66 sudo mknod --mode=0660 "$UDEV_DEVICES"/sda2 b 8 2
mknod --mode=0640 "$UDEV_DEVICES"/input/event3 c 13 67 sudo mknod --mode=0660 "$UDEV_DEVICES"/sda3 b 8 3
mknod --mode=0640 "$UDEV_DEVICES"/input/event4 c 13 68 sudo mknod --mode=0660 "$UDEV_DEVICES"/sda4 b 8 4
mknod --mode=0640 "$UDEV_DEVICES"/input/event5 c 13 69 sudo mknod --mode=0660 "$UDEV_DEVICES"/sdb b 8 16
mknod --mode=0640 "$UDEV_DEVICES"/input/event6 c 13 70 sudo mknod --mode=0660 "$UDEV_DEVICES"/sdb1 b 8 17
mknod --mode=0640 "$UDEV_DEVICES"/input/event7 c 13 71 sudo mknod --mode=0660 "$UDEV_DEVICES"/sdb2 b 8 18
mknod --mode=0640 "$UDEV_DEVICES"/input/event8 c 13 72 sudo mknod --mode=0660 "$UDEV_DEVICES"/sdb3 b 8 19
chown root.tty "$UDEV_DEVICES"/tty* sudo mknod --mode=0660 "$UDEV_DEVICES"/sdb4 b 8 20
chown root.kmem "$UDEV_DEVICES"/mem sudo mknod --mode=0660 "$UDEV_DEVICES"/fb0 c 29 0
chown root.disk "$UDEV_DEVICES"/sda* sudo mknod --mode=0660 "$UDEV_DEVICES"/dri/card0 c 226 0
chown root.video "$UDEV_DEVICES"/fb0 sudo mknod --mode=0640 "$UDEV_DEVICES"/input/mouse0 c 13 32
chown root.video "$UDEV_DEVICES"/dri/card0 sudo mknod --mode=0640 "$UDEV_DEVICES"/input/mice c 13 63
chmod 0666 "$UDEV_DEVICES"/null # Fix misconfiguration of /dev/null sudo mknod --mode=0640 "$UDEV_DEVICES"/input/event0 c 13 64
sudo mknod --mode=0640 "$UDEV_DEVICES"/input/event1 c 13 65
sudo mknod --mode=0640 "$UDEV_DEVICES"/input/event2 c 13 66
sudo mknod --mode=0640 "$UDEV_DEVICES"/input/event3 c 13 67
sudo mknod --mode=0640 "$UDEV_DEVICES"/input/event4 c 13 68
sudo mknod --mode=0640 "$UDEV_DEVICES"/input/event5 c 13 69
sudo mknod --mode=0640 "$UDEV_DEVICES"/input/event6 c 13 70
sudo mknod --mode=0640 "$UDEV_DEVICES"/input/event7 c 13 71
sudo mknod --mode=0640 "$UDEV_DEVICES"/input/event8 c 13 72
sudo chown root.tty "$UDEV_DEVICES"/tty*
sudo chown root.kmem "$UDEV_DEVICES"/mem
sudo chown root.disk "$UDEV_DEVICES"/sda*
sudo chown root.video "$UDEV_DEVICES"/fb0
sudo chown root.video "$UDEV_DEVICES"/dri/card0
sudo chmod 0666 "$UDEV_DEVICES"/null # Fix misconfiguration of /dev/null
# Since we may mount read-only, our mtab should symlink to /proc # Since we may mount read-only, our mtab should symlink to /proc
ln -sf /proc/mounts /etc/mtab sudo ln -sf /proc/mounts "${ROOT_FS_DIR}/etc/mtab"
# For the most part, we use our own set of Upstart jobs that were installed # For the most part, we use our own set of Upstart jobs that were installed
# in /etc/init.chromeos so as not to mingle with jobs installed by various # in /etc/init.chromeos so as not to mingle with jobs installed by various
# packages. We fix that up now. # packages. We fix that up now.
cp /etc/init/tty2.conf /etc/init.chromeos sudo cp "${ROOT_FS_DIR}/etc/init/tty2.conf" "${ROOT_FS_DIR}/etc/init.chromeos"
rm -rf /etc/init sudo rm -rf "${ROOT_FS_DIR}/etc/init"
mv /etc/init.chromeos /etc/init sudo mv "${ROOT_FS_DIR}/etc/init.chromeos" "${ROOT_FS_DIR}/etc/init"
# By default, xkb writes computed configuration data to # By default, xkb writes computed configuration data to
# /var/lib/xkb. It can re-use this data to reduce startup # /var/lib/xkb. It can re-use this data to reduce startup
# time. In addition, if it fails to write we've observed # time. In addition, if it fails to write we've observed
# keyboard issues. We add a symlink to allow these writes. # keyboard issues. We add a symlink to allow these writes.
rm -rf /var/lib/xkb sudo rm -rf "${ROOT_FS_DIR}/var/lib/xkb"
ln -s /var/cache /var/lib/xkb sudo ln -s /var/cache "${ROOT_FS_DIR}/var/lib/xkb"
# This is needed so that devicekit-disks has a place to # This is needed so that devicekit-disks has a place to
# put its sql lite database. Since we do not need to # put its sql lite database. Since we do not need to
# retain this information across boots, we are just # retain this information across boots, we are just
# putting it in /var/tmp # putting it in /var/tmp
rm -rf /var/lib/DeviceKit-disks sudo rm -rf "${ROOT_FS_DIR}/var/lib/DeviceKit-disks"
ln -s /var/tmp /var/lib/DeviceKit-disks sudo ln -s /var/tmp "${ROOT_FS_DIR}/var/lib/DeviceKit-disks"
# Remove pam-mount's default entry in common-auth and common-session # Remove pam-mount's default entry in common-auth and common-session
sed -i 's/^\(.*pam_mount.so.*\)/#\1/g' /etc/pam.d/common-* sudo sed -i 's/^\(.*pam_mount.so.*\)/#\1/g' "${ROOT_FS_DIR}"/etc/pam.d/common-*
# List all packages still installed post-pruning
sudo sh -c "/trunk/src/scripts/list_installed_packages.sh \
> /etc/package_list_pruned.txt"
# Clear the network settings. This must be done last, since it prevents # Clear the network settings. This must be done last, since it prevents
# any subsequent steps from accessing the network. # any subsequent steps from accessing the network.
cat <<EOF > /etc/network/interfaces cat <<EOF | sudo dd of="${ROOT_FS_DIR}/etc/network/interfaces"
auto lo auto lo
iface lo inet loopback iface lo inet loopback
EOF EOF
cat <<EOF > /etc/resolv.conf cat <<EOF | sudo dd of="${ROOT_FS_DIR}/etc/resolv.conf"
# Use the connman dns proxy. # Use the connman dns proxy.
nameserver 127.0.0.1 nameserver 127.0.0.1
EOF EOF
chmod a-wx /etc/resolv.conf sudo chmod a-wx "${ROOT_FS_DIR}/etc/resolv.conf"