1 - 下载debian

下载 debian 的安装文件

debian 的安装文件分为两种

  • netinst : 小型安装镜像,安装过程中需要网络连接
  • cd/dvd: 完整的安装镜像,文件较大,包含更好的软件包,可以没有网络连接时安装。

安装目前(2024年11月)最新的 debian 12.8 。

下载 netinst

打开 debian 官网

https://www.debian.org/distrib/

下载最新的版本:

https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.8.0-amd64-netinst.iso

文件大小 662M。

下载 dvd

https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/

下载 debian-12.8.0-amd64-DVD-1.iso 文件,大小为 3.7G。

2 - 物理机安装

在物理机上安装 debian 12.7

准备工作

安装版本

更新时间是 2024-09-16, 安装的当时的最新版本 debian 12.7。

制作U盘

用下载下来的 iso 文件制作启动 u 盘。

windows 下一般用 refus 软件。

安装

启动后进入 debian 安装界面,选择 “Graphical install”

  • select language: english
  • select your location: other -> Asia -> China
  • configure locales: United States en_US.UTF-8
  • keyboard: American English

配置网络:

  • hostname: debian12.local

配置用户和密码:

  • password of root:
  • 创建新用户
    • full name: Sky Ao
    • username: sky
    • password:

硬盘分区,选择 Guided - use entire disk -> all files in one partition, 等默认分区方案出来之后, 先删除除了 esp 分区之后的分区,然后在空闲空间上选择 create a new partition,大小为空闲空间 - 50g左右(留给 timeshift 做备份), mount 为 /。剩下的约 50g 空间继续分区,mount 为 /var/timeshift

“Finish partitioning and write changes to disk” , 选下一步,会提示没有 swap 空间,询问要不要退回去,选择 no。

确认分区,然后开始安装 base system。

configure the package manager, 选 “china” -> “mirrors.ustc.edu.cn”。

software selection,这是选择要继续安装的内容:

  • debian desktop environment: 桌面,我当服务器用就不需要了,取消勾选
  • 选择 ssh server 和 standard system utilities

等待安装完成,重启。

小结

安装比较简单,而且过程中可以配置包管理器,这样避免了从国外拉包的麻烦,用国内的服务器速度还是非常好的,因此推荐用网络安装的方式,这样安装完成之后系统和各个包都是最新版本了。

3 - pve安装

在 pve8.1 下安装 debian 12.4

准备工作

创建虚拟机

General:

  • name: debian12

OS:

  • iso image: 选 netinst.iso
  • type: linux
  • version: 6.x - 2.6 kernel

System:

  • Graphic card: default
  • Machine: q35 (直通时必须)
  • SCSI controller: Virtio SCSI single
  • qemu agent: 勾选
  • bios: OVMF(UEFI) (直通时必须)
  • EFI storage: local
  • Format: qemu image format(qcow2)

Disk:

  • bus/device: SCSI
  • SCSI Controller: 自动选择 Virtio SCSI single
  • Cache: default
  • IO Thread: 勾选
  • Storage: local
  • format: QEMU image format(qcow2)
  • 高级选项中:勾选 backup
  • side: 512g

cpu:

  • Type:host (暂时不用担心迁移的问题)
  • Socket:1
  • Cores: 4

Memory:

  • memory: 8192
  • minimum memory: 2048

Network:

  • bridage: vmbr0
  • model: virtIO

确认之后,先别启动,在虚拟机属性中,找到 boot order ,去掉 net0,保留 csi0 和 ide2 光盘启动。

备注:一定要保留硬盘启动并且在光盘前,否则安装完成后重启又进入安装流程了。而 pve 有bug,这种情况下无法关机,只能把整机重启,非常烦人。

安装

启动并开始安装

启动后进入 debian 安装界面,选择 “Graphical install”

  • select language: english
  • select your location: other -> Asia -> China
  • configure locales: United States en_US.UTF-8
  • keyboard: American English

配置网络:

  • hostname: debian12.local

配置用户和密码:

  • password of root:
  • 创建新用户
    • full name: Sky Ao
    • username: sky
    • password:

硬盘分区,选择 Guided - use entire disk -> all files in one partition, 等默认分区方案出来之后, 先删除除了 esp 分区之后的分区,然后在空闲空间上选择 create a new partition,大小为空闲空间 - 50g左右(留给 timeshift 做备份), mount 为 /。剩下的约 50g 空间继续分区,mount 为 /timeshift

