[Ubuntu 20.04 installation and deep learning environment to build 4090 graphics card]

Ubuntu installation steps refer to the article Zhihu: Ubuntu 20.04 system installation and initial configuration

1. Make a boot disk

1.1 Download image file

First download the system image from the Ubuntu official website (or directly bing to search for the corresponding version). 【Ubuntu official website】

1.2 Make a boot disk

Refer to this article https://blog.csdn.net/qq_21386397/article/details/129894803

  1. You need to prepare a U disk (back up the contents of the U disk before use, and the files in the U disk will be cleared after making the boot disk!)
  2. Go to the rufus official website or other websites to download software to write the image file downloaded in the previous step to the USB flash drive.
    Official website: rufus official website
    More versions to download: Other versions
    github: Download from github

    No installation required, you can use it directly after downloading
  3. Make a boot disk

2. Install the system

2.1 Start the computer and enter the BIOS

Confirm how to enter the BIOS according to your computer's motherboard. Mine is to press F2 or DEL to enter.
Insert the prepared boot disk and turn on the computer, then quickly press F2 to enter the BIOS and select the boot disk to start.

2.2 Start installation

(I forgot to take screenshots during installation and quoted some pictures from other people’s tutorials )

  1. After successful startup, you will enter the installation boot interface, select the language, and then click Install Ubuntu
    Install Ubuntu

  2. Next select your keyboard layout and proceed
    Choose keyboard layout

  3. Select network
    Insert image description here

    You can choose not to connect to the network in this step. After connecting to the network, more things will be downloaded during installation, causing the installation to be slower.

  4. Select normal installation
    Insert image description here

  5. Installation method

    There are many options for this step: you can choose to install as shown in the figure, and various partitions will be automatically allocated and installed; you can also choose Somthing else below to manually partition. If Yi has installed the system before, he will have other options, such as [Install according to the original system partition, overwrite] and [Coexist with the original system]

    Insert image description here

    Let’s talk about the solution of choosing Something else manual partitioning in detail:

    The hard drive of the host I installed is 2T. Due to previous habits, I only divided the necessary partitions such as efi, /boot, /, and /home. The details are as follows:

    Partition name Select partition File system type size of space describe
    efi system partition logical partition XXX 2G efi is a UEFI boot. Its function is the same as the boot boot partition, but the boot boot defaults to grub boot. Its capacity is enough for 2048MB
    /boot logical partition ext4 About 1G Boot partition, 1G=1024MB for solid state drive
    / logical partition ext4 200G solid state drive Install the system and software, that is, everything except mounting the home is placed here, so the space cannot be too small.
    /home logical partition ext4 2T solid state drive all memory Used to store data and various folders, videos, downloads, etc. It is equivalent to a personal folder. It is recommended to allocate a slightly larger size.
  6. Select time zone

    After partitioning, you will wait for a while, and then the following screen will appear. Just select your time zone.

    Insert image description here

  7. Enter user information

    Insert image description here

    Enter your name, computer name, username, and user password. It is not recommended that the computer name and user name be too long, otherwise it will be troublesome when you occasionally need to use the user name or computer name when using the system (entering a very long name).

  8. Wait for installation to complete

    Insert image description here

  9. Restart the system

    Insert image description here

3. Install nvidia graphics card driver

Reference article: Ubuntu18-22.04 installation and clean uninstallation of nvidia graphics card driver - super detailed and the simplest

1. Install dependencies

	sudo apt-get update   #更新软件列表
	sudo apt-get install g++
	sudo apt-get install gcc
	sudo apt-get install make

or

	sudo apt-get install build-essential gcc-multilib dkms
