本文档介绍如何在Trusted Cloud by S3NS 中调整操作系统 (OS) 映像,以使用您拥有许可的企业操作系统映像。
Trusted Cloud by S3NS 为 Debian、Ubuntu LTS、Rocky Linux 和 Container-Optimized OS 提供操作系统映像。如果您想使用其中任何一个提供的映像,请继续创建实例,并在创建实例时选择要使用的映像。
如果您拥有 Trusted Cloud by S3NS 未为其提供操作系统映像的企业操作系统(例如 Windows、Red Hat Enterprise Linux [RHEL] 或 SUSE Linux Enterprise Server [SLES])的许可,请使用本文档中提供的脚本来调整映像,以便与您的许可一起使用。该脚本会安装您在 Trusted Cloud by S3NS中使用映像创建实例所需的驱动程序。
准备工作
- 安装
jq
命令行处理器。 - 如果您尚未将包含要使用的操作系统映像的磁盘上传到 Cloud Storage 存储桶,请执行此操作。
- 确认您拥有创建自定义映像的所需权限。
-
如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 Trusted Cloud by S3NS 服务和 API 的过程。如需从本地开发环境运行代码或示例,您可以通过选择以下选项之一向 Compute Engine 进行身份验证:
Select the tab for how you plan to use the samples on this page:
gcloud
-
After installing the Google Cloud CLI, sign in to the gcloud CLI with your federated identity and then initialize it by running the following command:
gcloud init
- Set a default region and zone.
- 使用 Cloud Storage 中的磁盘创建实例,并在实例的磁盘上运行操作系统适应工具。此过程会安装操作系统映像在 Trusted Cloud by S3NS上运行所需的驱动程序。
- 提取操作系统适应性报告,并将输出文件复制到本地机器。此报告提供有关适应过程结果的信息,以及有关检测到的操作系统的详细信息。如果脚本未成功运行,报告会提供错误、警告和操作项,以便解决适配问题。
- 从实例的磁盘创建映像。然后,您可以使用此映像在 Trusted Cloud by S3NS上创建实例。
- 删除在此过程中创建的实例和磁盘。此步骤会清理项目中不需要的资源。
- 创建一个 shell 脚本。
- 复制操作系统适应脚本,然后将其粘贴到您的 shell 脚本文件中。
使用以下标志运行 shell 脚本:
SCRIPT_NAME \ -g 'INPUT_GCS_OBJECT' \ -o 'IMAGE_NAME' \ -z 'ZONE' \ -p 'PROJECT' \ -t 'TPC_PREFIX'
替换以下内容:
SCRIPT_NAME
:操作系统适应脚本文件的名称INPUT_GCS_OBJECT
:Cloud Storage 存储桶中磁盘的路径IMAGE_NAME
:调整后的映像的名称ZONE
:调整后的映像所在的可用区PROJECT
:您的 Trusted Cloud by S3NS 项目 IDTPC_PREFIX
:用于资源名称的前缀
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。
After installing the Google Cloud CLI, sign in to the gcloud CLI with your federated identity and then initialize it by running the following command:
gcloud init
如需了解详情,请参阅 Trusted Cloud 身份验证文档中的使用 REST 时进行身份验证。
操作系统适配脚本
为了帮助您为 Trusted Cloud by S3NS调整映像, Trusted Cloud by S3NS 提供了一个脚本,用于完成以下步骤:
以下脚本会调整映像以便在 Trusted Cloud by S3NS中使用:
完整的操作系统适配脚本
#!/usr/bin/env bash # Sets variables set -e set -x set -o pipefail UNIQUE_ID='' TPC_PREFIX='' ZONE='' PROJECT='' INPUT_IMAGE='' INPUT_DISK='' IMAGE_NAME='' ADAPTATION_INSTANCE_TYPE='c3-highcpu-4' # needs to support nested virtualization usage() { echo "" echo "Usage:" echo " $0 -g -o -z -t -p " echo "" echo "" echo "Parameters:" echo " -i
OR -d echo " -oOR -g " " echo " -z" echo " -t" echo " -p" echo " -h (help)" echo "" } while getopts ":i:d:g:o:z:t:p:h" opt; do case "${opt}" in i) INPUT_IMAGE="${OPTARG}" ;; d) INPUT_DISK="${OPTARG}" ;; g) INPUT_GCS_OBJECT="${OPTARG}" ;; o) IMAGE_NAME="${OPTARG}" ;; z) ZONE="${OPTARG}" ;; t) TPC_PREFIX="${OPTARG}" ;; p) PROJECT="${OPTARG}" ;; h) echo "$0 help:" usage exit 0 ;; *) echo "Unknown arg -${opt} ${OPTARG}" usage exit 1 ;; esac done shift $((OPTIND-1)) # Defines errors if [[ -n "${INPUT_IMAGE}" && -n "${INPUT_DISK}" ]] || [[ -n "${INPUT_IMAGE}" && -n "${INPUT_GCS_OBJECT}" ]] || [[ -n "${INPUT_DISK}" && -n "${INPUT_GCS_OBJECT}" ]]; then echo "Only one of -i, -d, or -g must be specified" usage exit 1 fi if [[ -z "${IMAGE_NAME}" ]]; then echo "The name of the image must be specified" usage exit 1 fi if [[ -z "${ZONE}" ]]; then echo "Zone must be specified" usage exit 1 fi if [[ -z "${TPC_PREFIX}" ]]; then echo "TPC prefix must be specified" usage exit 1 fi if [[ -z "${PROJECT}" ]]; then echo "Project must be specified" usage exit 1 fi # Creates disk OS_ADAPTATION_IMAGE="projects/${TPC_PREFIX}:v2v-community/global/images/family/v2v-tpc-stable" if [[ -z "${UNIQUE_ID}" ]]; then UNIQUE_ID=$(head /dev/urandom | tr -dc a-z0-9 | head -c4) fi if [[ -n "${INPUT_IMAGE}" ]]; then DISK_ID="${IMAGE_NAME}-disk-${UNIQUE_ID}" echo "Creating disk ${DISK_ID} from image ${INPUT_IMAGE}..." gcloud compute disks create "${DISK_ID}" --zone="${ZONE}" --image "${INPUT_IMAGE}" elif [[ -n "${INPUT_GCS_OBJECT}" ]]; then DISK_ID="${IMAGE_NAME}-disk-${UNIQUE_ID}" echo "Creating disk ${DISK_ID} from GCS object ${INPUT_GCS_OBJECT}..." CURL_OUTPUT=$(curl \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H 'Content-Type: application/json' \ -X POST \ "https://compute.s3nsapis.fr/compute/v1/projects/${TPC_PREFIX}:${PROJECT}/zones/${ZONE}/disks" \ -d '{"name":"'"${DISK_ID}"'", "sourceStorageObject":"'"${INPUT_GCS_OBJECT}"'"}') OPERATION_ID=$(jq -r '.name' <<< "${CURL_OUTPUT}") while ! gcloud compute operations describe --zone "${ZONE}" --format=json \ "${OPERATION_ID}" | jq -e '.status == "DONE"' >/dev/null; do sleep 5 done elif [[ -n "${INPUT_DISK}" ]]; then DISK_ID="${INPUT_DISK}" fi QUERY_PATH='v2v/report' DEVICE_NAME="dev-${UNIQUE_ID}" OUTPUT_DIR='/var/v2v' STARTUP_SCRIPT="docker run --privileged -v /dev:/dev -v ${OUTPUT_DIR}:${OUTPUT_DIR} v2v-tpc -vv --log file=${OUTPUT_DIR}/output.log,level=trace --report file=${OUTPUT_DIR}/report.json --report file=http://metadata.google.internal/computeMetadata/v1/instance/guest-attributes/${QUERY_PATH},headers=Metadata-Flavor=Google --license=byol --in-place --drive file=/dev/disk/by-id/google-${DEVICE_NAME},format=raw" # Creates instance and runs adaptation tool on disk echo "Adapting disk ${DISK_ID}" INSTANCE="os-adaptation-instance-${UNIQUE_ID}" gcloud compute instances create "${INSTANCE}" \ --zone="${ZONE}" \ --machine-type="${ADAPTATION_INSTANCE_TYPE}" \ --enable-nested-virtualization \ --metadata="^@@@^enable-guest-attributes=TRUE@@@startup-script=${STARTUP_SCRIPT}" \ --create-disk="auto-delete=yes,boot=yes,image=${OS_ADAPTATION_IMAGE}" \ --disk="name=${DISK_ID},auto-delete=no,device-name=${DEVICE_NAME}" # Retrieves report while [[ -z "${REPORT}" ]]; do sleep 5 set +e REPORT=$(gcloud compute instances get-guest-attributes "${INSTANCE}" \ --zone="${ZONE}" \ --query-path="${QUERY_PATH}" \ --format='value(value)') 2>/dev/null echo -n '.' set -e done echo "Operating System adaptation report:" jq . <<< "${REPORT}" gcloud compute scp --recurse "${INSTANCE}:${OUTPUT_DIR}" "$(pwd)" echo "Output file: $(pwd)/v2v/output.log, Report file: $(pwd)/v2v/report.json" echo "Deleting ${INSTANCE}..." gcloud compute instances delete "${INSTANCE}" --zone="${ZONE}" --quiet if jq --exit-status '.status != "SUCCESS"' <<< "${REPORT}" >/dev/null; then echo "Operating System adaptation failed" exit 1 fi # Creates image echo "Operating System adaptation successful, creating image..." IMAGE="image-${UNIQUE_ID}" gcloud compute images create "${IMAGE}" \ --source-disk-zone="${ZONE}" \ --guest-os-features="$(jq --raw-output '.guest_os_features | join(",")' <<< "${REPORT}")" \ --source-disk="${DISK_ID}" if [[ -z "${INPUT_DISK}" ]]; then gcloud compute disks delete "${DISK_ID}" --zone="${ZONE}" --quiet fi echo "Adapted image: ${IMAGE}"运行操作系统适配脚本
如需将操作系统映像调整为适用于 Trusted Cloud by S3NS,请执行以下操作:
脚本成功运行后,会输出以下消息:
Adapted image: IMAGE_NAME
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-24。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-24。"],[],[]] -