{"id":2374,"date":"2025-05-30T16:00:54","date_gmt":"2025-05-30T14:00:54","guid":{"rendered":"https:\/\/www.sfsoft.it\/blog\/?p=2374"},"modified":"2025-06-04T10:55:53","modified_gmt":"2025-06-04T08:55:53","slug":"virtualbox-su-debian-12-bookworm-e-secure-boot","status":"publish","type":"post","link":"http:\/\/www.sfsoft.it\/blog\/2025\/05\/30\/virtualbox-su-debian-12-bookworm-e-secure-boot\/","title":{"rendered":"VirtualBox su Debian 12 BookWorm e Secure Boot"},"content":{"rendered":"\n<p>fonte: <a href=\"https:\/\/medium.com\/@loice5\/fix-virtualbox-and-secure-boot-on-debian-based-linux-d62965973c4f\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/medium.com\/@loice5\/fix-virtualbox-and-secure-boot-on-debian-based-linux-d62965973c4f<\/a><\/p>\n\n\n\n<p>Se si ha un Debian su un PC recente \u00e8 facile ci sia Secure Boot attivo che inibisce il caricamento di moduli non firmati.<\/p>\n\n\n\n<p>O si disabilita il Secure Boot o si deve firmare i moduli e caricarli nel boot del PC.<\/p>\n\n\n\n<p>Procediamo a creare prima i certificati MOK per firmare poi i moduli:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo su -\nmkdir \/root\/module-signing\ncd \/root\/module-signing\n# Replace USERNAME by your username on the machine\nopenssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj \"\/CN=USERNAME\/\"\nchmod 600 MOK.priv<\/code><\/pre>\n\n\n\n<p>Verr\u00e0 generata una coppia di chiavi MOK.priv e MOK.der<\/p>\n\n\n\n<p>Si importa la chiave nel boot PC (la password impostata verr\u00e0 richiesta dopo al boot nella fase di importazione, sar\u00e0 richiesta solo una volta):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mokutil --import \/root\/module-signing\/MOK.der\n# You will be prompted for your password twice\n# input the temporary one you just imagined<\/code><\/pre>\n\n\n\n<p>Riavviare il PC, alla schermata blu con la richiesta di importazione della chiave selezionare <em>Enroll MOK<\/em> e seguire le indicazioni (verr\u00e0 richiesta la password di prima), riavviare poi il PC.<\/p>\n\n\n\n<p>Controlliamo che il certificato sia attivo:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mokutil --test-key \/root\/module-signing\/MOK.der\n\/root\/module-signing\/MOK.der is already in the enrollment\nrequest<\/code><\/pre>\n\n\n\n<p>Ora il certificato \u00e8 caricato nel boot e si pu\u00f2 procedere alla firma dei moduli, l&#8217;esempio fornito nell&#8217;articolo fa riferimento ai moduli VirtualBox nel formato compresso ZSTD, nel mio caso erano in formato non compresso .ko, ho riadattato il codice dello script per il mio caso:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# Ensure the script is running from \/root\/module-signing if that is required.\ncd \/root\/module-signing || { echo \"Failed to change directory to \/root\/module-signing\"; exit 1; }\n\n# Get the directory containing the vbox modules.\nMODULE_DIR=$(dirname \"$(modinfo -n vboxdrv)\")\n\n# Loop over every *.ko file in the module directory (not compressed).\nfor modfile in \"$MODULE_DIR\"\/*.ko; do\n    # Check if the file exists (in case there are no .ko files)\n    if &#91; ! -e \"$modfile\" ]; then\n        echo \"No .ko modules found in $MODULE_DIR\"\n        break\n    fi\n\n    echo \"----------------------------------------\"\n    echo \"Processing module: $modfile\"\n\n    # Define the temporary decompressed filename (no need to decompress).\n    temp_ko=\"$modfile\"\n\n    # Create a backup of the original module before any operations.\n    backup_modfile=\"${MODULE_DIR}\/old-$(basename \"$modfile\")\"\n    echo \"Creating backup of original module: $modfile ...\"\n    if cp \"$modfile\" \"$backup_modfile\"; then\n        echo \"Backup created successfully.\"\n    else\n        echo \"Failed to create backup for $modfile. Skipping...\"\n        continue\n    fi\n\n    # Signing the module directly.\n    echo \"Signing ${temp_ko} ...\"\n    if \/usr\/src\/linux-headers-$(uname -r)\/scripts\/sign-file sha256 \\\n         \/root\/module-signing\/MOK.priv \\\n         \/root\/module-signing\/MOK.der \\\n         \"$temp_ko\"; then\n        echo \"Signing successful.\"\n    else\n        echo \"Signing failed for $temp_ko. Restoring backup and skipping...\"\n        # Restore the backup if signing fails\n        mv \"$backup_modfile\" \"$modfile\"\n        continue\n    fi\n\n    echo \"Finished processing $modfile\"\n\n    # Extract the module name from the filename (remove path and .ko extension).\n    modname=$(basename \"$modfile\")\n    modname=\"${modname%.ko}\"\n    echo \"Attempting to load module: $modname\"\n\n    # Try to modprobe the module.\n    if modprobe \"$modname\"; then\n        echo \"modprobe $modname succeeded.\"\n    else\n        echo \"modprobe $modname failed. Restoring backup...\"\n        # Restore the backup if modprobe fails\n        mv \"$backup_modfile\" \"$modfile\"\n        continue\n    fi\ndone\n\necho \"----------------------------------------\"\necho \"All modules processed.\"<\/code><\/pre>\n\n\n\n<p>Ora i moduli sono firmati e caricati con <em>modprobe<\/em> se tutto funziona si pu\u00f2 caricare i moduli al boot del sistema:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo -e \"vboxdrv\\nvboxnetadp\\nvboxnetflt\" | sudo tee \/etc\/modules-load.d\/vboxmodules.conf<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>fonte: https:\/\/medium.com\/@loice5\/fix-virtualbox-and-secure-boot-on-debian-based-linux-d62965973c4f Se si ha un Debian su un PC recente \u00e8 facile ci sia Secure Boot attivo che inibisce il caricamento di moduli non firmati. O si disabilita il Secure Boot o si deve firmare i moduli e caricarli nel boot del PC. Procediamo a creare prima i certificati MOK per firmare poi i [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[166,15,3,47],"tags":[287,167,16,8,291,48],"_links":{"self":[{"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/posts\/2374"}],"collection":[{"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/comments?post=2374"}],"version-history":[{"count":8,"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/posts\/2374\/revisions"}],"predecessor-version":[{"id":2387,"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/posts\/2374\/revisions\/2387"}],"wp:attachment":[{"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/media?parent=2374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/categories?post=2374"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/tags?post=2374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}