命令别名
编辑文件
添加
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias dps='docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Ports}}\t{{.Status}}\t{{.Names}}"'
alias dis='docker images'
# w
alias wns='watch -n 1 nvidia-smi'
alias wnss='watch -n 1 "nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv"'
alias ns='nvidia-smi'
alias pi='pip install'
alias pii='pip install -i https://pypi.tuna.tsinghua.edu.cn/simple'
szdl() {
if [ -z "$1" ]; then
echo "Usage: szdl <local_ip> [port]"
return 1
fi
local_ip=$1
port=${2:-7890}
http_proxy=http://${local_ip}:${port}
https_proxy=http://${local_ip}:${port}
ftp_proxy=ftp://${local_ip}:${port}
socks_proxy=${local_ip}:${port}
export http_proxy https_proxy ftp_proxy socks_proxy
echo "Proxy settings updated: ${local_ip}:${port}"
}
ckdl(){
printenv | grep -i proxy
}
qxdl(){
unset http_proxy https_proxy ftp_proxy socks_proxy
}
|
应用
CentOS7安装NVIDIA驱动、CUDA
安装基础依赖环境
1
|
yum install kernel-devel
|
屏蔽默认带有的nouveau
1
|
nano /lib/modprobe.d/dist-blacklist.conf
|
# blacklist nvidiafb
blacklist nouveau options nouveau modeset=0
重建initramfs image
1
2
|
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
dracut /boot/initramfs-$(uname -r).img $(uname -r)
|
修改运行级别为文本模式,并重启
1
2
|
systemctl set-default multi-user.target
reboot
|
查看nouveau是否已经禁用
安装文件
下载 NVIDIA 官方驱动 | NVIDIA
CUDA Toolkit Archive | NVIDIA Developer
nvidia-smi
1
|
nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv
|

1
2
3
4
5
6
|
wnss
Every 1.0s: nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv H3C: Thu Jun 20 21:37:12 2024
pid, process_name, used_gpu_memory [MiB]
42551, /data1/miniconda3/envs/chatchat/bin/python, 12352 MiB
43966, /data1/miniconda3/envs/chatchat/bin/python, 1780 MiB
|
通过命令别名快速设置代理
设置别名
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
szdl() {
if [ -z "$1" ]; then
echo "Usage: szdl <local_ip> [port]"
return 1
fi
local_ip=$1
port=${2:-7890}
http_proxy=http://${local_ip}:${port}
https_proxy=http://${local_ip}:${port}
ftp_proxy=ftp://${local_ip}:${port}
socks_proxy=${local_ip}:${port}
export http_proxy https_proxy ftp_proxy socks_proxy
echo "Proxy settings updated: ${local_ip}:${port}"
}
ckdl(){
printenv | grep -i proxy
}
qxdl(){
unset http_proxy https_proxy ftp_proxy socks_proxy
}
|
使用
端口默认7890
阿里云扩容
查看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
fdisk -lu
Disk /dev/vda: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: DF3D4089-1021-4F37-ACCD-4B14CC944064
Device Start End Sectors Size Type
/dev/vda1 2048 411647 409600 200M EFI System
/dev/vda2 411648 209715166 209303519 99.8G Linux filesystem
Disk /dev/vdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 9C933549-F519-4795-862E-C546772988CB
Device Start End Sectors Size Type
/dev/vdb1 2048 209715166 209713119 100G Linux filesystem
Disk /dev/vdc: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: F5230BBC-5100-4E7C-B9F7-397C853BD268
Device Start End Sectors Size Type
/dev/vdc1 2048 209715166 209713119 100G Linux filesystem
|
创建分区
gdisk 硬盘名称
创建新的 GPT 分区表: 在 gdisk
提示符下,输入 g
然后按回车,选择 Create a new GUID partition table (GPT)
创建新的 GPT 分区表。
创建新的分区:
- 输入
n
然后按回车,选择 Add a new partition
。
- 按回车接受默认值或输入分区号。
- 同样按回车接受默认起始 LBA。
- 输入分区大小或接受默认值(这将使用所有剩余空间)。
- 选择分区类型,输入
8300
选择 Linux filesystem
类型。
- 按回车完成分区创建。
保存更改并退出:
- 输入
w
然后按回车,选择 Write table to disk and exit
。
- 输入
y
确认写入操作。
格式化新分区: 创建分区后,需要格式化它以使用 ext4
文件系统:
创建挂载点并挂载: 创建一个目录作为挂载点,然后挂载新分区:
设置开机自动挂载
编辑 /etc/fstab
文件
使用 blkid
获取分区的 UUID
1
|
UUID=$ blkid /dev/vdb1 | cut -d '"' -f 2
|
将以下行添加到 /etc/fstab
文件中:
1
|
UUID=$UUID /mnt/newdisk ext4 defaults 0 2
|
使用文本编辑器编辑 /etc/fstab
文件,例如使用 nano
:
添加上述行后,保存并退出编辑器。

测试 /etc/fstab
配置: 在修改 /etc/fstab
后,可以使用以下命令测试配置是否正确:
如果没有错误消息,那么配置就是正确的。
硬盘镜像重装系统
放入镜像文件

编辑grub启动项
1
|
nano /etc/grub.d/40_custom
|
添加或更新以下内容:
1
2
3
4
5
6
|
menuentry "Ubuntu 22.04.4 ISO" {
set isofile="/ubuntu-22.04.4-desktop-amd64.iso"
loopback loop (hd1,msdos1)$isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=${isofile} quiet splash
initrd (loop)/casper/initrd
}
|
- Ubuntu 22.04.4 ISO:启动项的名称
- (hd1,msdos1):镜像在哪个硬盘的哪个分区上,hd从0开始
如果不知道在哪个分区,在grub启动界面输入命令ls
grub> ls
grub> ls (hd0,msdos1)/
逐个找一下
确保分区挂载
/dev/sda1 /data1 ext4 defaults 0 0
mount /data1
更新grub配置
centos:
1
|
grub2-mkconfig -o /boot/grub2/grub.cfg
|
ubuntu:
重启
允许root远程登录
安装ssh
1
2
3
4
5
|
apt install openssh-server
service ssh start
ps -aux | grep ssh
|
修改配置
1
2
3
4
5
6
7
|
nano /etc/ssh/sshd_config
# PermitRootLogin prohibit-password
# 更改为:
# PermitRootLogin yes
systemctl restart sshd
|