kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

ubuntu 编译内核、模块

https://launchpad.net/ubuntu/+source/linux/+changelog

4.15.0

https://launchpad.net/ubuntu/bionic/+source/linux/+changelog

https://packages.ubuntu.com/xenial/linux-source-4.15.0
http://security.ubuntu.com/ubuntu/pool/main/l/linux-hwe/linux-source-4.15.0_4.15.0-58.64~16.04.1_all.deb

https://launchpad.net/ubuntu/xenial/amd64/linux-image-unsigned-4.15.0-58-generic-dbgsym
http://launchpadlibrarian.net/436393485/linux-image-unsigned-4.15.0-58-generic-dbgsym_4.15.0-58.64~16.04.1_amd64.ddeb

https://launchpad.net/ubuntu/bionic/amd64/linux-image-unsigned-4.15.0-58-generic-dbgsym
http://launchpadlibrarian.net/436226708/linux-image-unsigned-4.15.0-58-generic-dbgsym_4.15.0-58.64_amd64.ddeb

4.18.0

https://launchpad.net/ubuntu/xenial/+source/linux/+changelog

https://packages.ubuntu.com/bionic/linux-source-4.18.0
http://security.ubuntu.com/ubuntu/pool/main/l/linux-hwe/linux-source-4.18.0_4.18.0-25.26~18.04.1_all.deb

https://launchpad.net/ubuntu/bionic/amd64/linux-image-4.18.0-25-generic-dbgsym
http://launchpadlibrarian.net/430863032/linux-image-4.18.0-25-generic-dbgsym_4.18.0-25.26~18.04.1_amd64.ddeb

gcc 7 编译内核模块时无法找到 stdarg.h 的问题

https://blog.gloriousdays.pw/2018/09/09/cannot-find-stdarg-h-on-linux-kernel-4-15-with-gcc-7-3/

这是一个非常奇怪的错误,出现在 Ubuntu 18.04 上,默认安装的内核版本是 4.15,gcc 是 7.3,在编译内核模块时报错:

1
2
3
4
5
6
7
In file included from ./include/linux/list.h:9:0,
                 from ./include/linux/module.h:9,
                 from /root/Software/newbbr/tcp_tsunami.c:59:
./include/linux/kernel.h:6:10: fatal error: stdarg.h: No such file or directory
 #include <stdarg.h>
          ^~~~~~~~~~
compilation terminated.

gcc 认为找不到 stdarg.h。看这个错误的位置,个人认为应该不是我配置的问题或者是我代码的问题,搜索了一下,也有很多在 4.15 内核上出现的同样错误。目前没有什么很好的解决方案,暂时性的方案是在编译的 Makefile 里面加一行:

1
ccflags-y=-I/usr/lib/gcc/x86_64-linux-gnu/7/include

如果是 gcc 8,就相应把版本改成 8 就可以了

编译内核

1
2
3
sudo apt-get install libncurses-dev flex bison openssl-dev libssl-dev dkms libelf-dev

make bindeb-pkg -j8

按这里没成功 https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel

编译perf

1
2
cd tools/perf
make

CPU温控

常规调节

1
2
echo 72 > /sys/devices/system/cpu/intel_pstate/max_perf_pct
echo 1  > /sys/devices/system/cpu/intel_pstate/no_turbo

参数解释

https://www.kernel.org/doc/Documentation/cpu-freq/intel-pstate.txt

/sys/devices/system/cpu/intel_pstate/

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
      max_perf_pct: Limits the maximum P-State that will be requested by
      the driver. It states it as a percentage of the available performance. The
      available (P-State) performance may be reduced by the no_turbo
      setting described below.

      min_perf_pct: Limits the minimum P-State that will be requested by
      the driver. It states it as a percentage of the max (non-turbo)
      performance level.

      no_turbo: Limits the driver to selecting P-State below the turbo
      frequency range.

      turbo_pct: Displays the percentage of the total performance that
      is supported by hardware that is in the turbo range. This number
      is independent of whether turbo has been disabled or not.

      num_pstates: Displays the number of P-States that are supported
      by hardware. This number is independent of whether turbo has
      been disabled or not.

For example, if a system has these parameters:
	Max 1 core turbo ratio: 0x21 (Max 1 core ratio is the maximum P-State)
	Max non turbo ratio: 0x17
	Minimum ratio : 0x08 (Here the ratio is called max efficiency ratio)

Sysfs will show :
	max_perf_pct:100, which corresponds to 1 core ratio
	min_perf_pct:24, max_efficiency_ratio / max 1 Core ratio
	no_turbo:0, turbo is not disabled
	num_pstates:26 = (max 1 Core ratio - Max Efficiency Ratio + 1)
	turbo_pct:39 = (max 1 core ratio - max non turbo ratio) / num_pstates

Refer to "Intel庐 64 and IA-32 Architectures Software Developer鈥檚 Manual
Volume 3: System Programming Guide" to understand ratios.

There is one more sysfs attribute in /sys/devices/system/cpu/intel_pstate/
that can be used for controlling the operation mode of the driver:

      status: Three settings are possible:
      "off"     - The driver is not in use at this time.
      "active"  - The driver works as a P-state governor (default).
      "passive" - The driver works as a regular cpufreq one and collaborates
                  with the generic cpufreq governors (it sets P-states as
                  requested by those governors).
      The current setting is returned by reads from this attribute.  Writing one
      of the above strings to it changes the operation mode as indicated by that
      string, if possible.  If HW-managed P-states (HWP) are enabled, it is not
      possible to change the driver's operation mode and attempts to write to
      this attribute will fail.

https://huataihuang.gitbooks.io/cloud-atlas/os/linux/kernel/cpu/intel_pstate.html

