Debian 12 + NVIDIA Driver: Installation Guide for AI Enthusiasts

Debian 12 is the latest release of the Debian GNU/Linux distribution codenamed Bookworm. Artificial intelligence programs often require massive computing resources, especially GPUs, to speed up the training and inferencing process. In order for the Debian 12 system to render the desktop normally and take full advantage of the performance of the Nvidia GPU, we need to install a suitable graphics card driver.
This article describes how to install the Debian 12 system and Nvidia graphics driver to create an efficient artificial intelligence operating environment. We will introduce from the following aspects:

  • Installation Introduction: Introduces important updates and installation considerations for the system.
  • Disk partition: Reasonably divide the disk space to meet the needs of artificial intelligence programs.
  • Initial configuration: Do some simple configuration for subsequent use.
  • Graphics card driver installation: Download and install the latest version of the graphics card driver provided by Nvidia's official website to support GPU and CUDA tools.
  • Uninstall redundant programs: Clean up some unnecessary or infrequently used built-in programs to save disk space and attention.
  • Software ecological supplement: install macOS on the virtual machine to run software that Debian lacks, such as WeChat applet development tools and WeChat.

Installation Introduction

This release of Debian 12 contains many software updates. More importantly, the Linux kernel image uses version 6.1, and the GNOME desktop uses version 43.

Linux kernel 6.1 brings some new features and improvements, such as:

  • Support Rust language to write kernel code, improve the security and reliability of the kernel.
  • The MG-LRU algorithm is introduced to optimize memory recovery and improve system performance.
  • Improve the performance of the Btrfs file system.

GNOME 43 also provides a series of new features and improvements that improve the usability and aesthetics of the GNOME desktop environment, such as taking screenshots and recording screens more conveniently than before.

Download the latest stable image from the Debian official website , such as the current debian-12.0.0-amd64-DVD-1.iso. Several things to pay attention to during the installation process:

  1. Set user and password: leave the root password empty. This disables the root account and makes sudo available to user accounts.
    Set user and password

  2. Partition the disk: Manually. This allows flexibility in determining the size and location of each partition. The Debian graphical installation program is very convenient. You can enter the partition size with units, such as 100 MB, and you don't need to manually calculate the number of bytes.
    Partition the disk

  3. Configure the package manager: use a network mirror site. If you are connected to the Internet during the installation process, choosing a mirror site in China can speed up the download speed of the software package.

disk partition

Disk partitioning is an important step that needs to be done when installing the system. Here is a relatively common manual partitioning scheme, which is suitable for desktop computers with two hard disks (one solid-state hard disk and one mechanical hard disk). We will use solid-state drives to store operating system and program files to improve startup and running speed; we will use mechanical hard drives to store user files to save costs and expand capacity. The partition scheme is as follows:

  • EFI system partition: 100 MB, SSD. This partition is used to store the bootloader.
  • Swap space: 5 GB, SSD. This partition is used to temporarily store part of the memory data to the disk when the memory is insufficient to avoid system crashes. Because the swap space is basically not used at ordinary times, and the memory is not expensive now. My memory is 32G. If such a large swap space is allocated, it is a bit wasteful, so I choose to allocate a smaller swap space.
  • /:SSD. This partition is the root directory. The remaining space of the SSD is allocated to it.
  • /var: 50 GB, mechanical hard disk. This partition is used to store some frequently changing data, such as log files, cache files, temporary files, etc.
  • /home: mechanical hard disk. This partition is used to store user files, such as documents, pictures, videos, etc. The remaining space of the mechanical hard disk is allocated to it. Artificial intelligence data sets and models can be placed in the user directory, so the partition should be as large as possible, and I allocated it close to 2T.

initial configuration

1. Chinese directory changed to English

If you close the graphical interface, the Chinese display will be garbled, so it is best to use English, and it can also avoid the problem that some software does not support Chinese paths.

export LANG=en_US
xdg-user-dirs-gtk-update
export LANG=zh_CN.UTF-8

2. apt configuration

Open "Software & Update", select main, download from the server in China, remove the cdrom, and reload it.
This operation is equivalent to writing the following to /etc/apt/sources.list:

# deb cdrom:[Debian GNU/Linux 12.0.0 _Bookworm_ - Official amd64 DVD Binary-1 with firmware 20230610-10:23]/ bookworm main non-free-firmware
deb http://ftp.cn.debian.org/debian/ bookworm main

And completed the following command:

sudo apt update

3. Install vim editor

