mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-10 14:36:58 +02:00
churn(build_library): Change lots of stateful references to state.
For consistency we are using 'state' these days, not 'stateful'. While I'm mucking around in this code it seems like a good time to switch.
This commit is contained in:
parent
ebbd281f0d
commit
34cfe6e07e
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
. "${SRC_ROOT}/platform/dev/toolchain_utils.sh" || exit 1
|
. "${SRC_ROOT}/platform/dev/toolchain_utils.sh" || exit 1
|
||||||
|
|
||||||
# Overlays are parts of the disk that live on the stateful partition
|
# Overlays are parts of the disk that live on the state partition
|
||||||
ROOT_OVERLAYS=(var opt srv home usr/local)
|
ROOT_OVERLAYS=(var opt srv home usr/local)
|
||||||
|
|
||||||
cleanup_mounts() {
|
cleanup_mounts() {
|
||||||
@ -28,7 +28,7 @@ cleanup_mounts() {
|
|||||||
|
|
||||||
echo "Cleaning up mounts"
|
echo "Cleaning up mounts"
|
||||||
safe_umount_tree "${root_fs_dir}"
|
safe_umount_tree "${root_fs_dir}"
|
||||||
safe_umount_tree "${stateful_fs_dir}"
|
safe_umount_tree "${state_fs_dir}"
|
||||||
safe_umount_tree "${esp_fs_dir}"
|
safe_umount_tree "${esp_fs_dir}"
|
||||||
safe_umount_tree "${oem_fs_dir}"
|
safe_umount_tree "${oem_fs_dir}"
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ create_base_image() {
|
|||||||
info "Using image type ${image_type}"
|
info "Using image type ${image_type}"
|
||||||
|
|
||||||
root_fs_dir="${BUILD_DIR}/rootfs"
|
root_fs_dir="${BUILD_DIR}/rootfs"
|
||||||
stateful_fs_dir="${BUILD_DIR}/stateful"
|
state_fs_dir="${BUILD_DIR}/state"
|
||||||
esp_fs_dir="${BUILD_DIR}/esp"
|
esp_fs_dir="${BUILD_DIR}/esp"
|
||||||
oem_fs_dir="${BUILD_DIR}/oem"
|
oem_fs_dir="${BUILD_DIR}/oem"
|
||||||
|
|
||||||
@ -64,11 +64,11 @@ create_base_image() {
|
|||||||
local root_fs_img="${BUILD_DIR}/rootfs.image"
|
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 stateful_fs_label="STATE"
|
local state_fs_label="STATE"
|
||||||
local stateful_fs_num=$(get_num ${image_type} ${stateful_fs_label})
|
local state_fs_num=$(get_num ${image_type} ${state_fs_label})
|
||||||
local stateful_fs_img="${BUILD_DIR}/stateful.image"
|
local state_fs_img="${BUILD_DIR}/state.image"
|
||||||
local stateful_fs_bytes=$(get_filesystem_size ${image_type} ${stateful_fs_num})
|
local state_fs_bytes=$(get_filesystem_size ${image_type} ${state_fs_num})
|
||||||
local stateful_fs_uuid=$(uuidgen)
|
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})
|
||||||
@ -102,14 +102,14 @@ create_base_image() {
|
|||||||
|
|
||||||
df -h "${root_fs_dir}"
|
df -h "${root_fs_dir}"
|
||||||
|
|
||||||
# Build stateful FS disk image.
|
# Build state FS disk image.
|
||||||
info "Building ${stateful_fs_img}"
|
info "Building ${state_fs_img}"
|
||||||
truncate --size="${stateful_fs_bytes}" "${stateful_fs_img}"
|
truncate --size="${state_fs_bytes}" "${state_fs_img}"
|
||||||
/sbin/mkfs.ext4 -F -q "${stateful_fs_img}"
|
/sbin/mkfs.ext4 -F -q "${state_fs_img}"
|
||||||
/sbin/tune2fs -L "${stateful_fs_label}" -U "${stateful_fs_uuid}" \
|
/sbin/tune2fs -L "${state_fs_label}" -U "${state_fs_uuid}" \
|
||||||
-c 0 -i 0 "${stateful_fs_img}"
|
-c 0 -i 0 "${state_fs_img}"
|
||||||
mkdir -p "${stateful_fs_dir}"
|
mkdir -p "${state_fs_dir}"
|
||||||
sudo mount -o loop "${stateful_fs_img}" "${stateful_fs_dir}"
|
sudo mount -o loop "${state_fs_img}" "${state_fs_dir}"
|
||||||
|
|
||||||
# Build ESP disk image.
|
# Build ESP disk image.
|
||||||
info "Building ${esp_fs_img}"
|
info "Building ${esp_fs_img}"
|
||||||
@ -125,28 +125,28 @@ create_base_image() {
|
|||||||
mkdir -p "${oem_fs_dir}"
|
mkdir -p "${oem_fs_dir}"
|
||||||
sudo mount -o loop "${oem_fs_img}" "${oem_fs_dir}"
|
sudo mount -o loop "${oem_fs_img}" "${oem_fs_dir}"
|
||||||
|
|
||||||
# Prepare stateful 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
|
||||||
sudo mkdir -p "${stateful_fs_dir}/overlays/$i"
|
sudo mkdir -p "${state_fs_dir}/overlays/$i"
|
||||||
sudo mkdir -p "${root_fs_dir}/$i"
|
sudo mkdir -p "${root_fs_dir}/$i"
|
||||||
sudo mount --bind "${stateful_fs_dir}/overlays/$i" "${root_fs_dir}/$i"
|
sudo mount --bind "${state_fs_dir}/overlays/$i" "${root_fs_dir}/$i"
|
||||||
done
|
done
|
||||||
|
|
||||||
sudo mkdir -p "${stateful_fs_dir}/overlays/usr/local"
|
sudo mkdir -p "${state_fs_dir}/overlays/usr/local"
|
||||||
|
|
||||||
# Create symlinks so that /usr/local/usr based directories are symlinked to
|
# Create symlinks so that /usr/local/usr based directories are symlinked to
|
||||||
# /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc.
|
# /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc.
|
||||||
setup_symlinks_on_root "${stateful_fs_dir}/overlays/usr/local" \
|
setup_symlinks_on_root "${state_fs_dir}/overlays/usr/local" \
|
||||||
"${stateful_fs_dir}/overlays/var" \
|
"${state_fs_dir}/overlays/var" \
|
||||||
"${stateful_fs_dir}"
|
"${state_fs_dir}"
|
||||||
|
|
||||||
# Perform binding rather than symlinking because directories must exist
|
# Perform binding rather than symlinking because directories must exist
|
||||||
# on rootfs so that we can bind at run-time since rootfs is read-only.
|
# on rootfs so that we can bind at run-time since rootfs is read-only.
|
||||||
info "Binding directories from stateful partition onto the rootfs"
|
info "Binding directories from state partition onto the rootfs"
|
||||||
|
|
||||||
# Setup the dev image for developer tools
|
# Setup the dev image for developer tools
|
||||||
sudo mkdir -p "${root_fs_dir}/usr/local"
|
sudo mkdir -p "${root_fs_dir}/usr/local"
|
||||||
sudo mount --bind "${stateful_fs_dir}/overlays/usr/local" "${root_fs_dir}/usr/local"
|
sudo mount --bind "${state_fs_dir}/overlays/usr/local" "${root_fs_dir}/usr/local"
|
||||||
|
|
||||||
# TODO(bp): remove these temporary fixes for /mnt/stateful_partition going moving
|
# TODO(bp): remove these temporary fixes for /mnt/stateful_partition going moving
|
||||||
sudo mkdir -p "${root_fs_dir}/mnt/stateful_partition/"
|
sudo mkdir -p "${root_fs_dir}/mnt/stateful_partition/"
|
||||||
@ -208,7 +208,7 @@ create_base_image() {
|
|||||||
# trim the image size as much as possible.
|
# trim the image size as much as possible.
|
||||||
emerge_to_image --root="${root_fs_dir}" ${BASE_PACKAGE}
|
emerge_to_image --root="${root_fs_dir}" ${BASE_PACKAGE}
|
||||||
|
|
||||||
# Record directories installed to the stateful partition.
|
# Record directories installed to the state partition.
|
||||||
# Ignore /var/tmp, systemd covers this entry.
|
# Ignore /var/tmp, systemd covers this entry.
|
||||||
sudo "${BUILD_LIBRARY_DIR}/gen_tmpfiles.py" --root="${root_fs_dir}" \
|
sudo "${BUILD_LIBRARY_DIR}/gen_tmpfiles.py" --root="${root_fs_dir}" \
|
||||||
--output="${root_fs_dir}/usr/lib/tmpfiles.d/base_image.conf" \
|
--output="${root_fs_dir}/usr/lib/tmpfiles.d/base_image.conf" \
|
||||||
@ -259,24 +259,24 @@ create_base_image() {
|
|||||||
# Clean up symlinks so they work on a running target rooted at "/".
|
# Clean up symlinks so they work on a running target rooted at "/".
|
||||||
# Here development packages are rooted at /usr/local. However, do not
|
# Here development packages are rooted at /usr/local. However, do not
|
||||||
# create /usr/local or /var on host (already exist on target).
|
# create /usr/local or /var on host (already exist on target).
|
||||||
setup_symlinks_on_root "/usr/local" "/var" "${stateful_fs_dir}"
|
setup_symlinks_on_root "/usr/local" "/var" "${state_fs_dir}"
|
||||||
|
|
||||||
# Zero all fs free space to make it more compressible so auto-update
|
# Zero all fs free space to make it more compressible so auto-update
|
||||||
# payloads become smaller, not fatal since it won't work on linux < 3.2
|
# payloads become smaller, 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 "${stateful_fs_dir}" || true
|
sudo fstrim "${state_fs_dir}" || true
|
||||||
|
|
||||||
cleanup_mounts
|
cleanup_mounts
|
||||||
|
|
||||||
# Create the GPT-formatted image.
|
# Create the GPT-formatted image.
|
||||||
build_gpt "${BUILD_DIR}/${image_name}" \
|
build_gpt "${BUILD_DIR}/${image_name}" \
|
||||||
"${root_fs_img}" \
|
"${root_fs_img}" \
|
||||||
"${stateful_fs_img}" \
|
"${state_fs_img}" \
|
||||||
"${esp_fs_img}" \
|
"${esp_fs_img}" \
|
||||||
"${oem_fs_img}"
|
"${oem_fs_img}"
|
||||||
|
|
||||||
# Clean up temporary files.
|
# Clean up temporary files.
|
||||||
rm -f "${root_fs_img}" "${stateful_fs_img}" "${esp_fs_img}" "{oem_fs_img}"
|
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}"
|
||||||
|
@ -17,7 +17,7 @@ install_dev_packages() {
|
|||||||
trap "unmount_image ; delete_prompt" EXIT
|
trap "unmount_image ; delete_prompt" EXIT
|
||||||
|
|
||||||
mount_image "${BUILD_DIR}/${image_name}" "${root_fs_dir}" \
|
mount_image "${BUILD_DIR}/${image_name}" "${root_fs_dir}" \
|
||||||
"${stateful_fs_dir}" "${esp_fs_dir}"
|
"${state_fs_dir}" "${esp_fs_dir}"
|
||||||
|
|
||||||
# Determine the root dir for developer packages.
|
# Determine the root dir for developer packages.
|
||||||
local root_dev_dir="${root_fs_dir}/usr/local"
|
local root_dev_dir="${root_fs_dir}/usr/local"
|
||||||
@ -90,7 +90,7 @@ EOF
|
|||||||
|
|
||||||
# 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 "${stateful_fs_dir}" || true
|
sudo fstrim "${state_fs_dir}" || true
|
||||||
|
|
||||||
info "Developer image built and stored at ${image_name}"
|
info "Developer image built and stored at ${image_name}"
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
'''Scan an existing directory tree and record installed directories.
|
'''Scan an existing directory tree and record installed directories.
|
||||||
|
|
||||||
During build a number of directories under /var are created in the stateful
|
During build a number of directories under /var are created in the state
|
||||||
partition. We want to make sure that those are always there so create a record
|
partition. We want to make sure that those are always there so create a record
|
||||||
of them using systemd's tempfiles config format so they are recreated during
|
of them using systemd's tempfiles config format so they are recreated during
|
||||||
boot if they go missing for any reason.
|
boot if they go missing for any reason.
|
||||||
|
@ -191,10 +191,10 @@ resize_state_partition() {
|
|||||||
local original_size=$(stat -c%s "${TEMP_STATE}")
|
local original_size=$(stat -c%s "${TEMP_STATE}")
|
||||||
|
|
||||||
if [[ "${original_size}" -gt "${size_in_bytes}" ]]; then
|
if [[ "${original_size}" -gt "${size_in_bytes}" ]]; then
|
||||||
die "Cannot resize stateful image to smaller than original."
|
die "Cannot resize state image to smaller than original."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Resizing stateful partition to ${size_in_mb}MB"
|
info "Resizing state partition to ${size_in_mb}MB"
|
||||||
/sbin/e2fsck -pf "${TEMP_STATE}"
|
/sbin/e2fsck -pf "${TEMP_STATE}"
|
||||||
/sbin/resize2fs "${TEMP_STATE}" "${size_in_sectors}s"
|
/sbin/resize2fs "${TEMP_STATE}" "${size_in_sectors}s"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user