-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux.Rmd
375 lines (281 loc) · 13.3 KB
/
linux.Rmd
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# linux
## 安装和配置
- TP-P53 安装 ubuntu 18.04
参考[这里](https://blogg.bekk.no/how-to-install-ubuntu-18-04-on-lenovo-p1-617a4bdea389)
1. bios 关闭 `Secure Boot`, startup 选择 Both (UEFI/legacy), 以从 usb 安装系统
2. 安装 `Install Ubuntu`, 按 `e` 配置安装选项,以 `set`开始的行修改:
`gfxpayload=××text××`;
下面一行添加`=casper only-ubiquity ××nomodeset××`,不安装`nouveau`驱动,因为机
器带了nvidia T2000独显,后续要安装对应显卡驱动
3. 安装系统
4. 重启,`ctrl + alt + F1`进入命令行安装驱动,因为我们选择了`nomodeset`安装,
没有显卡驱动进入图形界面会卡死。`sudo ubuntu-drivers autoinstall`,重启即可
检查显卡驱动是否安装成功
```sh
# 看到configuration那里driver=nvidia表示显卡驱动安装成功,如果不采用nomodeset
# 选项安装,默认安装nouveau驱动
sudo lshw -C display
# *-display
# description: VGA compatible controller
# product: NVIDIA Corporation
# vendor: NVIDIA Corporation
# physical id: 0
# bus info: pci@0000:01:00.0
# version: a1
# width: 64 bits
# clock: 33MHz
# capabilities: pm msi pciexpress vga_controller bus_master cap_list rom
# configuration: driver=nvidia latency=0
```
- ubuntu 添加新用户并赋予sudo权限
```sh
# 切换到root账户
su -
# 添加用户
useradd xxx
# 添加至sudo组
usermod -aG sudo xxx
# 或直接修改/etc/sudoers, 使该账户具有root权限,默认不可写
chmod u+w /etc/sudoers
# root ALL=(ALL) ALL 后添加一行,root该成用户名xxx
xxx ALL=(ALL) ALL
```
- ubuntu 修复模式下修改文件
有时候在修改完某个文件后,重启系统会卡在 ubuntu 启动的log界面,比如通过修改
`rc.local`设置开机启动项,这时候就需要在recovery模式下修改引起启动问题的文件:
1. 开机后按`shift`或者`esc`进入grub,选额高级启动项
2. 进入recovery mode
3. 选则进入`Drop To Root Shell Prompt`,就用 root 用户登录了,然后修改文件即可
- Mac/windows 通过网线链接 ubuntu 服务器
网线链接两台电脑后,手动设置相应网卡的 IP 地址,保证在同一个网段。如
Mac IP 设置成192.168.11.1,子网掩码设置为 255.255.255.0,ubuntu
IP设置为192.168.11.2,子网掩码设置为 255.255.255.0。
- ubuntu 20.04 挂载局域网内windows共享的文件夹
1. 在 windows 设置好共享文件夹
2. ubuntu 20.04 安装 cifs-utils `sudo apt install cifs-utils`
3. 挂载 `sudo mount -t cifs -o username=<windows用户名> //<192.xx.xx.xx, windows局域网ip>/<共享的文件夹> </mnt/win, 挂载目录>`
- ubuntu 添加 aliyun 源
根据[这里](https://developer.aliyun.com/mirror/ubuntu)选择相应版本的源,以
16.04 xenial为例
```sh
# 备份原有文件
mv /etc/apt/sources.list /etc/apt/sources.list.backup
# 新建文件,添加源
touch /etc/apt/sources.list
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted # Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe # Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe # Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse # Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe # Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirr.iyun.com/ubuntu/ xenial-security multiverse
```
- ubuntu 18.04 设置开机启动脚本
方法参考[这里](http://www.r9it.com/20180613/ubuntu-18.04-auto-start.html)
ubutu 18.04采用 systemd 进行系统管理,启动的时候 systemd 默认读取
`/etc/systemd/system`下的配置文件,这些配置文件会链接`/lib/systemd/system`下的
文件。
`ls /lib/systemd/system`下可以看到有`rc-local.service`和`rc.local.service`文
件,其中`rc.local.servce`是链接到`rc-local.service`。打开`rc-local.service`
```sh
# SPDX-License-Identifier: LGPL-2.1+
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=on
```
该启动文件少了`INSTALL`字段,在`rc-local.service`后面添加
```sh
[INSTALL]
WantedBy=multi-user.target
Alias=rc-local.service
```
接着新建`/etc/rc.local`文件,在里面添加启动脚本
```sh
!bin/sh -e
# 如添加xx-net的启动脚本
/<path_to_xx-net>/xx_net.sh
```
加上`x`执行权限
```sh
sudo chmod +x /etc/rc.load
```
最后把`rc-local.service`链接到`/etc/systemd/system/`下
```sh
sudo ln -s /lib/systemd/system/rc-local.service /etc/systemd/system/
```
重启`/etc/rc.local`内的脚本就会在开机后自动启动。
- ubuntu workspace 呈 grid 形式显示
ubuntu 默认的 workspace 只能上下显示,安装
[gnome-shell-wsmatrix](https://github.com/mzur/gnome-shell-wsmatrix) 使
workspace 以行列显示。
1. 下载 **gnome-shell-wsmatrix**
2. 解压后拷贝到 `~/.local/share/gnome-shell/extensions/` 下
3. 保证 `metadata.json` 文件的`uuid`字段与加压后的文件夹同名,如
4. `alt + f2` 输入命 `r` 重启 ××gnome shell××即可
- ubuntu 触控板手势设置
安装 [fusuma](https://github.com/iberianpig/fusuma#installation)
1. 添加用户至 `INPUT` 用户组后重启
```sh
sudo gpasswd -a `$USER` input
```
2. 安装
```sh
sudo apt-get install libinput-tools
sudo gem install fusuma
sudo apt-get install xdotool
```
添加至开机自动启动: 打开 **gnome-session-properties** 添加 **fusuma**
(`which fusuma`)的路径, 路径后面加上参数 `-d` 表明后台运行
最后可以在`~/.config/fusuma/config.yml`下自定义配置
- ubuntu 搜狗输入法乱码
搜狗输入法需要切换两次才能正确显示,第一次切换拼音显示为乱码
解决办法参考[这里](https://blog.csdn.net/ZHJ123CSDN/article/details/104884258/)
1. 输入法配置,不要把搜狗输入法放在第一位
2. 依赖性检查`sudo apt-get install -f`
3. 删除配置文件后重启
```sh
cd ~/.config
rm -rf SogouPY* sogou*
fcitx -r
```
- ubuntu 开机后弹窗 检测系统程序出现问题
修改`/etc/default/apport`, `enable=0`
- centos 7 升级内核, 一些软件或者驱动(如网卡驱动)需要高版本内核
参考[这里](https://blog.csdn.net/fenglailea/article/details/88740961)
```sh
# 添加elrepo源,elrepo包含了许多硬件相关的软件包的rpm软件仓库
# 首先倒入public key
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# 参考http://elrepo.org/tiki/tiki-index.php选择对应系统版本的源
rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
# 查看可升级的内核
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
# 安装最新内核
yum --enablerepo=elrepo-kernel install kernel-ml
# 更新内核
grub2-mkconfig -o /boot/grub2/grub.cfg
# 查看系统中的内核
cat /boot/grub2/grub.cfg |grep menuentry
if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
menuentry_id_option=""
export menuentry_id_option
menuentry 'CentOS Linux (5.5.5-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-5.5.5-1.el7.elrepo.x86_64-advanced-a2c5cb57-ab41-44c2-b7f8-e3981fc2582d' {
menuentry 'CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1062.el7.x86_64-advanced-a2c5cb57-ab41-44c2-b7f8-e3981fc2582d'
# 然后根据上一步查看到的内核CentOS Linux (5.5.5-1.el7.elrepo.x86_64) 7 (Core)设置
grub2-set-default "CentOS Linux (5.5.5-1.el7.elrepo.x86_64) 7 (Core)"
# 重启即可看到新更新的内核
reboot
```
- centos 7 安装 Intel `Wi-Fi 6 AX200 160MHz`无线网卡驱动
[官网](https://www.intel.cn/content/www/cn/zh/support/articles/000005511/network-and-i-o/wireless-networking.html
上说该网卡要求内核在5.1以上,在升级完内核后,[下载](https://wireless.wiki.kernel.org/_media/en/users/drivers/iwlwifi/iwlwifi-cc-46.3cfab8da.0.tgz)
驱动,然后按照README中的步骤安装即可
```sh
cp iwlwifi-cc-a0-46.ucode /lib/firmware
```
- ubuntu 20.04 网络设置静态 IP 后,出现错误`Temporary failure in name
resolution`
ping ip 地址和网关都通,ping 域名则无法连接,原因可能是域名无法解析。
直接在`/etc/reslov.conf`添加 DNS 服务器
(如114.114.114.114)会在重启后会恢复为原来内容。在`/etc/systemd/resolved.conf`
添加 DNS 服务器,然后链接到`/etc/reslov.conf`即可(参考[这里](https://blog.csdn.net/booklijian/article/details/116491288)):
```sh
# 备份原有的/etc/reslov.conf,若不可修改,先修改其属性
# chattr -i /etc/reslov.conf
mv /etc/reslov.conf /etc/reslov.conf.bak
# 修改 /etc/systemd/resolved.conf 设置 DNS
vim /etc/systemd/resolved.conf # DNS = 114.114.114.114 8.8.8.8
# 链接
ln -s /run/systemd/resolve/resolv.conf /etc/reslov.conf
```
## 系统管理
### 1. 磁盘 {-}
- 取消磁盘挂载
```sh
# sudo umount </media/share>, 出现target is busy, 需要首先杀死使用
# 挂载目录的进程
fuser -km </media/share>
sudo umount </media/share>
```
- 永久挂载磁盘
```sh
# 查看磁盘信息
blkid </dev/sdx>
# UUID="7c6c4126-26ec-4071-966a-0cdb5c8a8f96" TYPE="ext4" ...
# 修改fstab文件(文件系统挂载),根据blkid显示的磁盘信息添加一行
# UUID和文件系统类型
UUID=7c6c4126-26ec-4071-966a-0cdb5c8a8f96 <挂载目录> ext4 defaults 0 0
## 挂载
sudo mount -a
```
## VIM
### 快捷键
#### Formatting 格式化排版
根据 `line-width` 格式化(重排)行
```
gq: (可视模式下)格式化选定内容,行宽度为 line-width 设置变量(80)
gqq: 根据 line-width 格式化当前行
ngqq: 格式化 n 行
```
### 插件
##### 安装插件 {-}
1. 安装插件管理器[vim-plug](https://github.com/junegunn/vim-plug),
[plug-vim](https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim)
保存为`~/.vim/autoload/plug.vim`:
```
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
```
2. `~/.vimrc`中添加
```
" 括号内为插件安装路径,默认为~/.vim/plugged
" 之前用的pathogen安装插件保存在~/.vim/bundle,所以修改了默认路径
call plug#begin('~/.vim/bundle')
" Make sure you use single quotes
" 要安装的插件
" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'
call plug#end()
```
**默认执行`filetype plugin indent on` 和 `syntax enable`**
3. 退出vim,重新打开后 `:PlugInstall` 即可安装
##### 安装 python autocompletion 插件 jedi-vim 后出现错误 {-}
因为安装系统的 vim 是基于自带的 python(3.5) 配置的, jedi-vim 默认使用系统自带的
python3.5 (`:python3 import sys; print(sys.version_info)`), 而我们需要使用更高版本的 python (3.9), 出现版本不匹配而引起错误
`File "/home/user/.vim/plugged/jedi-vim/pythonx/parso/parso/parser.py", line
113 node_map: Dict[str, type] = {} ^ SyntaxError: invalid syntax`.
**解决办法**: 用 conda 用相应版本 python 重新安装配置新的 vim `conda install -c conda-forge vim`. 参考
[这里](https://gitmemory.cn/repo/davidhalter/jedi-vim/issues/1062). 如果使用
自带的 vim 和 python, 则直接把 `python3` 链接到系统版本应该也可以.
## Misc
- `screen` 命令鼠标屏幕
1. `ctrl + A`,接着按 `ESC`,进入拷贝模式 ("Copy mode"),再次按 `ESC` 退出.
2. 鼠标滚轮: `echo 'termcapinfo xterm* ti@:te@' >> ~/.screenrc`.