>如果遇到无法下载的情况,可能是因为安装完系统后源不可用,可以先更换国内镜像源后在进行本步骤(换源方法:[写给工程师的 Ubuntu 20.04 最佳配置指南](https://zhuanlan.zhihu.com/p/139305626) 第**2、3**步)

2. Uninstall the original driver

	sudo apt-get remove --purge nvidia*   # 或者nvidia-*

3. Download the corresponding driver from the official website

After downloading, be sure to put the nvidia driver in a folder with an English name, such as mkdir driver. Create a new folder "driver". Official website address:
Nvidia driver download address.
My graphics card is 4090, and the official website recommended driver version is 535.54.03.

Insert image description here
Insert image description here

4. Disable nouveau

sudo gedit /etc/modprobe.d/blacklist.conf 或者(blacklist-nouveau.conf)

(If you enter the above command without gedit, an error will be reported. You can install gedit by sudo apt-get install gedit or use nano instead of gedit)

Add the following at the end of the opened blacklist.conf, save the text and close it

blacklist nouveau
options nouveau modeset=0

Enter the following command in the terminal to update

sudo update-initramfs –u

Restart your computer after the update is complete

sudo reboot

After restarting, enter the following command in the terminal. If there is no output, it means nouveau is successfully disabled.

lsmod | grep nouveau

5. Stop the current display server

The easiest way is to change to runlevel 3 using the telinit command. After entering the following linux command in the terminal, the display server will stop.

sudo telinit 3

Generally, after executing the above command, the system automatically enters the text interface tty;
if you cannot enter, press Ctrl + Alt + one of F1~F6 (corresponding to enter tty1~tty6 respectively)
and enter the user name and password.

6. In the text interface, disable the X-window service

Enter in the terminal

sudo /etc/init.d/gdm3 stop或者(sudo service gdm3 stop)

7. Install driver

cd command to enter the directory where the driver is stored and enter the command (the file name in the command is subject to the driver you downloaded)

sudo chmod 777 NVIDIA-Linux-x86_64-535.54.03.run   #给你下载的驱动赋予可执行权限,才可以安装
sudo ./NVIDIA-Linux-x86_64-535.54.03.run –no-opengl-files   #安装

Options that may appear during installation

question Options
The distribution-provided pre-install script failed! Are you sure you want to continue? yes
Would you like to register the kernel module souces with DKMS? This will allow DKMS to automatically build a new module, if you install a different kernel later? No
Nvidia’s 32-bit compatibility libraries? No
Would you like to run the nvidia-xconfigutility to automatically update your x configuration so that the NVIDIA x driver will be used when you restart x? Any pre-existing x confile will be backed up. No

The above questions did not appear in the order I wrote, but I didn’t have screenshots at the time so I forgot the order. The last question in the table needs attention. In other tutorials, I choose yes for this question, but during my system installation process, choosing yes will cause the computer to fail to boot normally after restarting. So I chose No here , and it can boot normally after restarting. (Ubuntu20.04, graphics card 4090)

8. Restart the graphical interface

After the installation is completed, return to the graphical interface:

sudo init 5 

or

ctrl + alt + f7 

or

sudo service gdm3 restart

Or enter reboot in the terminal to restart.

9. Test whether the graphics card driver is installed successfully

Terminal input:

	nvidia-smi

An interface similar to the one below appears, indicating that the driver has been successfully installed.
Insert image description here

4. Install CUDA

In order to be able to use pytorch2, I installed the CUDA11.8 version here.
Reference tutorial: CUDA_11.8 installation-Zhihu

1. Download CUDA from the official website

CUDA Toolkit 11.8 DownloadsYou
Insert image description here
can get two commands by selecting the options in the picture.

2. Download CUDA

Enter the command obtained in the previous step into the terminal and download the runfile file

	wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run

3. Installation

After executing the previous command to download the runfile file, cd to the path where the file is located, and execute the following command to install cuda

sudo sh cuda_11.8.0_520.61.05_linux.run

After execution, wait for a while and the following screen will appear.
Insert image description here
Enter accept and press Enter to continue.
Insert image description here

Move the cursor up and down to the Driver position and press the space button to cancel the selection; use the same operation to cancel the other three options and only install the main body of CUDA Toolkit 11.8 (as shown in the figure)

Continue to move the cursor to Options and press Enter to enter the installation configuration interface (as shown below)

Insert image description here

Move the cursor to Toolkit Options and press Enter to enter the CUDA installation and configuration interface\

Insert image description here

As shown above, remove all multi-select options, especially the Create symbolic link from /usr/local/cuda option. It is best to remove it. After the installation is completed, the cuda soft link directory will not be generated under /usr/local/. This soft link directory cannot be modified during the installation process. When we install multiple versions of CUDA, this soft link directory will be overwritten repeatedly, which will cause unnecessary trouble for us to use CUDA.

CUDA is installed in the /usr/local/ directory by default. Generally, the Change Toolkit Install Path does not need to be modified . However, if it is installed by an ordinary user, the installation path needs to be set to the user's home directory. Move the cursor to Change Toolkit Install Path and press Enter. After manually modifying the installation path, press Enter to exit the path configuration interface.

Insert image description here

If you want to modify the path, you can set it to the location you want, such as /home/username/app/cuda-11.8/

4. Set up the CUDA environment

If you choose to install in the default path with the root user in the previous step, the ordinary user environment variable configuration is as follows:

export PATH=/usr/local/cuda-11.8/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.8/lib64

If an ordinary user installs it in his or her own user directory, the environment variable configuration is as follows:

export PATH=/home/duyong/apps/cuda-11.8/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/duyong/apps/cuda-11.8/lib64

Make user profiles effective immediately

source ~/.bashrc

Verify whether CUDA is installed successfully

nvcc -V

If there is output similar to the following, the installation is successful.

nvcc: NVIDIA ® Cuda complier driver
Copyright © 2005-2022 NVIDIA Coropration
Bulit on Wed_Jun__8_16:49:14_PDT_2022
Cuda copiltation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler .31442593_0

Restart after installation is complete

5. Install CUDNN

Official website download address: (requires registration)

https://developer.nvidia.com/cudnn
Insert image description here
Insert image description here
Insert image description here
Click to download. After the download is complete, unzip the file, open the terminal in the current folder, and enter:

sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

This step is to copy the file to the specified location and grant permissions

To verify whether the installation is successful, enter:

cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

If the installation is successful, there will be an output similar to the picture below.
Insert image description here

6. Install Anaconda

Reference: Ubuntu 20.04 Installation and Simple Use of Anaconda3

7. Install Pytorch2

Reference: Super detailed steps to install PyTorch on Ubuntu

Reference article

  1. https://zhuanlan.zhihu.com/p/590877041
  2. https://blog.csdn.net/hwh295/article/details/113409389
  3. https://blog.csdn.net/Perfect886/article/details/119109380
  4. https://zhuanlan.zhihu.com/p/61255639
  5. https://blog.csdn.net/m0_50117360/article/details/108403586
  6. https://blog.csdn.net/KRISNAT/article/details/124068391

Guess you like

Origin blog.csdn.net/qq_43775794/article/details/131770933