Add TDX support for NixOS QEMU runs and document AsterNixOS usage
This commit is contained in:
parent
5d0779bd83
commit
ece52ee480
|
|
@ -76,3 +76,15 @@ cargo osdk build --scheme tdx
|
||||||
cargo osdk run --scheme tdx
|
cargo osdk run --scheme tdx
|
||||||
cargo osdk test --scheme tdx
|
cargo osdk test --scheme tdx
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Run AsterNixOS in Intel TDX
|
||||||
|
|
||||||
|
You can also run AsterNixOS with TDX by setting `INTEL_TDX=1`, which switches
|
||||||
|
the QEMU scheme in the NixOS run script to TDX.
|
||||||
|
|
||||||
|
Build the AsterNixOS image and run the OS:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make nixos
|
||||||
|
INTEL_TDX=1 make run_nixos
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -24,19 +24,20 @@ ASTERINAS_DIR=$(realpath "${SCRIPT_DIR}/../..")
|
||||||
# Change to Asterinas root directory to ensure all scripts run from the correct location.
|
# Change to Asterinas root directory to ensure all scripts run from the correct location.
|
||||||
cd "${ASTERINAS_DIR}"
|
cd "${ASTERINAS_DIR}"
|
||||||
|
|
||||||
# Base QEMU arguments
|
if [ "${INTEL_TDX}" = "1" ]; then
|
||||||
BASE_QEMU_ARGS="qemu-system-x86_64 \
|
SCHEME="tdx"
|
||||||
-bios /root/ovmf/release/OVMF.fd \
|
BASE_QEMU_ARGS="qemu-system-x86_64"
|
||||||
"
|
else
|
||||||
|
SCHEME="common"
|
||||||
|
BASE_QEMU_ARGS="qemu-system-x86_64 -bios /root/ovmf/release/OVMF.fd"
|
||||||
|
fi
|
||||||
|
|
||||||
# Mode-specific QEMU arguments
|
# Mode-specific QEMU arguments
|
||||||
case "$MODE" in
|
case "$MODE" in
|
||||||
nixos)
|
nixos)
|
||||||
NIXOS_DIR="${ASTERINAS_DIR}/target/nixos"
|
NIXOS_DIR="${ASTERINAS_DIR}/target/nixos"
|
||||||
QEMU_ARGS="${BASE_QEMU_ARGS} \
|
DISK_ARGS="-drive if=none,format=raw,id=u0,file=${NIXOS_DIR}/asterinas.img \
|
||||||
-drive if=none,format=raw,id=u0,file=${NIXOS_DIR}/asterinas.img \
|
-device virtio-blk-pci,drive=u0,disable-legacy=on,disable-modern=off"
|
||||||
-device virtio-blk-pci,drive=u0,disable-legacy=on,disable-modern=off \
|
|
||||||
"
|
|
||||||
;;
|
;;
|
||||||
iso)
|
iso)
|
||||||
ASTER_IMAGE_PATH=${ASTERINAS_DIR}/target/nixos/asterinas.img
|
ASTER_IMAGE_PATH=${ASTERINAS_DIR}/target/nixos/asterinas.img
|
||||||
|
|
@ -53,27 +54,24 @@ case "$MODE" in
|
||||||
dd if=/dev/zero of="${ASTER_IMAGE_PATH}" bs=1M count=${NIXOS_DISK_SIZE_IN_MB} status=none
|
dd if=/dev/zero of="${ASTER_IMAGE_PATH}" bs=1M count=${NIXOS_DISK_SIZE_IN_MB} status=none
|
||||||
echo "Image created successfully!"
|
echo "Image created successfully!"
|
||||||
|
|
||||||
QEMU_ARGS="${BASE_QEMU_ARGS} \
|
DISK_ARGS="-cdrom ${ISO_IMAGE_PATH} -boot d \
|
||||||
-cdrom ${ISO_IMAGE_PATH} -boot d \
|
|
||||||
-drive if=none,format=raw,id=u0,file=${ASTER_IMAGE_PATH} \
|
-drive if=none,format=raw,id=u0,file=${ASTER_IMAGE_PATH} \
|
||||||
-device virtio-blk-pci,drive=u0,disable-legacy=on,disable-modern=off \
|
-device virtio-blk-pci,drive=u0,disable-legacy=on,disable-modern=off"
|
||||||
"
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# Fetch architecture specific arguments from qemu_args.sh
|
||||||
|
EXTRA_ARGS=$(${ASTERINAS_DIR}/tools/qemu_args.sh ${SCHEME} 2>/dev/null)
|
||||||
|
|
||||||
|
QEMU_ARGS="${BASE_QEMU_ARGS} ${DISK_ARGS} ${EXTRA_ARGS}"
|
||||||
|
|
||||||
if [ "${ENABLE_KVM}" = "1" ]; then
|
if [ "${ENABLE_KVM}" = "1" ]; then
|
||||||
QEMU_ARGS="${QEMU_ARGS} -accel kvm"
|
QEMU_ARGS="${QEMU_ARGS} -accel kvm"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
COMMON_QEMU_ARGS=$(${ASTERINAS_DIR}/tools/qemu_args.sh common 2>/dev/null)
|
|
||||||
QEMU_ARGS="
|
|
||||||
${QEMU_ARGS} \
|
|
||||||
${COMMON_QEMU_ARGS} \
|
|
||||||
"
|
|
||||||
|
|
||||||
# The kernel uses a specific value to signal a successful shutdown via the
|
# The kernel uses a specific value to signal a successful shutdown via the
|
||||||
# isa-debug-exit device.
|
# isa-debug-exit device.
|
||||||
KERNEL_SUCCESS_EXIT_CODE=16 # 0x10 in hexadecimal
|
KERNEL_SUCCESS_EXIT_CODE=16 # 0x10 in hexadecimal
|
||||||
|
|
@ -83,7 +81,7 @@ QEMU_SUCCESS_EXIT_CODE=$(((KERNEL_SUCCESS_EXIT_CODE << 1) | 1))
|
||||||
|
|
||||||
# Execute QEMU
|
# Execute QEMU
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
${QEMU_ARGS} || exit_code=$?
|
eval "${QEMU_ARGS}" || exit_code=$?
|
||||||
exit_code=${exit_code:-0}
|
exit_code=${exit_code:-0}
|
||||||
|
|
||||||
# Check if the execution was successful:
|
# Check if the execution was successful:
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,10 @@ if [ "$1" = "tdx" ]; then
|
||||||
-cpu host,-kvm-steal-time,pmu=off \
|
-cpu host,-kvm-steal-time,pmu=off \
|
||||||
-machine q35,kernel-irqchip=split,confidential-guest-support=tdx0 \
|
-machine q35,kernel-irqchip=split,confidential-guest-support=tdx0 \
|
||||||
-object '$TDX_OBJECT' \
|
-object '$TDX_OBJECT' \
|
||||||
|
-drive if=none,format=raw,id=x0,file=./test/initramfs/build/ext2.img \
|
||||||
|
-drive if=none,format=raw,id=x1,file=./test/initramfs/build/exfat.img \
|
||||||
|
-device virtio-blk-pci,drive=x0,serial=vext2,disable-legacy=on,disable-modern=off,queue-size=64,num-queues=1,request-merging=off,backend_defaults=off,discard=off,write-zeroes=off,event_idx=off,indirect_desc=off,queue_reset=off \
|
||||||
|
-device virtio-blk-pci,drive=x1,serial=vexfat,disable-legacy=on,disable-modern=off,queue-size=64,num-queues=1,request-merging=off,backend_defaults=off,discard=off,write-zeroes=off,event_idx=off,indirect_desc=off,queue_reset=off \
|
||||||
-device virtio-net-pci,netdev=net01,disable-legacy=on,disable-modern=off$VIRTIO_NET_FEATURES \
|
-device virtio-net-pci,netdev=net01,disable-legacy=on,disable-modern=off$VIRTIO_NET_FEATURES \
|
||||||
-device virtio-keyboard-pci,disable-legacy=on,disable-modern=off \
|
-device virtio-keyboard-pci,disable-legacy=on,disable-modern=off \
|
||||||
$NETDEV_ARGS \
|
$NETDEV_ARGS \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue