Skip to content

Commit

Permalink
feat: Use SATA disks for legacy devices (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Jun 9, 2024
1 parent e38d479 commit 392ae1b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
32 changes: 18 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

</div></h1>

QEMU in a docker container for running ARM-based virtual machines, for devices like the Raspberry Pi 5 and many others.
Docker container for running ARM-based virtual machines using QEMU, for devices like the Raspberry Pi 5 and many others.

It uses high-performance QEMU options (like KVM acceleration, kernel-mode networking, IO threading, etc.) to achieve near-native speed.
It allows you to create VM's which behave just like normal containers, meaning you can manage them using all your existing tools (like Portainer) and configure them in a language (YAML) you are already familiar with.

This greatly reduces the learning curve and also eliminates the need for a dedicated Proxmox or ESXi server in many cases. It uses high-performance QEMU options (like KVM acceleration, kernel-mode networking, IO threading, etc.) to achieve near-native speed.

Note: for KVM acceleration you need a Linux-based operating system, as it's not available on MacOS unfortunately.

Expand Down Expand Up @@ -121,17 +123,6 @@ kubectl apply -f kubernetes.yml
DISK_TYPE: "blk"
```

* ### How do I verify if my system supports KVM?

To verify if your system supports KVM, run the following commands:

```bash
sudo apt install cpu-checker
sudo kvm-ok
```

If you receive an error from `kvm-ok` indicating that KVM acceleration can't be used, check the virtualization settings in the BIOS.

* ### How do I change the amount of CPU or RAM?

By default, the container will be allowed to use a maximum of 1 CPU core and 1 GB of RAM.
Expand All @@ -143,7 +134,20 @@ kubectl apply -f kubernetes.yml
RAM_SIZE: "4G"
CPU_CORES: "4"
```


* ### How do I verify if my system supports KVM?

To verify that your system supports KVM, run the following commands:

```bash
sudo apt install cpu-checker
sudo kvm-ok
```

If you receive an error from `kvm-ok` indicating that KVM acceleration can't be used, check whether virtualization extensions are enabled in your BIOS. If you are running the container inside a VM instead of directly on the host, you will also need to enable nested virtualization in its settings. If you are using a cloud provider, you may be out of luck as most of them do not allow nested virtualization for their VPS's. If you are using MacOS, you are also out of luck, as only Linux and Windows support KVM.

If you don't receive any error from `kvm-ok` at all, but the container still complains that `/dev/kvm` is missing, it might help to add `privileged: true` to your compose file (or `--privileged` to your `run` command), to rule out any permission issue.

* ### How do I assign an individual IP address to the container?

By default, the container uses bridge networking, which shares the IP address with the host.
Expand Down
37 changes: 32 additions & 5 deletions src/disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ createDevice () {
;;
"ide" )
result+=",if=none \
-device ide-hd,drive=${DISK_ID},bus=ide.$DISK_INDEX,rotation_rate=$DISK_ROTATION${index}"
-device ich9-ahci,id=ahci${DISK_INDEX},addr=$DISK_ADDRESS,iothread=io2 \
-device ide-hd,drive=${DISK_ID},bus=ahci$DISK_INDEX.0,rotation_rate=$DISK_ROTATION${index}"
echo "$result"
;;
"blk" | "virtio-blk" )
Expand Down Expand Up @@ -416,7 +417,8 @@ addMedia () {
;;
"ide" )
result+=",if=none \
-device ide-cd,drive=${DISK_ID},bus=ide.${DISK_BUS}${index}"
-device ich9-ahci,id=ahci${DISK_BUS},addr=$DISK_ADDRESS,iothread=io2 \
-device ide-cd,drive=${DISK_ID},bus=ahci${DISK_BUS}.0${index}"
echo "$result"
;;
"blk" | "virtio-blk" )
Expand Down Expand Up @@ -529,10 +531,30 @@ html "Initializing disks..."

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

[[ "${MACHINE,,}" != "virt" ]] && MEDIA_TYPE="ide" || MEDIA_TYPE="auto"
if [ -z "${MEDIA_TYPE:-}" ]; then
case "${DISK_TYPE,,}" in
"ide" | "usb" | "scsi" )
if [[ "${MACHINE,,}" == "virt" ]]; then
MEDIA_TYPE="auto"
else
MEDIA_TYPE="$DISK_TYPE"
fi ;;
"blk" | "auto" )
if [[ "${MACHINE,,}" != "virt" ]] && [[ "${MACHINE,,}" != "pc-i440fx-2"* ]]; then
MEDIA_TYPE="ide"
else
MEDIA_TYPE="auto"
fi ;;
esac
fi

case "${MEDIA_TYPE,,}" in
"ide" | "usb" | "scsi" | "blk" | "auto" ) ;;
* ) error "Invalid MEDIA_TYPE specified, value \"$MEDIA_TYPE\" is unrecognized!" && exit 80 ;;
esac

if [ -f "$BOOT" ] && [ -s "$BOOT" ]; then
ADD_OPTS=$(addMedia "$BOOT" "$MEDIA_TYPE" "0" "$BOOT_INDEX" "0x5")
Expand All @@ -543,7 +565,12 @@ DRIVERS="/drivers.iso"
[ ! -f "$DRIVERS" ] || [ ! -s "$DRIVERS" ] && DRIVERS="$STORAGE/drivers.iso"

if [ -f "$DRIVERS" ] && [ -s "$DRIVERS" ]; then
ADD_OPTS=$(addMedia "$DRIVERS" "$MEDIA_TYPE" "1" "" "0x6")
if [[ "${MACHINE,,}" != "virt" ]] && [[ "${MACHINE,,}" != "pc-i440fx-2"* ]]; then
DRIVER_TYPE="ide"
else
DRIVER_TYPE="auto"
fi
ADD_OPTS=$(addMedia "$DRIVERS" "$DRIVER_TYPE" "1" "" "0x6")
DISK_OPTS+=" $ADD_OPTS"
fi

Expand Down
2 changes: 1 addition & 1 deletion src/proc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if [[ "$KVM" != [Nn]* ]]; then
warn "you are using Windows 10 which has no KVM support, this will cause a major loss of performance."
else
error "KVM acceleration not available $KVM_ERR, this will cause a major loss of performance."
error "See the FAQ on how to enable it, or continue without KVM by setting KVM=N (not recommended)."
error "See the FAQ on how to diagnose the cause, or continue without KVM by setting KVM=N (not recommended)."
[[ "$DEBUG" != [Yy1]* ]] && exit 88
fi
fi
Expand Down

0 comments on commit 392ae1b

Please sign in to comment.