{"id":9652,"date":"2024-03-04T22:42:00","date_gmt":"2024-03-04T21:42:00","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=9652"},"modified":"2024-07-23T22:54:24","modified_gmt":"2024-07-23T20:54:24","slug":"linux-prevent-x11-xorg-from-using-a-nvidia-gpu","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/linux-prevent-x11-xorg-from-using-a-nvidia-gpu\/","title":{"rendered":"Linux: Prevent X11\/Xorg from using a (Nvidia) GPU"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_9652 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_9652')){$('.twoclick_social_bookmarks_post_9652').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Linux%3A%20Prevent%20X11%2FXorg%20from%20using%20a%20%28Nvidia%29%20GPU\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Awhen%20you%20install%20an%20NVidia%20GPU%20to%20run%20HPC%20tasks%20you%20usually%20don%27t%20want%20that%20X11%2Fxorg%20use%20it.%20This%20can%20be%20done%20by%20force%20Xorg%20to%20use%20the%20framebuffer%20device%20and%20prevent%20the%20nvidia_drm%20driver%20from%20creating%20a%20framebuffer%20device.%20%0D%0AYou%20can%20check%20this%20by%20nvidia-smi%0D%0A%5Bshell%5D%0D%0Aroot%40debdev%20~%20%23%20nvidia-smi%20%0D%0A%2B---------------------------------------------------------------------------------------%2B%0D%0A%20...\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/linux-prevent-x11-xorg-from-using-a-nvidia-gpu\\\/\",\"post_id\":9652,\"post_title_referrer_track\":\"Linux%3A+Prevent+X11%2FXorg+from+using+a+%28Nvidia%29+GPU\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>when you install an NVidia GPU to run HPC tasks you usually don&#8217;t want that X11\/xorg use it. This can be done by force Xorg to use the framebuffer device and prevent the nvidia_drm driver from creating a framebuffer device.<br \/>\nYou can check this by nvidia-smi<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # nvidia-smi \r\n+---------------------------------------------------------------------------------------+\r\n| Processes:                                                                            |\r\n|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |\r\n|        ID   ID                                                             Usage      |\r\n|=======================================================================================|\r\n|    0   N\/A  N\/A      1581      G   \/usr\/lib\/xorg\/Xorg                          167MiB |\r\n|    0   N\/A  N\/A      1713      G   \/usr\/bin\/gnome-shell                         16MiB |\r\n+---------------------------------------------------------------------------------------+\r\n<\/pre>\n<p><!--more--><\/p>\n<p>These are the tasks to install the nvidia drivers (Tested with Ubuntu 22.04 LTS on Hyper-V)<\/p>\n<p>I use Hyper-V so I installed an optimized kernel. Omit this if you are not on Hyper-V.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmichael@debdev ~ # sudo su\r\nroot@debdev ~ # apt update\r\nroot@debdev ~ # apt install linux-azure\r\n<\/pre>\n<p>Reboot, check kernel version and remove no longer used packages<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # uname -a \r\n... 6.5.0-1015-azure #15~22.04.1-Ubuntu SMP ..\r\nroot@debdev ~ # apt autoremove\r\n<\/pre>\n<p>Install build tools and kernel header<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # apt install build-essential\r\nroot@debdev ~ # apt install linux-headers-$(uname -r )\r\n<\/pre>\n<p>Configure <a href=\"https:\/\/developer.nvidia.com\/cuda-downloads?target_os=Linux&#038;target_arch=x86_64&#038;Distribution=Ubuntu&#038;target_version=22.04&#038;target_type=deb_local\" rel=\"noopener\" target=\"_blank\">NVidia package sources. <\/a> Remove the old nvidia siging key,<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # wget https:\/\/developer.download.nvidia.com\/compute\/cuda\/repos\/ubuntu2204\/x86_64\/cuda-ubuntu2204.pin\r\nroot@debdev ~ # mv cuda-ubuntu2204.pin \/etc\/apt\/preferences.d\/cuda-repository-pin-600\r\nroot@debdev ~ # wget https:\/\/developer.download.nvidia.com\/compute\/cuda\/12.3.2\/local_installers\/cuda-repo-ubuntu2204-12-3-local_12.3.2-545.23.08-1_amd64.deb\r\nroot@debdev ~ # dpkg -i cuda-repo-ubuntu2204-12-3-local_12.3.2-545.23.08-1_amd64.deb\r\nroot@debdev ~ # cp \/var\/cuda-repo-ubuntu2204-12-3-local\/cuda-*-keyring.gpg \/usr\/share\/keyrings\/\r\nroot@debdev ~ # apt-get update\r\nroot@debdev ~ # apt-key del 7fa2af80\r\n<\/pre>\n<p>Install the <a href=\"https:\/\/docs.nvidia.com\/cuda\/cuda-installation-guide-linux\/#switching-between-driver-module-flavors\" rel=\"noopener\" target=\"_blank\"> nvidia drivers<\/a>.<\/p>\n<p>There are 2 options:<br \/>\n&#8211; The open drivers<br \/>\n&#8211; The legacy drivers<\/p>\n<p><strong>Open drivers: <\/strong>To install the open driver (remove already istalled legacy drivers before):<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # apt-get --purge remove nvidia-kernel-source-545\r\nroot@debdev ~ # apt-get install -y nvidia-kernel-open-545\r\nroot@debdev ~ # apt-get install -y cuda-drivers-545\r\n<\/pre>\n<p><!--Do not use the \"open\" drivers. The open drivers are linked into the Framebuffer device so the GPU is used even the framebuffer device is forced.--><\/p>\n<p><strong>Legeacy drivers: <\/strong>If installed remove the open drivers and install the legeacy drivers (check the installed version. In this case 545):<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # apt-get remove --purge nvidia-kernel-open-545\r\nroot@debdev ~ # apt-get install -y cuda-drivers\r\n<\/pre>\n<p>Disable creating a nvidia fb device<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # modinfo nvidia_drm\r\n...\r\nparm:           fbdev:Create a framebuffer device\r\n...\r\n<\/pre>\n<p>Edit \/etc\/default\/grub<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # vi \/etc\/default\/grub\r\n<\/pre>\n<p>and append <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nnvidia_drm.fbdev=0\r\n<\/pre>\n<p>to the GRUB_CMDLINE_LINUX_DEFAULT parameter. For example<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nGRUB_CMDLINE_LINUX_DEFAULT=&quot;quiet splash nvidia_drm.fbdev=0&quot;\r\n<\/pre>\n<p>Update grub and initfs<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # update-grub\r\nroot@debdev ~ # update-initramfs -v -u -k $(uname -r)  \r\n<\/pre>\n<p>Force Xorg\/X11 to use the framebuffer device. Create a file \/etc\/X11\/xorg.conf.d\/fb.conf<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSection &quot;Device&quot;\r\n    Identifier &quot;FBDEV&quot;\r\n    Driver &quot;fbdev&quot;\r\n    Option &quot;fbdev&quot; &quot;\/dev\/fb0&quot;\r\n    Option      &quot;AutoAddDevices&quot; &quot;false&quot;\r\n    Option      &quot;AutoAddGPU&quot; &quot;false&quot;\r\nEndSection\r\n<\/pre>\n<p>and restart the restart gdm<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # systemctl stop gdm3\r\n<\/pre>\n<p>Check if any processes are running on the GPU<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # nvidia-smi\r\nTue Mar  4 22:47:26 2024\r\n+---------------------------------------------------------------------------------------+\r\n| NVIDIA-SMI 545.23.08              Driver Version: 545.23.08    CUDA Version: 12.3     |\r\n|-----------------------------------------+----------------------+----------------------+\r\n| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |\r\n| Fan  Temp   Perf          Pwr:Usage\/Cap |         Memory-Usage | GPU-Util  Compute M. |\r\n|                                         |                      |               MIG M. |\r\n|=========================================+======================+======================|\r\n|   0  NVIDIA L40                     On  | 0000AF52:00:00.0 Off |                    0 |\r\n| N\/A   26C    P8              21W \/ 300W |      4MiB \/ 46068MiB |      0%      Default |\r\n|                                         |                      |                  N\/A |\r\n+-----------------------------------------+----------------------+----------------------+\r\n\r\n+---------------------------------------------------------------------------------------+\r\n| Processes:                                                                            |\r\n|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |\r\n|        ID   ID                                                             Usage      |\r\n|=======================================================================================|\r\n|  No running processes found                                                           |\r\n+---------------------------------------------------------------------------------------+\r\n\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, when you install an NVidia GPU to run HPC tasks you usually don&#8217;t want that X11\/xorg use it. This can be done by force Xorg to use the framebuffer device and prevent the nvidia_drm driver from creating a framebuffer device. You can check this by nvidia-smi root@debdev ~ # nvidia-smi +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+ | Processes: | &hellip; <a href=\"https:\/\/michlstechblog.info\/blog\/linux-prevent-x11-xorg-from-using-a-nvidia-gpu\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Linux: Prevent X11\/Xorg from using a (Nvidia) GPU<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[888,3,2],"tags":[2038,892,2039,2040,20],"class_list":["post-9652","post","type-post","status-publish","format-standard","hentry","category-hyper-v","category-linux","category-windows","tag-gpu","tag-hyper-v","tag-nvidia","tag-prevent-xorg","tag-windows-2"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=9652"}],"version-history":[{"count":28,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9652\/revisions"}],"predecessor-version":[{"id":9680,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9652\/revisions\/9680"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=9652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=9652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=9652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}