sudo apt install vim

Graphics card driver installation

The graphics card driver that comes with Debian 12 is Nouveau, which is prone to problems. For example, after I installed it and entered the system, the screen kept flickering. In order for the desktop to work properly and to run deep learning programs, we need to install Nvidia's official graphics driver.

1. Download the driver

Open a browser and visit the download page of Nvidia official website . On the page, select the following options:

  • Product Type: GeForce
  • Product series: GeForce RTX 30 Series (select according to the actual graphics card model)
  • Product Family: GeForce RTX 3060 (choose according to the actual graphics card model)
  • OS: Linux 64-bit
  • Download Type: Production Branch
  • Language: Chinese (Simplified)
    Then click the search button, and the available drivers will be displayed. Clicking the download button will start downloading a file ending in .run (for example, NVIDIA-Linux-x86_64-530.41.03.run).

2. Install dependent packages and kernel header files

Before installing the driver, we need to install some dependency packages and kernel header files so that the driver can be compiled and loaded correctly. Enter the following command:

sudo apt install gcc make linux-headers-$(uname -r)

In order to prevent the graphics card driver from running abnormally due to future kernel version upgrades, we need to disable kernel updates. Refer to the following commands:

dpkg --get-selections | grep linux

sudo apt-mark hold linux-image-6.1.0-9-amd64 linux-headers-6.1.0-9-amd64 linux-headers-6.1.0-9-common

3. Run the driver

We need to switch to the directory where the driver was downloaded (for example, ~/Downloads), and give the driver executable permission. Refer to the following commands:

cd ~/Downloads
chmod u+x NVIDIA-Linux-x86_64-530.41.03.run

Then, we can run the driver. Refer to the following commands:

sudo ./NVIDIA-Linux-x86_64-530.41.03.run

This launches an interactive installation wizard that lets us choose some options. During the installation process, some warnings or error messages may appear, we can ignore the warnings, or deal with the errors according to the prompts.

4. Handling error messages

If an error message prompts us to stop gdm3, run the following command (otherwise skip this step):

sudo /etc/init.d/gdm3 stop

After stopping gdm3, it will close the GUI, enter a command line mode with a black screen, and re-run the driver.

If the error message tells us that the driver conflicts with Nouveau, we need to disable Nouveau (otherwise skip this step). The driver will help us generate the /etc/modprobe.d/nvidia-installer-disable-nouveau.conf file. After confirming that the file has been written, we only need to run the following command:

sudo update-initramfs -u

sudo reboot

Rerun the driver after restarting.

5. Verify the driver

We can verify that the driver is working properly with the following command:

nvidia-smi

From the output information, we can see the driver version number, the highest supported CUDA version number, video memory usage, GPU temperature and other information.

Uninstall unnecessary programs

After installing the Debian 12 system, we may find that the system comes with some unnecessary programs, such as games. There are two ways to uninstall the built-in program, one is to use the software manager with a graphical interface, and the other is to use the apt tool of the command line.

Open "Software", we can uninstall:

  • 2048
  • Match
  • Tetris
  • International chess
  • Reversi
  • Huarong Road
  • robot
  • Matchball
  • Minesweeper
  • Sudoku
  • a few
  • neighbors
  • Connect four
  • push plate
  • Achromatic block
  • dice
  • AisleRiot Solitaire Game
  • GNOME Snake

If you don't like to use firefox browser, you can uninstall it. It is recommended to uninstall after installing the required browser.

sudo apt purge firefox-esr

After the uninstallation is complete, you can use the following commands to clean up some no longer needed dependent packages and configuration files:

sudo apt-get --purge autoremove

Software Ecological Supplement

The software and development tools we use every day are basically available in Debian, such as Baidu Netdisk, Youdao Cloud Notes, QQ, etc. However, it is inevitable that some software does not provide a Linux version, such as the WeChat applet development tool. At this time, we can use a virtual machine to run it. It is recommended to install macOS.
macOS

Summarize

The road to artificial intelligence is boundless, and only by continuing to move forward can we see the scenery. Installing the system is the first step in our exploration of artificial intelligence, but it is by no means the last step. In the next article, I will share more knowledge and experience about artificial intelligence with you. Stay tuned!
Debian 12
File system
resource


If you like my article, welcome to scan the QR code to follow my official account, get more technical dry goods, and come to communicate if you encounter problems!

Technical long-distance running

Guess you like

Origin blog.csdn.net/CanvaChen/article/details/131254870