一、安装WSL2下的Ubuntu20.04
1)打开windows WSL服务
# 以管理员身份运行 PowerShell dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# 使用powershell将wsl2设置为默认版本 wsl --set-default-version 2
2)安装linux子系统
# 安装操作系统 wsl --install -d <可安装的版本名> 例如,我安装版本名为Ubuntu-18.04,命令为:wsl --install -d Ubuntu-20.04 wsl --install -d Ubuntu-20.04
# 查看可以安装的linux版本 wsl -l -o
3)给Ubuntu换源
# 备份源列表 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak # 命令行打开sources.list文件 sudo vim /etc/apt/sources.list
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse multiverse
sudo apt-get update
二、迁移子系统到其他磁盘
wsl --shutdown Ubuntu-20.04 wsl --export Ubuntu-20.04 D:\WSL2\WSL2Ubuntu20.04.bak wsl --unregister Ubuntu-20.04 wsl --import Ubuntu-20.04 D:\WSL2Ubuntu20.04LTS D:\WSL2\WSL2Ubuntu20.04.bak --version 2
三、修改为静态IP地址
在 /etc/netplan 下创建 01-network-manager-all.yaml 文件,包含以下内容:
# Let NetworkManager manage all devices on this system network: version: 2 renderer: NetworkManager ethernets: eth0: #网卡名 dhcp4: no #关闭ipv4动态分配ip地址 dhcp6: no #关闭ipv6动态分配ip地址 addresses: [172.19.222.100/24] #前面是ip地址,子网掩码是255.255.240.0 gateway4: 172.19.208.1 #网关 nameservers: addresses: [114.114.114.114, 8.8.8.8] #DNS
四、在WSL下启用 systemctl 命令
参考:https://www.cnblogs.com/leokale-zz/p/17579564.html
五、安装 openssh
sudo apt-get install openssh-server -y
修改 /etc/ssh/sshd_config 配置内容
port 22 AllowUsers root leo PermitRootLogin yes PasswordAuthentication yes
启动服务:
sudo service ssh restart #或 sudo systemctl start ssh # 开机启动 sudo systemctl enable ssh
六、安装anaconda
下载:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
版本:Anaconda3-2023.07-1-Linux-x86_64.sh (Python3.11)
bash Anaconda3-2023.07-1-Linux-x86_64.sh
七、安装 cuda toolkit
CUDA toolkit版本12.1
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600 wget https://developer.download.nvidia.com/compute/cuda/12.1.0/local_installers/cuda-repo-wsl-ubuntu-12-1-local_12.1.0-1_amd64.deb sudo dpkg -i cuda-repo-wsl-ubuntu-12-1-local_12.1.0-1_amd64.deb sudo cp /var/cuda-repo-wsl-ubuntu-12-1-local/cuda-*-keyring.gpg /usr/share/keyrings/ sudo apt-get update sudo apt-get -y install cuda
配置cuda环境变量
export CUDA_HOME=/usr/local/cuda-12.1 export PATH=/usr/local/cuda-12.1/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda-12.1/lib64:$LD_LIBRARY_PATH
八、安装cudnn
cudnn版本8.9.3.28
下载:cudnn-local-repo-ubuntu2004-8.9.3.28_1.0-1_amd64.deb
sudo dpkg -i cudnn-local-repo-ubuntu2004-8.9.3.28_1.0-1_amd64.deb sudo cp /var/cudnn-local-repo-ubuntu2004-8.9.3.28/cudnn-local-AAD7FE56-keyring.gpg /usr/share/keyrings/ apt-get update sudo apt-get install libcudnn8=8.9.3.28-1+cuda12.1 sudo apt-get install libcudnn8-dev=8.9.3.28-1+cuda12.1 sudo apt-get install libcudnn8-samples=8.9.3.28-1+cuda12.1
验证是否成功:
sudo apt-get install libfreeimage3 libfreeimage-dev -y cp -r /usr/src/cudnn_samples_v8/ $HOME cd $HOME/cudnn_samples_v8/mnistCUDNN make clean && make ./mnistCUDNN
#Test Passed!
九、编译安装ffmpeg
1)安装pkg-config
sudo apt-get install pkg-config
2)安装nv-codec-headers
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git cd nv-codec-headers sudo make install # 验证是否安装成功 pkg-config --modversion ffnvcodec
3)源码安装libx264(可选apt安装)
git clone https://code.videolan.org/videolan/x264.git cd x264 ./configure --disable-asm --enable-shared --enable-pic # 编译 & 安装 make -j32 sudo make install
4)安装依赖库
sudo apt-get install -y aptitude sudo aptitude install -y build-essential sudo aptitude install -y yasm nasm sudo apt-get install -y libssl-dev librtmp-dev libvorbis-dev sudo apt-get install -y libgmp3-dev libaom-dev libtheora-dev sudo apt-get install -y libass-dev libbluray-dev libfdk-aac-dev sudo apt-get install -y libmp3lame-dev libopencore-amrnb-dev sudo apt-get install -y libopenmpt-dev libopus-dev libxvidcore-dev liblzma-dev sudo apt-get install -y libshine-dev libsnappy-dev libsoxr-dev sudo apt-get install -y libspeex-dev libtheora-dev libtwolame-dev sudo apt-get install -y libvo-amrwbenc-dev libvpx-dev libwavpack-dev sudo apt-get install -y libwebp-dev libx264-dev libx265-dev
5)下载ffmpeg源码
wget https://ffmpeg.org/releases/ffmpeg-4.4.tar.gz tar zxvf ffmpeg-4.4.tar.gz
6)编译安装
./configure --prefix="/usr/local/ffmpeg" \ --enable-static --enable-shared \ --enable-version3 --enable-gpl \ --enable-nonfree --enable-small --enable-libmp3lame \ --enable-libx264 --enable-libx265 \ --enable-libvpx --enable-libtheora --enable-libvorbis \ --enable-libopus --enable-libfdk-aac --enable-libass --enable-libwebp \ --enable-librtmp --enable-postproc --enable-libfreetype --enable-pthreads \ --enable-openssl --enable-shared --disable-debug --disable-doc --disable-ffplay \ --enable-cuvid --enable-cuda --enable-cuda-nvcc \ --extra-cflags="-I/usr/local/cuda-12.1/include" --extra-ldflags="-L/usr/local/cuda-12.1/lib64" \ --extra-cflags="-I/usr/local/include" --extra-ldflags="-L/usr/local/lib" --extra-libs="-lpthread -lm"
sudo make -j16 sudo make install
问题:
ERROR: failed checking for nvcc. #将configure文件中的sm_30为sm_90(cuda12对应90)
= =
标签:Ubuntu20.04,enable,--,sudo,dev,apt,install,Linux,WSL2 From: https://www.cnblogs.com/leokale-zz/p/17579603.html