| # Copyright 2024 The ChromiumOS Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| description "LVM migration to reclaim space for thinpool" |
| author "chromium-os-dev@chromium.org" |
| |
| start on stopped startup |
| stop on stopping system-services |
| task |
| |
| # The job can be later restarted. |
| oom score -100 |
| |
| env VPD_MIGRATION_STATUS=/sys/firmware/vpd/rw/thinpool_migration_status |
| |
| script |
| get_volume_group() { |
| local physical_volume="$1" |
| |
| pvs --reportformat json --readonly -o vg_name "${physical_volume}" \ |
| | jq .report[0].pv[0].vg_name |
| } |
| |
| if ! [ -f "${VPD_MIGRATION_STATUS}" ]; then |
| stop |
| exit 0 |
| fi |
| |
| # Example root dev types we need to handle: /dev/sda2 -> /dev/sda, |
| # /dev/mmcblk0p0 -> /dev/mmcblk0p, /dev/ubi2_1 -> /dev/ubi |
| STATE_DEV="$(rootdev -s | sed 's/[0-9_]*$//')1" |
| |
| VG_NAME="$(get_volume_group "${STATE_DEV}")" |
| |
| if ! [ -n "${VG_NAME}" ]; then |
| stop |
| exit 0 |
| fi |
| |
| # Disable passdowns for the duration of this script: this speeds up the |
| # reclaim process by ~30%. |
| lvchange --discards nopassdown "${VG_NAME}/thinpool" |
| |
| # Add ionice to ensure that we don't overwhelm the system with discards. |
| ionice -c 3 -- fstrim /mnt/stateful_partition |
| |
| lvchange --discards passdown "${VG_NAME}/thinpool" |
| |
| # Cleanup ensures that we will only trim the stateful logical volume |
| # once post migration. |
| thinpool_migrator --cleanup |
| |
| logger -t "${UPSTART_JOB}" "LVM migration finalized" |
| end script |