Ram Chandrasekar | 613e1f4 | 2022-08-25 00:02:12 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright 2022 The ChromiumOS Authors |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | # This script is automatically generated by @SCRIPT_GENERATOR@. |
| 7 | # Do not edit! |
| 8 | |
| 9 | if ! type numsectors >/dev/null 2>&1; then |
| 10 | # shellcheck disable=SC1091 |
| 11 | . "/usr/share/misc/chromeos-common.sh" || exit 1 |
| 12 | fi |
| 13 | locate_gpt |
| 14 | |
| 15 | # Usage: create_image <device> <min_disk_size> |
| 16 | # If <device> is a block device, wipes out the GPT |
| 17 | # If it's not, it creates a new file of the requested size |
| 18 | create_image() { |
| 19 | local dev="$1" |
| 20 | local min_disk_size="$2" |
| 21 | |
| 22 | if [ -b "${dev}" ]; then |
| 23 | # Make sure block size is not greater than 8K. Otherwise the partition |
| 24 | # start calculation won't fit. |
| 25 | block_size=$(blocksize "${dev}") |
| 26 | if [ "${block_size}" -gt 8192 ]; then |
| 27 | echo "Destination blocksize too large. Only blocksizes of 8192 bytes and \ |
| 28 | smaller are supported." >&2 |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | # Zap any old partitions (otherwise gpt complains). |
| 33 | dd if=/dev/zero of="${dev}" conv=notrunc bs=512 count=64 |
| 34 | dd if=/dev/zero of="${dev}" conv=notrunc bs=512 count=64 \ |
Mike Frysinger | 946987e | 2023-03-10 22:55:45 -0500 | [diff] [blame] | 35 | seek=$((min_disk_size / 512 - 64)) |
Ram Chandrasekar | 613e1f4 | 2022-08-25 00:02:12 +0000 | [diff] [blame] | 36 | else |
| 37 | if [ ! -e "${dev}" ]; then |
| 38 | # Align to 512 bytes |
Mike Frysinger | 946987e | 2023-03-10 22:55:45 -0500 | [diff] [blame] | 39 | min_disk_size=$(((min_disk_size + 511) & ~511)) |
Ram Chandrasekar | 613e1f4 | 2022-08-25 00:02:12 +0000 | [diff] [blame] | 40 | truncate -s "${min_disk_size}" "${dev}" |
| 41 | fi |
| 42 | fi |
| 43 | } |