From bf0a37a0f41cdb3c68b1d9e536b67374beee9152 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Sat, 24 Aug 2013 22:36:02 -0400 Subject: [PATCH 1/4] fix(make_chroot): Move timezone setup to general init function. No idea why this was in the user setup function, move it a bit. --- sdk_lib/make_chroot.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh index 4134e4e2fd..716813db19 100755 --- a/sdk_lib/make_chroot.sh +++ b/sdk_lib/make_chroot.sh @@ -139,14 +139,6 @@ delete_existing() { } init_users () { - info "Set timezone..." - # date +%Z has trouble with daylight time, so use host's info. - rm -f "${FLAGS_chroot}/etc/localtime" - if [ -f /etc/localtime ] ; then - cp /etc/localtime "${FLAGS_chroot}/etc" - else - ln -sf /usr/share/zoneinfo/PST8PDT "${FLAGS_chroot}/etc/localtime" - fi info "Adding user/group..." # Add ourselves as a user inside the chroot. bare_chroot groupadd -g 5000 eng @@ -202,6 +194,14 @@ EOF # Fix bad group for some. 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..." # Copy config from outside chroot into chroot. cp /etc/{hosts,resolv.conf} "$FLAGS_chroot/etc/" From 6c2f9a9ffb29b6ade8eb8d0ea415cd939b283de1 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Sat, 24 Aug 2013 23:34:15 -0400 Subject: [PATCH 2/4] fix(make_chroot): Improve chroot user creation. If the user already exists check that the UID and GID are correct and modify it (setting shell and home directory) to match what the SDK expects. This avoids needlessly failing if the user calling cros_sdk is the 'core' user on a CoreOS machine. Change new-user creation to copy the user's full name and group instead of using a generic name and Google's 'eng' group. Also remove the default password for the account, it isn't needed and uses perl. --- sdk_lib/make_chroot.sh | 47 +++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh index 716813db19..2537ed9821 100755 --- a/sdk_lib/make_chroot.sh +++ b/sdk_lib/make_chroot.sh @@ -71,10 +71,7 @@ switch_to_strict_mode . "${SCRIPT_ROOT}"/sdk_lib/make_conf_util.sh -FULLNAME="ChromeOS Developer" -DEFGROUPS="eng,adm,cdrom,floppy,audio,video,portage" -PASSWORD=chronos -CRYPTED_PASSWD=$(perl -e 'print crypt($ARGV[0], "foo")', $PASSWORD) +DEFGROUPS="adm,cdrom,floppy,audio,video,portage" USEPKG="" if [[ $FLAGS_usepkg -eq $FLAGS_TRUE ]]; then @@ -139,19 +136,35 @@ delete_existing() { } init_users () { - info "Adding user/group..." - # Add ourselves as a user inside the chroot. - bare_chroot groupadd -g 5000 eng - # We need the UID to match the host user's. This can conflict with - # a particular chroot UID. At the same time, the added user has to - # be a primary user for the given UID for sudo to work, which is - # determined by the order in /etc/passwd. Let's put ourselves on top - # of the file. - bare_chroot useradd -o -G ${DEFGROUPS} -g eng -u ${SUDO_UID} -s \ - /bin/bash -m -c "${FULLNAME}" -p ${CRYPTED_PASSWD} ${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/passwd" + if grep -q "^${SUDO_USER}:[^:]*:${SUDO_UID}:${SUDO_GID}:" \ + "${FLAGS_chroot}/etc/passwd"; then + info "Updating ${SUDO_USER} (already exists in chroot)..." + bare_chroot usermod -a -G "${DEFGROUPS}" \ + -s /bin/bash -m -d "/home/${SUDO_USER}" "${SUDO_USER}" + elif grep -q "^${SUDO_USER}:" "${FLAGS_chroot}/etc/passwd"; then + die "User ${SUDO_USER} exists in chroot with different UID/GID" + else + info "Adding user ${SUDO_USER}..." + local full_name group_name + full_name=$(getent passwd "${SUDO_USER}" | cut -d: -f5) + [[ -n "${full_name}" ]] || die "Looking up user $SUDO_USER failed." + group_name=$(getent group "${SUDO_GID}" | cut -d: -f1) + [[ -n "${group_name}" ]] || die "Looking up gid $SUDO_GID failed." + + # We need the UID to match the host user's. This can conflict with + # a particular chroot UID. At the same time, the added user has to + # be a primary user for the given UID for sudo to work, which is + # determined by the order in /etc/passwd. Let's put ourselves on top + # of the file. + 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 () { From 4f18deb87f55096fae8e39a926680c0ec7e2bda9 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Sun, 25 Aug 2013 00:16:44 -0400 Subject: [PATCH 3/4] fix(build_image): Add support for using git in dev images. If git is installed via coreos-dev in the STATE partition it will need some help finding its install location since it was built thinking it would be installed in /usr rather than /usr/local. --- build_library/dev_image_util.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/build_library/dev_image_util.sh b/build_library/dev_image_util.sh index 3401316778..543cb46f36 100755 --- a/build_library/dev_image_util.sh +++ b/build_library/dev_image_util.sh @@ -41,9 +41,6 @@ install_dev_packages() { 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). # TODO(arkaitzr): Remove this file when applications no longer rely on it # (crosbug.com/16648). The preferred way of determining developer mode status @@ -88,6 +85,16 @@ EOF sudo chmod a+rx "${path}" 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" < Date: Sun, 25 Aug 2013 15:56:22 -0400 Subject: [PATCH 4/4] Revert "fix(build_library): Create disk image first instead of last." This reverts commit b97cfe126f0934d1505e352e17f15d580879d3cc. The minor device numbers of loop partitions are allocated dynamically which significantly complicates dunning under Docker which uses a static /dev. Rolling this back until we can rely on /dev being dynamic. --- build_library/base_image_util.sh | 81 ++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/build_library/base_image_util.sh b/build_library/base_image_util.sh index 3fd26f7bdd..b1a6be6358 100755 --- a/build_library/base_image_util.sh +++ b/build_library/base_image_util.sh @@ -32,11 +32,6 @@ cleanup_mounts() { safe_umount_tree "${esp_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. set -e } @@ -64,33 +59,36 @@ create_base_image() { trap "cleanup_mounts && delete_prompt" EXIT 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_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_blocks=$((root_fs_bytes / fs_block_size)) local state_fs_label="STATE" 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_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_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. - info "Building ROOT filesystem" - sudo mkfs.ext2 -F -q -b ${fs_block_size} "${root_fs_dev}" "${root_fs_blocks}" - sudo tune2fs -L "${root_fs_label}" \ + info "Building ${root_fs_img}" + truncate --size="${root_fs_bytes}" "${root_fs_img}" + /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 \ -T 20091119110000 \ -c 0 \ @@ -98,33 +96,34 @@ create_base_image() { -m 0 \ -r 0 \ -e remount-ro \ - "${root_fs_dev}" + "${root_fs_img}" 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. - info "Building STATE filesystem" - sudo mkfs.ext4 -F -q "${state_fs_dev}" - sudo tune2fs -L "${state_fs_label}" \ - -c 0 \ - -i 0 \ - "${state_fs_dev}" + info "Building ${state_fs_img}" + truncate --size="${state_fs_bytes}" "${state_fs_img}" + /sbin/mkfs.ext4 -F -q "${state_fs_img}" + /sbin/tune2fs -L "${state_fs_label}" -U "${state_fs_uuid}" \ + -c 0 -i 0 "${state_fs_img}" 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. - info "Building ESP filesystem" - sudo mkfs.vfat "${esp_fs_dev}" + info "Building ${esp_fs_img}" + truncate --size="${esp_fs_bytes}" "${esp_fs_img}" + /usr/sbin/mkfs.vfat "${esp_fs_img}" # Build OEM FS disk image. - info "Building OEM filesystem" - sudo mkfs.ext4 -F -q "${oem_fs_dev}" - sudo tune2fs -L "${oem_fs_label}" \ - -c 0 \ - -i 0 \ - "${oem_fs_dev}" + info "Building ${oem_fs_img}" + truncate --size="${oem_fs_bytes}" "${oem_fs_img}" + /sbin/mkfs.ext4 -F -q "${oem_fs_img}" + /sbin/tune2fs -L "${oem_fs_label}" -U "${oem_fs_uuid}" \ + -c 0 -i 0 "${oem_fs_img}" 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. for i in ${ROOT_OVERLAYS}; do @@ -269,6 +268,16 @@ create_base_image() { 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_gpt_scripts "${BUILD_DIR}/${image_name}" "${BUILD_DIR}"