脚本笔记8/27/2026
nvidia.sh
来源文件:
nvidia.sh
已自动脱敏 8 处敏感信息。
bash
apt install ubuntu-drivers-common
ubuntu-drivers devices
apt install libnvidia-common-535 libnvidia-gl-535 nvidia-driver-535 -y
wget https://developer.download.nvidia.com/compute/cuda/12.2.2/local_installers/cuda_12.2.2_535.104.05_linux.run
sudo sh cuda_12.2.2_535.104.05_linux.run
echo 'export PATH="/usr/local/cuda-12.2/bin${PATH:+:${PATH}}"' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH="/usr/local/cuda-12.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"' >> ~/.bashrc
source ~/.bashrc
sudo ldconfig
apt install -y nvidia-container-toolkit
nvidia-ctk runtime configure --runtime=docker
docker run --rm --runtime=nvidia --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi
add-apt-repository ppa:graphics-drivers/ppa
apt update
apt install nvidia-driver-550-server nvidia-cuda-toolkit libcurl4-openssl-dev -y
/etc/wgetrc
https_proxy = http://[REDACTED_IP]:18001/
http_proxy = http://[REDACTED_IP]:18001/
ftp_proxy = http://[REDACTED_IP]:18001/
use_proxy = on
docker run -d --restart=on-failure \
--name my_workspace \
--gpus all \
--shm-size=1024m \
-e USER=ubuntu \
-e PASSWORD=[REDACTED] \
-e GID=$(id -g) \
-e UID=$(id -u) \
-e REMOTE_DESKTOP=kasmvnc \
-p 10022:22 \
-p 14000:4000 \
registry.cn-hongkong.aliyuncs.com/gezp/ubuntu-desktop:20.04-cu11.0.3
--gpus all --shm-size=1024m -e USER=ubuntu -e PASSWORD=[REDACTED] -e GID=0 -e UID=0 -e REMOTE_DESKTOP=kasmvnc -p 10022:22 -p 14000:4000
docker run -d --restart=on-failure --name my_workspace --gpus all --shm-size=1024m -e USER=simon -e PASSWORD=[REDACTED] -p 10022:22 -p 13389:3389 ubuntu-desktop:22.04-cu11.8.0
docker run -d --restart=on-failure --name my --gpus all -p 10022:22 -p 13389:3389 ubuntu-desktop:22.04-cu11.8.0
nvidia-ctk runtime configure --runtime=docker --set-as-default
service docker restart
docker run -v $PWD:[REDACTED] -p 3000:3000 --gpus all -it -d --name webtop linuxserver/webtop:ubuntu-xfce
docker run --network host --gpus all --privileged -d --name=webtop -e PUID=1000 -e PGID=1000 -e TZ=Asia/Shanghai -v $PWD:[REDACTED] -v /var/run/docker.sock:/var/run/docker.sock --shm-size="1gb" linuxserver/webtop:ubuntu-xfce
# 22.04带3389 linuxserver/webtop:amd64-ubuntu-kde-781d8753-ls91
XAUTH=$(ps a | grep Xorg | awk -F '-auth ' '{print $2}' | awk '{print $1}' | head -n 1)
#nvidia-xconfig -a --cool-bits=28 --allow-empty-initial-configuration
nvidia-xconfig -a --enable-all-gpus --cool-bits=28 --allow-empty-initial-configuration
cat <<EOT > /etc/X11/Xwrapper.config
allowed_users=anybody
needs_root_rights=yes
EOT
#ssh连接时会有多个xorg进程 使用$DISPLAY 或 -c :0都会提示认证失败的解决方案
ps a |grep X
ps -ef | grep X
who
DISPLAY=:0 XAUTHORITY=/var/run/lightdm/root/:0 nvidia-settings -c :0 -a GPUPowerMizerMode=1 -a '[gpu:0]/GPUGraphicsClockOffset[2]=0'
DISPLAY=:0 XAUTHORITY=$XAUTH nvidia-settings -c :0 -a '[gpu:0]/GPUFanControlState=1' -a '[fan:0]/GPUTargetFanSpeed=60'
DISPLAY=:0 XAUTHORITY=$XAUTH nvidia-settings -c :0 -a '[gpu:0]/GPUGraphicsClockOffset[2]=200'
DISPLAY=:0 XAUTHORITY=$XAUTH nvidia-settings -c :0 -a '[gpu:0]/GPUMemoryTransferRateOffset[4]=2600'
DISPLAY=:0 XAUTHORITY=$XAUTH nvidia-settings -c :0 -a '[gpu:0]/GPUGraphicsClockOffset[2]=200'
for i in `nvidia-smi -L | awk -F: '{print $1}' | awk '{print $2}'`; do
DISPLAY=:0 XAUTHORITY=$XAUTH nvidia-settings -c :0 -a [gpu:$i]/GPUFanControlState=1 -a [fan:$i]/GPUTargetFanSpeed=100
DISPLAY=:0 XAUTHORITY=$XAUTH nvidia-settings -c :0 -a [gpu:$i]/GPUMemoryTransferRateOffset[4]=2000 -a [gpu:$i]/GPUGraphicsClockOffset[4]=-600
echo GPU $i is ready.
done
loginctl show-session $XDG_SESSION_ID
DISPLAY=:0 XAUTHORITY=$XAUTH nvidia-settings -q [gpu:0]/GPUGraphicsClockOffsetAllPerformanceLevels
GPUMemoryTransferRateOffsetAllPerformanceLevels
nvidia-settings -q [gpu:0]/GPUPowerMizerMode
nvidia-settings -a "[gpu:0]/GPUPowerMizerMode=1"
DISPLAY=:0 XAUTHORITY=$XAUTH nvidia-settings -c :0 -a GPUPowerMizerMode=1 -a '[gpu:0]/GPUMemoryTransferRateOffsetAllPerformanceLevels=-2000'
DISPLAY=:0 XAUTHORITY=$XAUTH nvidia-settings -c :0 -a GPUPowerMizerMode=1 -a '[gpu:0]/GPUGraphicsClockOffsetAllPerformanceLevels=-150'
#使用slot判断是哪块显卡,先得到bus编号,再用bus编号查slot,再和主板手册对比
nvidia-smi --query-gpu=index,name,pci.bus_id,pci.bus,pci.device --format=csv
dmidecode -t slot