“Finish partitioning and write changes to disk” , 选下一步,会提示没有 swap 空间,询问要不要退回去,选择 no。

确认分区,然后开始安装 base system。

安装完成后,询问要不要扫描更多的媒体,选择 no。

configure the package manager, 选 “china” -> “mirrors.ustc.edu.cn”。

software selection,这是选择要继续安装的内容:

  • debian desktop environment: 桌面,我当服务器用就不需要了,取消勾选
  • 选择 ssh server 和 standard system utilities

等待安装完成,重启。

4 - raid安装

组建 raid 设备并安装 debian 12

先准备好两块硬盘,重新分区,并保持两个硬盘的分区方案一致。

第一块硬盘,先后分区为:

  • 512 MB: 分区选择 “EFI System Partition”
  • 剩余空间-30g:分区选择不使用该分区(use as:“do not use”),准备 raid 后给 “/” 用
  • 30g:分区选择不使用该分区(use as:“do not use”),准备 raid 后给 “/timeshift” 用

第二块硬盘和第一块硬盘保持一致,先后分区为:

  • 512 MB: 分区选择不使用该分区(use as:“do not use”)
  • 剩余空间-30g:分区选择不使用该分区(use as:“do not use”),准备 raid 后给 “/” 用
  • 30g:分区选择不使用该分区(use as:“do not use”),准备 raid 后给 “/timeshift” 用

然后选择 “Configure software RAID”, 将两块大的分区和两块小的分区分别创建 raid0 。

这样就得到两个 raid0 device,大小分别为 1.7t 和 60g。

分别格式化为 ext4,挂载为 “/” 和 “/timeshift” 。

然后正常安装 debian12。

5 - 安装完成后的基本配置

在 debian 12.4 安装完成后的基本配置

5.1 - timeshift

安装配置 timeshift 进行备份

备注:安装完成之后,第一时间安装 timeshift 进行备份,后续操作中出现任何失误都可以通过 timeshift 来选择性的恢复到中间状态,避免出错后需要重新安装。

具体操作参考:

https://skyao.io/learning-ubuntu-server/docs/installation/timeshift/

安装

先 su 到 root,再进行安装:

su root
apt install timeshift

配置

找到 timeshift 分区的 UUID:

lsblk -f

例如这个机器有三块硬盘, /var/timeshift 所在的分区 UUDI 为 3c5ad47e-4318-4797-8342-7e602ac524d2

