This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cvm-image-rewriter: refine the cvm-image-rewriter (#256)
- Refine the cvm-image-rewriter - Add readme for each plugin - Update the serial number of plugin Signed-off-by: Yanbo0101 <[email protected]>
- Loading branch information
Showing
49 changed files
with
263 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Resize the image | ||
|
||
This plugin is used to extend the guest image size to given value from the | ||
environment variable `${GUEST_SIZE}`. | ||
|
||
If `${GUEST_SIZE}` is not specified like below, then this plugin will be skipped. | ||
``` | ||
export GUEST_SIZE=50G | ||
``` |
5 changes: 3 additions & 2 deletions
5
...ter/pre-stage/01-resize-image/host_run.sh → ...ins/01-resize-image/pre-stage/host_run.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Motd welcome | ||
|
||
This plugin is used to set the information in `/etc/motd`, which will be displayed after successful login. Users can customize the welcome information by updating the content of `files/etc/motd`. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Netplan | ||
|
||
This plugin is used to add network configuration file `netplan.yaml` in the `/etc/netplan/` directory, which will configure the network for the guest image. Users can customize `netplan.yaml` by updating the contents of `files/etc/netplan/netplan.yaml` |
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
tools/cvm-image-rewriter/plugins/04-user-authkey/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# User authkey | ||
|
||
This plugin is used to set the SSH login user and public key using environment variables `${CVM_USER}` and `${CVM_AUTH_KEY}`. | ||
|
||
The default value of `${CVM_USER}` is "cvm", and users can customize it as shown below. | ||
``` | ||
export CVM_USER=<user> | ||
``` | ||
|
||
The `${CVM_AUTH_KEY}` has no default value, users need to set it themselves. If `${CVM_AUTH_KEY}` is not specified like below, this plugin will be skipped. | ||
|
||
``` | ||
export CVM_AUTH_KEY=<ssh public key> | ||
``` |
2 changes: 1 addition & 1 deletion
2
...er/pre-stage/05-readonly-data/clean_up.sh → ...ns/04-user-authkey/post-stage/clean_up.sh
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Readonly data | ||
|
||
This plugin is used to fix some file permissions to read-only. Users can specify the names of files and directories that need to be fixed in the `pre-stage/file_list`. |
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
tools/cvm-image-rewriter/plugins/05-readonly-data/post-stage/clean_up.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
DIR=$(dirname "$(readlink -f "$0")") | ||
CLD_DIR="$DIR/../cloud-init" | ||
|
||
if [[ -d "$CLD_DIR" ]]; then | ||
rm -rf "$CLD_DIR" | ||
fi |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tools/cvm-image-rewriter/plugins/06-install-tdx-guest-kernel/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Install TDX guest kernel | ||
|
||
This plugin is used to install a TDX guest kernel from a given local repository. | ||
|
||
# Prerequisite | ||
|
||
Prepare the local repository and confirm that there are Debian packages related to the TDX kernel in the `/jammy/amd64/` directory of this repository. It is recommended to place this local repository in the `pre-stage/artifacts/` directory. | ||
``` | ||
mkdir -p ./pre-stage/artifacts | ||
mv <your guest repo> ./pre-stage/artifacts/ | ||
``` | ||
|
||
Set `${CVM_TDX_GUEST_REPO}` to the repository absolute path, or this plugin will be skipped. | ||
``` | ||
export CVM_TDX_GUEST_REPO=$(pwd)/pre-stage/artifacts/<your guest repo> | ||
# Or | ||
export CVM_TDX_GUEST_REPO=<your local guest repo> | ||
``` | ||
|
||
|
||
_NOTE: IF the original image is smaller than 1.5G, please set the environment variable GUEST\_SIZE to a larger value, as this will result in the execution of plugin 01._ |
8 changes: 8 additions & 0 deletions
8
tools/cvm-image-rewriter/plugins/06-install-tdx-guest-kernel/post-stage/clean_up.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
DIR=$(dirname "$(readlink -f "$0")") | ||
CLD_DIR="$DIR/../cloud-init" | ||
|
||
if [[ -d "$CLD_DIR" ]]; then | ||
rm -rf "$CLD_DIR" | ||
fi |
File renamed without changes.
48 changes: 48 additions & 0 deletions
48
tools/cvm-image-rewriter/plugins/06-install-tdx-guest-kernel/pre-stage/host_run.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
CURR_DIR=$(dirname "$(readlink -f "$0")") | ||
TOP_DIR="${CURR_DIR}/../../../" | ||
SCRIPTS_DIR="${TOP_DIR}/scripts" | ||
# shellcheck disable=SC1091 | ||
source "${SCRIPTS_DIR}/common.sh" | ||
ARTIFACTS_GUEST=/srv | ||
|
||
# check environment variable 'CVM_TDX_GUEST_REPO' | ||
if [[ -z "$CVM_TDX_GUEST_REPO" ]]; then | ||
warn "SKIP: TDX guest repo is not defined via environment variable 'CVM_TDX_GUEST_REPO' " | ||
exit 0 | ||
fi | ||
|
||
info "TDX Guest Repo is at ${CVM_TDX_GUEST_REPO}..." | ||
|
||
# check if the repo exists | ||
if [[ ! -d "$CVM_TDX_GUEST_REPO" ]]; then | ||
warn "SKIP: TDX guest local repo CVM_TDX_GUEST_REPO does not exist." | ||
exit 0 | ||
fi | ||
|
||
# Check if it is a valid TDX repo | ||
if ! compgen -G "$CVM_TDX_GUEST_REPO/jammy/amd64/linux-image-*mvp*.deb"; then | ||
warn "SKIP: $CVM_TDX_GUEST_REPO is invalid." | ||
exit 0 | ||
fi | ||
|
||
info "TDX guest local repo $CVM_TDX_GUEST_REPO check passed" | ||
|
||
# Copy TDX local repo from host to guest | ||
virt-copy-in -a "${GUEST_IMG}" "$CVM_TDX_GUEST_REPO" "$ARTIFACTS_GUEST" | ||
ok "TDX guest local repo $CVM_TDX_GUEST_REPO copied to guest $ARTIFACTS_GUEST" | ||
|
||
# Generate cloud-config | ||
mkdir -p "${CURR_DIR}/../cloud-init/x-shellscript/" | ||
cat > "${CURR_DIR}/../cloud-init/x-shellscript/07-install-tdx-guest-kernel.sh" << EOL | ||
#!/bin/bash | ||
PACKAGE_DIR=""$ARTIFACTS_GUEST"/$(basename "$CVM_TDX_GUEST_REPO")/jammy/" | ||
pushd \$PACKAGE_DIR || exit 0 | ||
apt install ./amd64/linux-image-unsigned-*.deb ./amd64/linux-modules-*.deb \ | ||
./amd64/linux-headers-*.deb ./all/linux-headers-*.deb --allow-downgrades -y | ||
popd || exit 0 | ||
EOL | ||
|
||
ok "Cloud config cloud-init/x-shellscript/07-install-tdx-guest-kernel.sh generated" |
3 changes: 3 additions & 0 deletions
3
tools/cvm-image-rewriter/plugins/07-device-permission/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Device permission | ||
|
||
This plugin is used to setup udev rules for CCNP device plugin. It is typically not required for users to customize unless additional udev rules are needed. |
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
tools/cvm-image-rewriter/plugins/08-ccnp-uds-directory-permission/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# CCNP UDS directory permission | ||
|
||
This plugin is used to prepare shared unix domain socket directories for CCNP. It is typically not required for users to customize unless additional Unix domain socket directories are needed. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Initrd update | ||
|
||
This plugins is used to update the initrd image. To change the initrd image, place the necessary files in the `files/` directory. The plugin will copy these files to the initramfs. |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...er/pre-stage/60-initrd-update/clean_up.sh → ...s/60-initrd-update/post-stage/clean_up.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.