Skip to content

Commit

Permalink
feat: Add NVME disk type
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Oct 7, 2024
1 parent 8244a48 commit c8d8c2e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -Eeuo pipefail

: "${DISK_IO:="native"}" # I/O Mode, can be set to 'native', 'threads' or 'io_uring'
: "${DISK_FMT:="raw"}" # Disk file format, 'raw' by default for best performance
: "${DISK_TYPE:=""}" # Device type to be used, choose "ide", "usb", "blk" or "scsi"
: "${DISK_TYPE:=""}" # Device type to be used, "sata", "nvme", "blk" or "scsi"
: "${DISK_FLAGS:=""}" # Specifies the options for use with the qcow2 disk format
: "${DISK_CACHE:="none"}" # Caching mode, can be set to 'writeback' for better performance
: "${DISK_DISCARD:="on"}" # Controls whether unmap (TRIM) commands are passed to the host.
Expand Down Expand Up @@ -369,6 +369,7 @@ createDevice () {
local result=" -drive file=$DISK_FILE,id=$DISK_ID,format=$DISK_FMT,cache=$DISK_CACHE,aio=$DISK_IO,discard=$DISK_DISCARD,detect-zeroes=on"

case "${DISK_TYPE,,}" in
"none" ) ;;
"auto" )
echo "$result"
;;
Expand All @@ -377,7 +378,12 @@ createDevice () {
-device usb-storage,drive=${DISK_ID}${index}"
echo "$result"
;;
"ide" )
"nvme" )
result+=",if=none \
-device nvme,drive=${DISK_ID}${index},serial=deadbeaf${DISK_INDEX}"
echo "$result"
;;
"ide" | "sata" )
result+=",if=none \
-device ich9-ahci,id=ahci${DISK_INDEX},addr=$DISK_ADDRESS \
-device ide-hd,drive=${DISK_ID},bus=ahci$DISK_INDEX.0,rotation_rate=$DISK_ROTATION${index}"
Expand Down Expand Up @@ -410,7 +416,7 @@ addDisk () {
local DISK_FMT=$7
local DISK_IO=$8
local DISK_CACHE=$9
local DISK_EXT DIR DATA_SIZE FS PREV_FMT PREV_EXT CUR_SIZE OPTS
local DISK_EXT DIR DATA_SIZE FS PREV_FMT PREV_EXT CUR_SIZE

DISK_EXT=$(fmt2ext "$DISK_FMT")
local DISK_FILE="$DISK_BASE.$DISK_EXT"
Expand All @@ -424,11 +430,11 @@ addDisk () {
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")

if (( DATA_SIZE < 1 )); then
error "Invalid value for ${DISK_DESC^^}_SIZE: $DISK_SPACE" && exit 73
error "Invalid value for ${DISK_DESC^^}_SIZE: $DISK_SPACE" && exit 73
fi

if (( DATA_SIZE < 6442450944 )); then
error "Please increase ${DISK_DESC^^}_SIZE to at least 6 GB." && exit 73
error "Please increase ${DISK_DESC^^}_SIZE to at least 6 GB." && exit 73
fi

FS=$(stat -f -c %T "$DIR")
Expand Down Expand Up @@ -495,7 +501,7 @@ html "Initializing disks..."
[ -z "${DISK_NAME:-}" ] && DISK_NAME="data"

case "${DISK_TYPE,,}" in
"ide" | "usb" | "scsi" | "blk" | "auto" ) ;;
"ide" | "sata" | "nvme" | "usb" | "scsi" | "blk" | "auto" | "none" ) ;;
* ) error "Invalid DISK_TYPE specified, value \"$DISK_TYPE\" is not recognized!" && exit 80 ;;
esac

Expand Down

0 comments on commit c8d8c2e

Please sign in to comment.