Merge pull request #95 from marineam/sdk-on-coreos

SDK on CoreOS
This commit is contained in:
Michael Marineau 2013-08-25 20:19:39 -07:00
commit 309e247b9a
3 changed files with 93 additions and 64 deletions

View File

@ -32,11 +32,6 @@ cleanup_mounts() {
safe_umount_tree "${esp_fs_dir}" safe_umount_tree "${esp_fs_dir}"
safe_umount_tree "${oem_fs_dir}" safe_umount_tree "${oem_fs_dir}"
if [[ -n "${loop_dev}" ]]; then
sudo losetup -d "${loop_dev}"
loop_dev=
fi
# Turn die on error back on. # Turn die on error back on.
set -e set -e
} }
@ -64,33 +59,36 @@ create_base_image() {
trap "cleanup_mounts && delete_prompt" EXIT trap "cleanup_mounts && delete_prompt" EXIT
cleanup_mounts &> /dev/null cleanup_mounts &> /dev/null
write_partition_table "${image_type}" "${BUILD_DIR}/${image_name}"
loop_dev=$(sudo losetup -P -f --show "${BUILD_DIR}/${image_name}")
local fs_block_size=$(get_fs_block_size)
local root_fs_label="ROOT-A" local root_fs_label="ROOT-A"
local root_fs_num=$(get_num ${image_type} ${root_fs_label}) local root_fs_num=$(get_num ${image_type} ${root_fs_label})
local root_fs_dev="${loop_dev}p${root_fs_num}" local root_fs_img="${BUILD_DIR}/rootfs.image"
local root_fs_bytes=$(get_filesystem_size ${image_type} ${root_fs_num}) local root_fs_bytes=$(get_filesystem_size ${image_type} ${root_fs_num})
local root_fs_blocks=$((root_fs_bytes / fs_block_size))
local state_fs_label="STATE" local state_fs_label="STATE"
local state_fs_num=$(get_num ${image_type} ${state_fs_label}) local state_fs_num=$(get_num ${image_type} ${state_fs_label})
local state_fs_dev="${loop_dev}p${state_fs_num}" local state_fs_img="${BUILD_DIR}/state.image"
local state_fs_bytes=$(get_filesystem_size ${image_type} ${state_fs_num})
local state_fs_uuid=$(uuidgen)
local esp_fs_label="EFI-SYSTEM" local esp_fs_label="EFI-SYSTEM"
local esp_fs_num=$(get_num ${image_type} ${esp_fs_label}) local esp_fs_num=$(get_num ${image_type} ${esp_fs_label})
local esp_fs_dev="${loop_dev}p${esp_fs_num}" local esp_fs_img="${BUILD_DIR}/esp.image"
local esp_fs_bytes=$(get_filesystem_size ${image_type} ${esp_fs_num})
local oem_fs_label="OEM" local oem_fs_label="OEM"
local oem_fs_num=$(get_num ${image_type} ${oem_fs_label}) local oem_fs_num=$(get_num ${image_type} ${oem_fs_label})
local oem_fs_dev="${loop_dev}p${oem_fs_num}" local oem_fs_img="${BUILD_DIR}/oem.image"
local oem_fs_bytes=$(get_filesystem_size ${image_type} ${oem_fs_num})
local oem_fs_uuid=$(uuidgen)
local fs_block_size=$(get_fs_block_size)
# Build root FS image. # Build root FS image.
info "Building ROOT filesystem" info "Building ${root_fs_img}"
sudo mkfs.ext2 -F -q -b ${fs_block_size} "${root_fs_dev}" "${root_fs_blocks}" truncate --size="${root_fs_bytes}" "${root_fs_img}"
sudo tune2fs -L "${root_fs_label}" \ /sbin/mkfs.ext2 -F -q -b ${fs_block_size} "${root_fs_img}" \
"$((root_fs_bytes / fs_block_size))"
/sbin/tune2fs -L "${root_fs_label}" \
-U clear \ -U clear \
-T 20091119110000 \ -T 20091119110000 \
-c 0 \ -c 0 \
@ -98,33 +96,34 @@ create_base_image() {
-m 0 \ -m 0 \
-r 0 \ -r 0 \
-e remount-ro \ -e remount-ro \
"${root_fs_dev}" "${root_fs_img}"
mkdir -p "${root_fs_dir}" mkdir -p "${root_fs_dir}"
sudo mount "${root_fs_dev}" "${root_fs_dir}" sudo mount -o loop "${root_fs_img}" "${root_fs_dir}"
df -h "${root_fs_dir}"
# Build state FS disk image. # Build state FS disk image.
info "Building STATE filesystem" info "Building ${state_fs_img}"
sudo mkfs.ext4 -F -q "${state_fs_dev}" truncate --size="${state_fs_bytes}" "${state_fs_img}"
sudo tune2fs -L "${state_fs_label}" \ /sbin/mkfs.ext4 -F -q "${state_fs_img}"
-c 0 \ /sbin/tune2fs -L "${state_fs_label}" -U "${state_fs_uuid}" \
-i 0 \ -c 0 -i 0 "${state_fs_img}"
"${state_fs_dev}"
mkdir -p "${state_fs_dir}" mkdir -p "${state_fs_dir}"
sudo mount "${state_fs_dev}" "${state_fs_dir}" sudo mount -o loop "${state_fs_img}" "${state_fs_dir}"
# Build ESP disk image. # Build ESP disk image.
info "Building ESP filesystem" info "Building ${esp_fs_img}"
sudo mkfs.vfat "${esp_fs_dev}" truncate --size="${esp_fs_bytes}" "${esp_fs_img}"
/usr/sbin/mkfs.vfat "${esp_fs_img}"
# Build OEM FS disk image. # Build OEM FS disk image.
info "Building OEM filesystem" info "Building ${oem_fs_img}"
sudo mkfs.ext4 -F -q "${oem_fs_dev}" truncate --size="${oem_fs_bytes}" "${oem_fs_img}"
sudo tune2fs -L "${oem_fs_label}" \ /sbin/mkfs.ext4 -F -q "${oem_fs_img}"
-c 0 \ /sbin/tune2fs -L "${oem_fs_label}" -U "${oem_fs_uuid}" \
-i 0 \ -c 0 -i 0 "${oem_fs_img}"
"${oem_fs_dev}"
mkdir -p "${oem_fs_dir}" mkdir -p "${oem_fs_dir}"
sudo mount "${oem_fs_dev}" "${oem_fs_dir}" sudo mount -o loop "${oem_fs_img}" "${oem_fs_dir}"
# Prepare state partition with some pre-created directories. # Prepare state partition with some pre-created directories.
for i in ${ROOT_OVERLAYS}; do for i in ${ROOT_OVERLAYS}; do
@ -269,6 +268,16 @@ create_base_image() {
cleanup_mounts cleanup_mounts
# Create the GPT-formatted image.
build_gpt "${BUILD_DIR}/${image_name}" \
"${root_fs_img}" \
"${state_fs_img}" \
"${esp_fs_img}" \
"${oem_fs_img}"
# Clean up temporary files.
rm -f "${root_fs_img}" "${state_fs_img}" "${esp_fs_img}" "{oem_fs_img}"
# Emit helpful scripts for testers, etc. # Emit helpful scripts for testers, etc.
emit_gpt_scripts "${BUILD_DIR}/${image_name}" "${BUILD_DIR}" emit_gpt_scripts "${BUILD_DIR}/${image_name}" "${BUILD_DIR}"

View File

@ -41,9 +41,6 @@ install_dev_packages() {
sudo mkdir -p ${root_fs_dir}/etc/make.profile sudo mkdir -p ${root_fs_dir}/etc/make.profile
# Re-run ldconfig to fix /etc/ldconfig.so.cache.
sudo /sbin/ldconfig -r "${root_fs_dir}"
# Mark the image as a developer image (input to chromeos_startup). # Mark the image as a developer image (input to chromeos_startup).
# TODO(arkaitzr): Remove this file when applications no longer rely on it # TODO(arkaitzr): Remove this file when applications no longer rely on it
# (crosbug.com/16648). The preferred way of determining developer mode status # (crosbug.com/16648). The preferred way of determining developer mode status
@ -88,6 +85,16 @@ EOF
sudo chmod a+rx "${path}" sudo chmod a+rx "${path}"
fi fi
# If git is installed in the state partition it needs some help
if [[ -x "${root_fs_dir}/usr/local/bin/git" ]]; then
sudo_clobber "${root_fs_dir}/etc/env.d/99git" <<EOF
GIT_EXEC_PATH=/usr/local/libexec/git-core
EOF
fi
# Re-run env-update/ldconfig to fix profile and ldconfig.so.cache.
sudo ROOT="${root_fs_dir}" env-update
# Zero all fs free space, not fatal since it won't work on linux < 3.2 # Zero all fs free space, not fatal since it won't work on linux < 3.2
sudo fstrim "${root_fs_dir}" || true sudo fstrim "${root_fs_dir}" || true
sudo fstrim "${state_fs_dir}" || true sudo fstrim "${state_fs_dir}" || true

View File

@ -71,10 +71,7 @@ switch_to_strict_mode
. "${SCRIPT_ROOT}"/sdk_lib/make_conf_util.sh . "${SCRIPT_ROOT}"/sdk_lib/make_conf_util.sh
FULLNAME="ChromeOS Developer" DEFGROUPS="adm,cdrom,floppy,audio,video,portage"
DEFGROUPS="eng,adm,cdrom,floppy,audio,video,portage"
PASSWORD=chronos
CRYPTED_PASSWD=$(perl -e 'print crypt($ARGV[0], "foo")', $PASSWORD)
USEPKG="" USEPKG=""
if [[ $FLAGS_usepkg -eq $FLAGS_TRUE ]]; then if [[ $FLAGS_usepkg -eq $FLAGS_TRUE ]]; then
@ -139,27 +136,35 @@ delete_existing() {
} }
init_users () { init_users () {
info "Set timezone..." if grep -q "^${SUDO_USER}:[^:]*:${SUDO_UID}:${SUDO_GID}:" \
# date +%Z has trouble with daylight time, so use host's info. "${FLAGS_chroot}/etc/passwd"; then
rm -f "${FLAGS_chroot}/etc/localtime" info "Updating ${SUDO_USER} (already exists in chroot)..."
if [ -f /etc/localtime ] ; then bare_chroot usermod -a -G "${DEFGROUPS}" \
cp /etc/localtime "${FLAGS_chroot}/etc" -s /bin/bash -m -d "/home/${SUDO_USER}" "${SUDO_USER}"
else elif grep -q "^${SUDO_USER}:" "${FLAGS_chroot}/etc/passwd"; then
ln -sf /usr/share/zoneinfo/PST8PDT "${FLAGS_chroot}/etc/localtime" die "User ${SUDO_USER} exists in chroot with different UID/GID"
fi else
info "Adding user/group..." info "Adding user ${SUDO_USER}..."
# Add ourselves as a user inside the chroot. local full_name group_name
bare_chroot groupadd -g 5000 eng full_name=$(getent passwd "${SUDO_USER}" | cut -d: -f5)
# We need the UID to match the host user's. This can conflict with [[ -n "${full_name}" ]] || die "Looking up user $SUDO_USER failed."
# a particular chroot UID. At the same time, the added user has to group_name=$(getent group "${SUDO_GID}" | cut -d: -f1)
# be a primary user for the given UID for sudo to work, which is [[ -n "${group_name}" ]] || die "Looking up gid $SUDO_GID failed."
# determined by the order in /etc/passwd. Let's put ourselves on top
# of the file. # We need the UID to match the host user's. This can conflict with
bare_chroot useradd -o -G ${DEFGROUPS} -g eng -u ${SUDO_UID} -s \ # a particular chroot UID. At the same time, the added user has to
/bin/bash -m -c "${FULLNAME}" -p ${CRYPTED_PASSWD} ${SUDO_USER} # be a primary user for the given UID for sudo to work, which is
# Because passwd generally isn't sorted and the entry ended up at the # determined by the order in /etc/passwd. Let's put ourselves on top
# bottom, it is safe to just take it and move it to top instead. # of the file.
sed -e '1{h;d};$!{H;d};$G' -i "${FLAGS_chroot}/etc/passwd" bare_chroot groupadd -o -g "${SUDO_GID}" "${group_name}"
bare_chroot useradd -o \
-G "${DEFGROUPS}" -g "${SUDO_GID}" -u "${SUDO_UID}" \
-s /bin/bash -m -c "${full_name}" "${SUDO_USER}"
# Because passwd generally isn't sorted and the entry ended up at the
# bottom, it is safe to just take it and move it to top instead.
sed -e '1{h;d};$!{H;d};$G' -i "${FLAGS_chroot}/etc/group"
sed -e '1{h;d};$!{H;d};$G' -i "${FLAGS_chroot}/etc/passwd"
fi
} }
init_setup () { init_setup () {
@ -202,6 +207,14 @@ EOF
# Fix bad group for some. # Fix bad group for some.
chown -R root:root "${FLAGS_chroot}/etc/"sudoers* chown -R root:root "${FLAGS_chroot}/etc/"sudoers*
info "Setting timezone..."
rm -f "${FLAGS_chroot}/etc/localtime"
if [ -f /etc/localtime ] ; then
cp /etc/localtime "${FLAGS_chroot}/etc"
else
ln -sf /usr/share/zoneinfo/UTC "${FLAGS_chroot}/etc/localtime"
fi
info "Setting up hosts/resolv..." info "Setting up hosts/resolv..."
# Copy config from outside chroot into chroot. # Copy config from outside chroot into chroot.
cp /etc/{hosts,resolv.conf} "$FLAGS_chroot/etc/" cp /etc/{hosts,resolv.conf} "$FLAGS_chroot/etc/"