# Debian 安裝指南 [ToC] ## 準備安裝介質 - 準備安裝用隨身碟:參考 Ventoy [官方網站](https://www.ventoy.net/cn/index.html) - 使用 Ventoy 好處:不需要為每個 OS 都準備一個安裝介質等 - 到 Debian 官方網站下載最新的[網路安裝 ISO](https://www.debian.org/distrib/index.zh-tw.html) - 放到隨身碟的 Ventoy 分區 - **注意事項** - Ventoy 安裝程式僅能在 Windos 和 Linux 上使用 - 在安裝的時候記得把磁碟分割表改成 GPT - Ventoy 安裝程式預設會開啟 Secure Boot,需要另外 Enroll key;如果選擇關閉,在使用時也要先到 Bios 關閉 Secure Boot ## 安裝 Debian - 使用剛剛準備的隨身碟,直接用 Graphic Installer 即可 - 分區 - EFI(建議 256~512MB,如有其他需求(要用 UKI 之類的),可以到 1GB) - SWAP(個人使用與記憶體 1:1) - ROOT(剩餘容量全部) - 其他分區按需求自行分割 - 選擇 APT Mirror:建議先選擇地區預設(第一個),之後再改成其他的 - Tasksel:僅選擇 Standard System Utility,DE 另外安裝 - 等安裝更新完重新開機即可 ## 設定 sudo - 進到系統登入後,先進到 root 環境安裝 sudo - 修改 /etc/sudoers,修改方式如下 ![image](https://hackmd.io/_uploads/Byqgx4mzke.png) - 退出 root 環境,執行 sudo -s 確定成功設定權限 ## 更新到 Debian Unstable - 更新到 Unstable(Sid)版本獲得更新版本的套件 - 修改 /etc/apt/source.list ```shell deb https://debian.csie.ntu.edu.tw/debian/ unstable main contrib non-free non-free-firmware deb-src https://debian.csie.ntu.edu.tw/debian/ unstable main contrib non-free non-free-firmware deb https://security.debian.org/debian-security stable-security main contrib non-free non-free-firmware deb-src https://security.debian.org/debian-security stable-security main contrib non-free non-free-firmware deb https://debian.csie.ntu.edu.tw/debian/ stable-updates main contrib non-free non-free-firmware deb-src https://debian.csie.ntu.edu.tw/debian/ stable-updates main contrib non-free non-free-firmware ``` - 要使用 apt over https 需要安裝 apt-transport-https - 更新系統 ```shell sudo apt update && sudo apt full-upgrade -y && sudo apt dist-upgrade -y sudo apt autoremove -y ``` - 更新完先重新啟動系統 ## 安裝 NVIDIA Driver > 因為 Debian 提供的版本較舊,建議參考 Nvidia [官方安裝指南](https://docs.nvidia.com/datacenter/tesla/driver-installation-guide/index.html#post-installation-actions) ### 安裝流程 - 移除舊的 Apt key ```shell # 此處需要先安裝 gnupg sudo apt-key del 7fa2af80 ``` - 先安裝 NVIDIA 的 Apt Repo,根據使用的 Distro 跟 Arch 修改網址 ```shell wget https://developer.download.nvidia.com/compute/cuda/repos/{{ distro }}/{{ arch }}/cuda-keyring_1.1-1_all.deb sudo dpkg -i cuda_keyring_1.1-1_all.deb sudo apt update ``` - 安裝 Linux Headers(很重要,一定要先裝) ```shell sudo apt install linux-headers-$(uname -r) -y ``` - 安裝 NVIDIA driver ```shell sudo apt install nvidia-driver -y ``` - 安裝 NVIDIA kernel module(選擇以下任一) ```shell # open source sudo apt install nvidia-open -y # proprietary sudo apt install cuda-drivers -y ``` - 如有開啟 Secure Boot,需 Enroll key 這樣之後更新才能自動 signed kernel module >參考[此頁](https://wiki.debian.org/SecureBoot#DKMS_and_secure_boot) ```shell sudo mokutil --import /var/lib/dkms/mok.pub # prompts for one-time password sudo mokutil --list-new # recheck your key will be prompted on next boot # rebooting machine then enters MOK manager EFI utility: enroll MOK, continue, confirm, enter password, reboot sudo dmesg | grep cert # verify your key is loaded ``` ### Wayland 相關設定 >此處參考 [Debian Wiki](https://wiki.debian.org/NvidiaGraphicsDrivers#Wayland) - Enable kernel modesetting with the NVIDIA driver: ```shell echo 'GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX nvidia-drm.modeset=1"' > /etc/default/grub.d/nvidia-modeset.cfg sudo update-grub ``` - 啟用 nvidia-suspend-common ```shell sudo systemctl enable nvidia-suspend.service sudo systemctl enable nvidia-hibernate.service sudo systemctl enable nvidia-resume.service ``` - PreserveVideoMemoryAllocations ```shell cat /proc/driver/nvidia/params | grep PreserveVideoMemoryAllocations # 如以上結果為 1 則不需要進行下一步設定 echo 'options nvidia NVreg_PreserveVideoMemoryAllocations=1' > /etc/modprobe.d/nvidia-power-management.conf ``` - 設定完重新開機 ### 安裝 Cuda > 參考[官方說明](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/#common-installation-instructions-for-debian) ## 安裝 Gnome DE - 執行以下指令安裝精簡版的桌面環境 ```shell sudo apt install --no-install-recommends --no-install-suggests \ gnome-core \ network-manager network-manager-gnome \ bluetooth-gnome \ gnome-shell-extensions gnome-shell-extension-manager \ seahorse \ xdg-user-dirs -y ``` - 安裝完重新啟動 - 進入桌面環境後,建議移除幾個用不到的程式 ```shell sudo apt remove gnome-calculator \ gnome-calendar \ gnome-snapshot \ gnome-characters \ gnome-clocks \ gnome-connections \ gnome-contacts \ baobab \ simple-scan \ evince \ yelp \ totem \ gnome-logs \ gnome-maps \ gnome-software \ gnome-text-editor \ gnome-weather -y sudo apt autoremove -y ``` ## SSH - 安裝以下兩個套件 ```shell sudo apt install openssh-server \ avahi-daemon -y ``` - avahi-daemon 可以啟用 mDNS 讓其他在同個區域網路的機器能更簡單的 SSH 連線到本機 ## 其他 > 以下為個人偏好設定 - **推薦安裝套件** ```shell sudo apt install nala -y sudo nala install ``` ### XDG Base Directory > 讓 home diretory 能更乾淨 - 在 /etc/zsh/zshenv 裡設定以下幾個環境變數 ```shell export XDG_CONFIG_HOME="$HOME/.config" export XDG_CACHE_HOME="$HOME/.cache" export XDG_DATA_HOME="$HOME/.local/share" export XDG_STATE_HOME="$HOME/.local/state" export XDG_RUNTIME_DIR="/run/user/$UID" export XDG_DATA_DIRS="/usr/local/share:/usr/share" export XDG_CONFIG_DIRS="/etc/xdg" ``` - 有些軟體不特別設定的話還是會把東西塞到 home ,所以還是明確地設定一下 - 如果 home directory 已經亂了或是不知道要把設定檔放哪,可以參考以下工具 - [XDG Base Directory - Arch Wiki](https://wiki.archlinux.org/title/XDG_Base_Directory) - [XDG ninija](https://github.com/b3nj5m1n/xdg-ninja) ### Shell:ZSH - 同樣在 /etc/zsh/zshenv 下設定環境變數 ```shell export ZDOTDIR="$HOME/.config/zsh" ``` - 切換預設 SHELL 到 Zsh > 先確保安裝的 Zsh 的 path 有被寫到 /etc/shells ```shell chsh -s {{ path to zsh }} ``` #### Plugin Manager: Zplug - 安裝:見官方 [Repo](https://github.com/zplug/zplug) - 推薦安裝 Plugin - ### Terminal:Alacritty ### Python > - Toolchain:UV - 安裝 ```shell # 引入 APT repo,也可用官方安裝方式 curl -sSL https://raw.githubusercontent.com/upciti/wakemeops/main/assets/install_repository | sudo bash # 安裝 sudo apt install uv -y ``` - 類似 Rust 的 Cargo,也是用 Rust 寫的,快速好用 - Linter & Formatter:Ruff - 安裝 ```shell sudo apt install ruff -y ```