-
Notifications
You must be signed in to change notification settings - Fork 1
enables make vm-create in gentoo linux #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,7 +21,6 @@ VM_VCPUS=2 | |||||||||||
| VM_RAM=2048 | ||||||||||||
| SHARED_FOLDER="/var/lib/libvirt/shared/${VM_NAME}" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| function log() { | ||||||||||||
| echo | ||||||||||||
| echo | ||||||||||||
|
|
@@ -30,24 +29,11 @@ function log() { | |||||||||||
|
|
||||||||||||
| function vm_create() { | ||||||||||||
| log "Installing system packages" | ||||||||||||
| apt update | ||||||||||||
| apt install -y libvirt-daemon-system virtiofsd | ||||||||||||
|
|
||||||||||||
| log "Configuring libvirt user permission and network" | ||||||||||||
| if ! groups $USER | grep -q "\blibvirt\b"; then | ||||||||||||
| adduser $USER libvirt | ||||||||||||
| fi | ||||||||||||
| if ! virsh --connect "qemu:///system" net-info default | grep -q "Active:.*yes"; then | ||||||||||||
| virsh --connect "qemu:///system" net-start default | ||||||||||||
| fi | ||||||||||||
| if ! virsh --connect "qemu:///system" net-info default | grep -q "Autostart:.*yes"; then | ||||||||||||
| virsh --connect "qemu:///system" net-autostart default | ||||||||||||
| fi | ||||||||||||
| mkdir -p "$SHARED_FOLDER" | ||||||||||||
| chown -R ${SUDO_USER:-$USER}:libvirt "$SHARED_FOLDER" | ||||||||||||
|
|
||||||||||||
| log "Downloading Debian cloud-ready image" | ||||||||||||
| wget -c -t 0 -O "$DEBIAN_QCOW2" "$DEBIAN_QCOW2_URL" | ||||||||||||
| install_libs | ||||||||||||
| config_permissions | ||||||||||||
| qemu_connect | ||||||||||||
| create_shared_folder | ||||||||||||
| download_image | ||||||||||||
|
|
||||||||||||
| log "Creating cloud-init YAML files" | ||||||||||||
| cat <<EOF > "$CLOUDINIT_USER_YAML" | ||||||||||||
|
|
@@ -90,6 +76,12 @@ EOF | |||||||||||
| qemu-img create -f qcow2 -F qcow2 -b "$DEBIAN_QCOW2" "$OVERLAY_QCOW2" "$OVERLAY_DISK_SIZE" | ||||||||||||
|
|
||||||||||||
| log "Creating virtual machine" | ||||||||||||
|
|
||||||||||||
| if is_gentoo; then | ||||||||||||
| mkdir /var/lib/libvirt/shared/debian12-pydokku | ||||||||||||
| mkdir /var/lib/libvirt/boot | ||||||||||||
| fi | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+79
to
+84
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't understand why those lines are needed, since there's
Suggested change
|
||||||||||||
| virt-install \ | ||||||||||||
| --connect "qemu:///system" \ | ||||||||||||
| --name "$VM_NAME" \ | ||||||||||||
|
|
@@ -113,6 +105,58 @@ EOF | |||||||||||
| echo "Use: ssh $DEFAULT_USERNAME@$ip (password: $DEFAULT_PASSWORD)" | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| function is_gentoo() { | ||||||||||||
| if uname -r | grep -iq "gentoo"; then | ||||||||||||
| true | ||||||||||||
| else | ||||||||||||
| false | ||||||||||||
| fi | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| function install_libs() { | ||||||||||||
| if is_gentoo; then | ||||||||||||
| echo "Gentoo system detected. Running emerge --sync..." | ||||||||||||
| emerge --sync | ||||||||||||
| emerge --deep app-emulation/libvirt app-emulation/qemu virtiofsd app-emulation/virt-manager whois | ||||||||||||
| systemctl start libvirtd | ||||||||||||
| else | ||||||||||||
| echo "Non-Gentoo system detected. Running apt update..." | ||||||||||||
| apt update | ||||||||||||
| apt install -y libvirt-daemon-system virtiofsd | ||||||||||||
| fi | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| function config_permissions() { | ||||||||||||
| log "Configuring libvirt user permission and network" | ||||||||||||
| if ! groups $USER | grep -q "\blibvirt\b"; then | ||||||||||||
| usermod -a -G libvirt $USER | ||||||||||||
| fi | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| function qemu_connect() { | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function name does not describe what it does (all
Suggested change
|
||||||||||||
| if ! virsh --connect "qemu:///system" net-info default | grep -q "Active:.*yes"; then | ||||||||||||
| virsh --connect "qemu:///system" net-start default | ||||||||||||
| fi | ||||||||||||
| if ! virsh --connect "qemu:///system" net-info default | grep -q "Autostart:.*yes"; then | ||||||||||||
| virsh --connect "qemu:///system" net-autostart default | ||||||||||||
| fi | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| function create_shared_folder() { | ||||||||||||
| log "Creating shared folder" | ||||||||||||
| mkdir -p "$SHARED_FOLDER" | ||||||||||||
| chown -R ${SUDO_USER:-$USER}:libvirt "$SHARED_FOLDER" | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| function download_image() { | ||||||||||||
| log "Downloading Debian cloud-ready image" | ||||||||||||
|
|
||||||||||||
| if is_gentoo; then | ||||||||||||
| mkdir -p /var/lib/libvirt/images | ||||||||||||
| fi | ||||||||||||
|
Comment on lines
+154
to
+156
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is not required by Gentoo only and also could be improved to reuse the variable where the image path is stored. I prefer changing it to:
Suggested change
|
||||||||||||
| wget -c -t 0 -O "$DEBIAN_QCOW2" "$DEBIAN_QCOW2_URL" | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| function vm_start() { | ||||||||||||
| virsh --connect "qemu:///system" start "$VM_NAME" | ||||||||||||
| while [[ $(virsh --connect "qemu:///system" -q domstate "$VM_NAME") != "running" ]]; do | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.