http://www.litrin.net/2018/12/28/cpu%E7%9A%84%E7%94%B5%E6%BA%90%E7%8A%B6%E6%80%81%E5%88%86%E7%B1%BB/

ubuntu 16.04 & 18.04

删除snap,snap会自动更新,严重占带宽

1
2
3
4
5
6
7
8
snap list
sudo snap remove gtk-common-themes
...
sudo apt-get remove snapd

df -h | grep snap
sudo systemctl stop snap-core-6350.mount
sudo systemctl disable snap-core-6350.mount

ssh 保持连接

服务端

1
2
ClientAliveInterval 60
ClientAliveCountMax 1

SSH Server 每 60 秒就会自动发送一个信号给 Client,客户端没有回应数超过 ClientAliveCountMax 时,才会断开连接。

客户端

1
2
TCPKeepAlive yes
ServerAliveInterval 300

前一个参数是说要保持连接,后一个参数表示每过5分钟发一个数据包到服务器

命令行进行设定即:

1
ssh -o TCPKeepAlive=yes -o ServerAliveInterval=300 root@1.2.3.4

dns 命令

1
2
3
4
5
6
7
8
9
sudo apt-get install pppconfig
/etc/init.d/dns-clean

systemctl stop systemd-resolved
systemctl start systemd-resolved

systemd-resolve --statistics
systemd-resolve --status
systemd-resolve --flush-caches

代理设置

1
2
3
4
5
6
7
8
9
10
11
12
13
# cat /etc/apt/apt.conf
Acquire::https::Proxy "http://proxy.proxy.com:8080";
# err? http_proxy=http://proxy.proxy.com:8080
# err? https_proxy=http://proxy.proxy.com:8080

# cat /etc/environment
http_proxy=http://proxy.proxy.com:8080
https_proxy=http://proxy.proxy.com:8080
no_proxy=localhost,127.0.0.0/8,::1,*.pp.com,*.oa.com

# cat /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://proxy.proxy.com:8080"

amdgpu.dc

VGA,DIV-D接口 4.15.0 以后内核黑屏,需要设置amdgpu.dc=0 HDMI,DP接口支持音频,需要设置amdgpu.dc=1

注释掉下面这行将会显示引导菜单

1
#GRUB_HIDDEN_TIMEOUT=0

设定默认启动项 /etc/default/grub

1
2
3
4
5
6
7
8
9
# 用数字
GRUB_DEFAULT=0

# 最近启动
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true

# 指定内核
GRUB_DEFAULT="gnulinux-advanced-999d2fc9-3d7b-4654-a25c-4f5d4472a23b>gnulinux-4.15.0-55-generic-advanced-999d2fc9-3d7b-4654-a25c-4f5d4472a23b"

Warning: Please don’t use old title Ubuntu, with Linux 4.15.0-55-generic' for GRUB_DEFAULT, useAdvanced options for Ubuntu>Ubuntu, with Linux 4.15.0-55-generic' (for versions before 2.00) or `gnulinux-advanced-999d2fc9-3d7b-4654-a25c-4f5d4472a23b>gnulinux-4.15.0-55-generic-advanced-999d2fc9-3d7b-4654-a25c-4f5d4472a23b' (for 2.00 or later)

卸载amazon

1
2
3
4
5
# 16.04
sudo apt-get remove unity-webapps-common

# 18.04
sudo apt-get remove ubuntu-web-launchers

新立得

1
sudo apt-get install synaptic

禁用apport

1
2
/etc/default/apport
enabled=0

禁用service

1
2
3
4
5
6
7
8
9
# 禁用
sudo systemctl disable apport.service

# 如果这不起作用,那么您需要屏蔽该服务
systemctl mask apport.service

# 重新启用
systemctl unmask apport.service # if you masked it
sudo systemctl enable apport.service

中文输入法

1
2
3
sudo apt-get install ibus-pinyin
# 选择全拼模式,同时勾选“简拼”, 然后运行
sudo ibus restart

温度

1
2
3
4
sudo apt-get install lm-sensors hddtemp
sudo sensors-detect
sensors
sudo apt-get install psensor

查看SSD状态

https://www.cnblogs.com/fiberhome/p/8275961.html

1
2
3
4
5
6
7
8
hdparm -t --direct /dev/sda

smartctl -i /dev/sda

sudo smartctl -data -A /dev/sda
sudo smartctl -A /dev/sda

# 233一行的值就是寿命,默认为100,当小于10的时候就要非常注意了。

个人桌面系统可以加 noatime

1
2
3
4
vim /etc/fstab
增加 noatime

stat /etc/fstab

nvme硬盘温度

1
2
3
4
5
6
7
sudo apt-get install nvme-cli
sudo nvme list

sudo nvme smart-log /dev/nvme0
sudo watch -n 1 nvme smart-log /dev/nvme0

sudo nvme smart-log /dev/nvme0 | grep "^temperature"

SSD

1
2
3
4
5
Aggressive LPM Support功能是SATA口的节能电源管理,开启会导致SSD掉盘,不认盘,掉速等问题。

解决方法:

到BIOS中找到Aggressive LPM Support并关闭。

18.04 unity

1
2
3
4
5
6
sudo apt install ubuntu-unity-desktop
select lightdm

# 恢复gnome
sudo apt purge ubuntu-unity-desktop
sudo dpkg-reconfigure gdm3

18.04 用synergy1.6.2

https://packages.ubuntu.com/xenial/libcrypto++9v5

https://packages.ubuntu.com/xenial/synergy

synergy_1.6.2-0ubuntu2_amd64.deb

libcrypto++9v5_5.6.1-9ubuntu0.1_amd64.deb