$ lsblk -f
NAME        FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
nvme1n1                                                                            
`-nvme1n1p1 ext4   1.0         ccae6bf3-d4cd-422d-b67a-b5b8dfe83fc6  782.2G     0% /var/data2
nvme0n1                                                                            
`-nvme0n1p1 ext4   1.0         eff3a45e-be5e-4f5e-a969-0998a8a10e33  782.2G     0% /var/data
nvme2n1                                                                            
|-nvme2n1p1 vfat   FAT32       C4B5-2470                             505.1M     1% /boot/efi
|-nvme2n1p2 ext4   1.0         41949492-a351-4770-80f6-d4c7dc5b23bc  171.2G     1% /
`-nvme2n1p3 ext4   1.0         3c5ad47e-4318-4797-8342-7e602ac524d2     48G     0% /var/timeshift

然后设置 backup_device_uuid ,注意 timeshift 在第一次使用时会读取 default.json 文件:

vi /etc/timeshift/default.json

验证一下:

timeshift --list

这个时候还没有进行备份,没有 snapshot:

timeshift --list
First run mode (config file not found)
Selected default snapshot type: RSYNC
Mounted '/dev/nvme2n1p3' at '/run/timeshift/3424/backup'
Device : /dev/nvme2n1p3
UUID   : 3c5ad47e-4318-4797-8342-7e602ac524d2
Path   : /run/timeshift/3424/backup
Mode   : RSYNC
Status : No snapshots on this device
First snapshot requires: 0 B

No snapshots found

此时会自动创建配置文件 /etc/timeshift/timeshift.json,后续修改配置就要修改这个文件。

配置 excludes

除了基本的 backup_device_uuid 外,还需要配置 excludes 以排除不需要 timeshift 进行备份的内容。

{
  "backup_device_uuid" : "3c5ad47e-4318-4797-8342-7e602ac524d2",
  ......
  "exclude" : [
    "/root/**",
    "/home/**",
    "/timeshift/**",
    "/var/data/**",
    "/var/data2/**",
    "/var/data3/**"
  ],
  ......
}

需要排除的内容通常包括用户目录(/root//home/),以及资料存储如我这里的 "/var/data/ 等几块用来存储的硬盘,以及 timeshift 自身所在目录 /timeshift/ (取决于安装debian时选择的timeshift分区的挂载路径)。

配置自动备份

设置每天/每周/每月的自动备份:

{
  ......
  "schedule_monthly" : "true",
  "schedule_weekly" : "true",
  "schedule_daily" : "true",
  ......
  "count_monthly" : "2",
  "count_weekly" : "3",
  "count_daily" : "5",
  ......
}

创建快照

先不做任何操作,在操作系统安装完成之后,第一时间进行备份:

timeshift --create --comments "first backup after install"

第一次备份大概要消耗2.3g的存储空间。

5.2 - path修改

修改默认path路径避免找不到命令的错误

问题描述

debian 12 默认的 PATH 路径有点少:

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/games

很多常见的命令都会因为不包含在 PATH 中而无法使用,报错 “command not found”:

$ usermod -aG sudo sky
bash: usermod: command not found

打开 /etc/profile 文件看到:

if [ "$(id -u)" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH

看上去像是没有自动 source /etc/profile,比如我用 su 到 root 账号后执行 source,那就正常的得到上面的 PATH:

$ su root
Password: 
$ id
uid=0(root) gid=0(root) groups=0(root)
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/games
$ source /etc/profile
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

普通账号的修复

对于普通账号,比如我安装时建立的 sky 账号,只要简单在 .zshrc 中加入:

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=$HOME/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

重新登录 sky 账号,验证即可:

$ echo $PATH

/home/sky/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

这个需要先安装 zsh 和 oh-my-zsh,bash 应该类似,只是我目前基本只用 zsh。

root 账号的修复

貌似没有找到解决不自动 source /etc/profile 的办法,所以只能手工执行

source /etc/profile

来解决。或者,类似 sky 账号那样,安装 zsh 和 oh-my-zsh,但发现 root 账号不能改成默认使用 zsh,只能在 su 到 root 账号之后,手工执行 zsh 来从 bash 换到 zsh。

5.3 - sudo设置

增加账号的sudo权限

安装

先 su 到 root 账号,安装 sudo:

apt install sudo

问题

安装时默认的 sky 账号是没有 sudo 权限的:

$ id
uid=1000(sky) gid=1000(sky) groups=1000(sky),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),100(users),106(netdev)

$ sudo ls
[sudo] password for sky: 
sky is not in the sudoers file.

解决方案

先 su 为 root,然后为 sky 账号加入 sudo:

# 如果没有修复 path 的问题,则会报错找不到 usermod
# export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
usermod -aG sudo sky

退出 sky 账号,再次登录就可以 sudo 了:

$ ls                                                                                      
[sudo] password for sky: 
bin  debian12  temp  work
$ id
uid=1000(sky) gid=1000(sky) groups=1000(sky),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),100(users),106(netdev)

5.4 - git

安装配置 git

直接 apt 安装:

apt install git

检查版本:

$ git version
git version 2.39.5

配置代理

mkdir -p ~/.ssh/
vi ~/.ssh/config

增加内容为:

# for  github
Host github.com
    HostName github.com
    User git
    # for HTTP proxy
    #ProxyCommand socat - PROXY:192.168.0.1:%h:%p,proxyport=7890
    #ProxyCommand socat - PROXY:192.168.2.1:%h:%p,proxyport=7890
    #ProxyCommand socat - PROXY:192.168.3.1:%h:%p,proxyport=7890
    #ProxyCommand socat - PROXY:192.168.5.1:%h:%p,proxyport=7890
    # for socks5 proxy
    #ProxyCommand nc -v -x 192.168.0.1:7891 %h %p
    #ProxyCommand nc -v -x 192.168.2.1:7891 %h %p
    #ProxyCommand nc -v -x 192.168.3.1:7891 %h %p
    #ProxyCommand nc -v -x 192.168.5.1:7891 %h %p
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_github

其他设置参考: https://skyao.io/learning-git/docs/installation/initial/

5.5 - zsh

安装配置zsh和ohmyzsh!

安装配置 zsh

安装zsh

首先安装 zsh:

sudo apt install zsh zsh-doc

安装 Oh my zsh!

在 zsh 终端执行:

# 如果被墙则增加代理设置
# export all_proxy=socks5://192.168.2.1:7891

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

DNS 污染问题:

如果遇到 DNS 污染,导致 raw.githubusercontent.com 被解析到 127.0.0.1 或者 0.0.0.1 导致无法访问。需要修改 hosts 文件:

sudo vi /etc/hosts

增加一行:

199.232.68.133 raw.githubusercontent.com

中途询问是否把zsh作为默认 shell 时选择Y:

Do you want to change your default shell to zsh? [Y/n] Y
Changing the shell...

安装字体和主题

在这里下载并安装几个字体

https://github.com/romkatv/powerlevel10k#meslo-nerd-font-patched-for-powerlevel10k

  • MesloLGS NF Regular.ttf
  • MesloLGS NF Bold.ttf
  • MesloLGS NF Italic.ttf
  • MesloLGS NF Bold Italic.ttf
mkdir -p ~/.fonts
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf -O ~/.fonts/MesloLGS_NF_Regular.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf -O ~/.fonts/MesloLGS_NF_Bold.ttf  
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf -O ~/.fonts/MesloLGS_NF_Italic.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf -O ~/.fonts/MesloLGS_NF_Bold_Italic.ttf

执行

$ ls ~/.fonts

可以看到下载好的字体文件:

MesloLGS_NF_Bold_Italic.ttf  MesloLGS_NF_Bold.ttf  MesloLGS_NF_Italic.ttf  MesloLGS_NF_Regular.ttf

执行

fc-cache -f -v

可以看到字体缓存成功:

Font directories:
        /root/.local/share/fonts
        /usr/local/share/fonts
        /usr/share/fonts
        /root/.fonts
......
/root/.fonts: caching, new cache contents: 4 fonts, 0 dirs
......
fc-cache: succeeded

下载安装 Powerlevel10k 主题:

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

修改

vi ~/.zshrc

增加内容:

ZSH_THEME="powerlevel10k/powerlevel10k"
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(history)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=1

# User configuration
export LS_COLORS="rs=0:no=00:mi=00:mh=00:ln=01;36:or=01;31:di=01;34:ow=04;01;34:st=34:tw=04;34:pi=01;33:so=01;33:do=01;33:bd=01;33:cd=01;33:su=01;35:sg=01;35:ca=01;35:ex=01;32:"

安装插件

安装 wd 插件:

sh -c "$(curl -fsSL https://github.com/mfaerevaag/wd/raw/master/install.sh)"

配置以下插件:

git clone https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-history-substring-search.git $ZSH_CUSTOM/plugins/history-substring-search
git clone https://github.com/Pilaton/OhMyZsh-full-autoupdate.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/ohmyzsh-full-autoupdate

修改 zsh 配置

vi ~/.zshrc

注释掉这一行:

DISABLE_MAGIC_FUNCTIONS="true"

修改 plugins 为

plugins=(    
    git
    golang
    rust
    docker
    docker-compose 
    kubectl
    npm
    node
    mvn
    sudo
    helm
    redis-cli
    wd 
    zsh-autosuggestions
    zsh-syntax-highlighting
    history-substring-search
    ohmyzsh-full-autoupdate
)

# User configuration

ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor root line)
ZSH_HIGHLIGHT_PATTERNS=('rm -rf *' 'fg=white,bold,bg=red')

重启 zsh。

Updating plugins and themes Oh My ZSH
--------------------------------------

Updating Plugin — ohmyzsh-full-autoupdate -> https://github.com/Pilaton/OhMyZsh-full-autoupdate
Already up to date.

Updating Plugin — zsh-autosuggestions -> https://github.com/zsh-users/zsh-autosuggestions
Already up to date.

Updating Plugin — zsh-syntax-highlighting -> https://github.com/zsh-users/zsh-syntax-highlighting
Already up to date.

Updating Theme — powerlevel10k -> https://github.com/romkatv/powerlevel10k
Already up to date.

备注: 这个自动更新可能会因为 github.com 被墙无法访问而失败。可以修改 .zshrc 的设置,默认开启代理避免更新时被墙:

# auto start proxy on
export all_proxy=socks5://192.168.2.1:7891;export http_proxy=http://192.168.2.1:7890;export https_proxy=http://192.168.2.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16

然后手工更新 ohmyzsh:

# proxyon
omz update

执行完 ohmyzsh 的更新之后,关闭所有的终端,再重新打开,就会触发 zsh plugins 的自动更新。

配置网络代理

修改 zsh 配置

vi ~/.zshrc

增加以下内容:

# set proxy for different locations
alias proxyon-nansha='export all_proxy=socks5://192.168.0.1:7891;export http_proxy=http://192.168.0.1:7890;export https_proxy=http://192.168.0.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
alias proxyon-tianhe='export all_proxy=socks5://192.168.2.1:7891;export http_proxy=http://192.168.2.1:7890;export https_proxy=http://192.168.2.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
alias proxyon-fenghu='export all_proxy=socks5://192.168.3.1:7891;export http_proxy=http://192.168.3.1:7890;export https_proxy=http://192.168.3.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
alias proxyon-local='export all_proxy=socks5://127.0.0.1:7897;export http_proxy=http://127.0.0.1:7897;export https_proxy=http://127.0.0.1:7897;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
# set default proxy by this line
alias proxyon='proxyon-local'
alias proxyoff='unset all_proxy http_proxy https_proxy no_proxy'
# uncomment next line to enable proxy by default when zsh is opened
# proxyon

5.6 - 网络代理

设置网络代理

设置网络代理

我通常在 openwrt 上安装 openclash,支持 socks5 和 http 代理,因此设置很简单:

vi ~/.zshrc

加入以下内容:

# set proxy for different locations
alias proxyon-nansha='export all_proxy=socks5://192.168.0.1:7891;export http_proxy=http://192.168.0.1:7890;export https_proxy=http://192.168.0.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
alias proxyon-tianhe='export all_proxy=socks5://192.168.2.1:7891;export http_proxy=http://192.168.2.1:7890;export https_proxy=http://192.168.2.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
alias proxyon-shanghai='export all_proxy=socks5://192.168.3.1:7891;export http_proxy=http://192.168.3.1:7890;export https_proxy=http://192.168.3.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
alias proxyon-cudy='export all_proxy=socks5://192.168.5.1:7891;export http_proxy=http://192.168.5.1:7890;export https_proxy=http://192.168.5.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
# set default proxy by this line
alias proxyon='proxyon-nansha'
alias proxyoff='unset all_proxy http_proxy https_proxy no_proxy'
# uncomment next line to enable proxy by default when zsh is opened
# proxyon

开启网络代理

需要开启代理时,输入 proxyon 命令就设置好代理了。不使用时 proxyoff 关闭。

5.7 - 安装其他软件

安装其他软件

安装操作系统相关的软件

sudo apt install dkms

这个过程中会自动安装 linux-headers 。

常用工具软件

sudo apt install htop unzip zip curl

网络速度测试软件:

sudo apt install iperf iperf3

修复 locale 报错

默认安装之后经常在执行各种命令时看到如下的警告:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_CTYPE = "UTF-8",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

可以通过执行 locale 命令来重现这个警告:

解决方案,

vi ~/.zshrc

增加内容:

export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

执行

source ~/.zshrc

验证结果。

参考:

6 - 内核配置

debian 核心的升级和清理

6.1 - 查看内核版本

查看 debian 核心版本信息

查看当前 debian 内核的版本:

$ uname -r
6.1.0-31-amd64
$ uname -v
#1 SMP PREEMPT_DYNAMIC Debian 6.1.128-1 (2025-02-07)
$ uname -a
Linux debian12 6.1.0-31-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.128-1 (2025-02-07) x86_64 GNU/Linux

这说明安装时的内核版本为 6.1.0-31-amd64,当前已经更新到 6.1.0-31-amd64 版本(debian 12.9,更新时间 2025-02-07)。

其他方式:

$ cat /proc/version
Linux version 6.1.0-31-amd64 (debian-kernel@lists.debian.org) (gcc-12 (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40) #1 SMP PREEMPT_DYNAMIC Debian 6.1.128-1 (2025-02-07)

dmesg 命令:

$ sudo dmesg | grep Linux
[    0.000000] Linux version 6.1.0-31-amd64 (debian-kernel@lists.debian.org) (gcc-12 (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40) #1 SMP PREEMPT_DYNAMIC Debian 6.1.128-1 (2025-02-07)
......

dpkg 命令:

$ dpkg --list | grep linux-image
ii  linux-image-6.1.0-31-amd64      6.1.128-1                       amd64        Linux 6.1 for 64-bit PCs (signed)
ii  linux-image-amd64               6.1.128-1                       amd64        Linux for 64-bit PCs (meta-package)

$ dpkg --list | grep -Ei 'linux-image|linux-headers|linux-modules'
ii  linux-image-6.1.0-31-amd64      6.1.128-1                       amd64        Linux 6.1 for 64-bit PCs (signed)
ii  linux-image-amd64               6.1.128-1                       amd64        Linux for 64-bit PCs (meta-package)

6.2 - 更新内核

更新 debian 核心

可以单独更新 linux 内核:

$ sudo apt update
$ sudo apt install linux-image-amd64

也可以使用 apt upgrade 更新所有内容:

$ sudo apt update
$ sudo apt upgrade

6.3 - 删除内核

删除不再需要的 debian 核心

多次升级之后,系统内就会累计有多个内核版本,可以考虑删除旧的不用的内核。

参考:

https://askubuntu.com/questions/1253347/how-to-easily-remove-old-kernels-in-ubuntu-20-04-lts

vi remove_old_kernels.sh

新建一个文件内容如下:

#!/bin/bash
# Run this script without any param for a dry run
# Run the script with root and with exec param for removing old kernels after checking
# the list printed in the dry run

uname -a
IN_USE=$(uname -a | awk '{ print $3 }')
if [[ $IN_USE == *-generic ]]
then
  IN_USE=${IN_USE::-8}
fi
echo "Your in use kernel is $IN_USE"

OLD_KERNELS=$(
    dpkg --list |
        grep -v "$IN_USE" |
        grep -v "linux-headers-generic" |
        grep -v "linux-image-generic"  |
        grep -Ei 'linux-image|linux-headers|linux-modules' |
        awk '{ print $2 }'
)
echo "Old Kernels to be removed:"
echo "$OLD_KERNELS"

if [ "$1" == "exec" ]; then
    for PACKAGE in $OLD_KERNELS; do
        yes | apt purge "$PACKAGE"
    done
fi

执行

bash ./remove_old_kernels.sh

看查看到要删除的内核版本和相关的包,确认没有问题之后再通过

sudo bash ./remove_old_kernels.sh exec

进行实际删除。

之后重启,再检查现有的内核是否符合预期。

7 - 克隆后的配置

在 debian 12.4 从模版克隆后的配置

在使用 pve 等虚拟化软件时,为了方便重用,会将配置好的 debian 系统制作成模版,然后使用时从模版克隆出来。

这样就会有一些特殊的配置需要在克隆之后进行。

7.1 - 修改hostname

克隆后修改hostname

参考:

https://skyao.io/learning-ubuntu-server/docs/installation/basic/change-hostname

7.2 - 静态IP地址

克隆后设置静态IP地址

每个克隆后的虚拟机都应该有自己固定的ip地址,但是通过 dhcp 来修改不合适,毕竟这些经常变化。

因此需要设置静态 ip 地址,每次克隆之后虚拟机就自行设置。

设置静态ip

修改前先备份:

sudo cp /etc/network/interfaces /etc/network/interfaces.bak

看一下目前的网络适配器情况,enp6s18 是正在使用的网卡:

$ ip addr
2: enp6s18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether bc:24:11:97:c4:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.20.228/24 brd 192.168.20.255 scope global dynamic enp6s18

修改网络设置:

sudo vi /etc/network/interfaces

将 enp6s18 原有的配置:

# The primary network interface
allow-hotplug enp6s18
iface enp6s18 inet dhcp

修改为:

# The primary network interface
allow-hotplug enp6s18
# iface enp6s18 inet dhcp
iface enp6s18 inet static
address 192.168.20.25
netmask 255.255.255.0
gateway 192.168.20.1
dns-nameservers 192.168.20.1

保存后重启网络:

sudo systemctl restart networking

之后就可以用新的 ip 地址访问了。

参考资料