真机安装 Ubuntu 及基本配置

By | 2022年12月19日

1. 用 rufus 制作 Ubuntu U盘启动盘

家里电脑 CPU X86 架构,系统是 Windows10,下面将它换成 Ubuntu,当前下载的最新版是 ubuntu-22.04.1-desktop-amd64.iso,不同版本安装基本都一样,Ubuntu 官方下载地址

Windows 上装好 Rufus,插入U盘,按下面设置制作启动盘:

装好后,U盘被占 4 个GB,Ubuntu 22 被装在里面了,无需放 iso 镜像。

2. 安装步骤

BIOS 上选择 U盘启动就不讲了,这里最关键的是要 开启CSM选择UEFI

设好 UEFI 重启电脑,就出来下面选项了,选择 Try or Install Ubuntu 开始安装:

3. 设置国内原

先备份原来的源:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

接着执行 vi /etc/apt/sources.list 编辑源,依次按 :%d 三个字符清空文件,放入下面内容:

# deb cdrom:[Ubuntu 22.04 LTS _Jammy Jellyfish_ - Release amd64 (20220419)]/ jammy main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted
# deb-src http://security.ubuntu.com/ubuntu jammy-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security universe
# deb-src http://security.ubuntu.com/ubuntu jammy-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu jammy-security multiverse

# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.

接着使用命令 sudo apt update 更新源就好了。

4. 安装 SSH 服务

# 安装 SSH 服务
apt install -y openssh-server

# 安装 vim(通过 vi 改 ssh 文件太难受)
apt install -y vim

允许 root 账户使用 SSH:

vim /etc/ssh/sshd_config

找到 PermitRootLogin prohibit-password 注释掉,下面加一条 PermitRootLogin yes,改好后重启服务:

systemctl start sshd

5. 允许 root 账号登录桌面

默认 root 账号无法登录桌面的,下面来支持下,先配个 root 密码:

sudo passwd root

接下来执行 su root 切换到 root 账户下操作:

vim /etc/pam.d/gdm-autologin

找到 auth required pam_succeed_if.so user !=root quiet_success 加 # 注释,大概在第三行。

vim /etc/pam.d/gdm-password

auth required pam_succeed_if.so user !=root quiet_success 加 # 注释。

两处注释掉后重启电脑,就可以用 root 账号来登录桌面了。

6. 安装 Nvidia GPU 显卡驱动

# 借助下面命令查看可安装驱动
ubuntu-drivers devices
# 安装带 recommend 标志的驱动
# 遇到在 GTX 3060 Ti 上装了 recommend 标志的驱动 nvidia-driver-525-open,重启无效,卸载后,指定装 nvidia-driver-525 重启就没问题了。
sudo apt install  -y nvidia-driver-525

装到一半出现 UEFI Secure boot 验证机制,需要输入一个 secure boot 密码(装 GTX 3060 Ti 时没有出现这个验证机制),以便重启系统时再次输入此密码来验证固件启动的代码是可信的:

安装完显卡驱动后,需重启加载驱动,重启后出现如下图,开始不懂选了第一个 Continue boot,致新安装的 N 卡驱动没有加载,想重新选择重启电脑却再也不不出来此界面:

出现 perform mok management 后正确的做法是:

  1. 当进入蓝色背景的界面perform mok management 后,选择 enroll mok
  2. 进入enroll mok 界面,选择 continue
  3. 进入enroll the key 界面,选择 yes
  4. 接下来输入你在安装驱动时输入的密码
  5. 之后会跳到蓝色背景的界面perform mok management 选择第一个 reboot

这样,重启后N卡驱动就加载了(ubuntu下搜索软件 nvidia):

也可以用下面的命令来测试 nvidia driver 是否安装成功:

nvidia-smi

对于像我一样刚开始 perform mok management 选错的,可以通过下面方式清理驱动,然后重新安装:

sudo apt remove -y --purge nvidia*
sudo apt update
sudo apt install  nvidia-driver-525

最后附上 Docker 中 GPU 的使用

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注