跳转至

Linux常用系统定制

SCP 文件传输

1. 使用方法

usage: scp [-346ABCOpqRrsTv] [-c cipher] [-D sftp_server_path] [-F ssh_config]
           [-i identity_file] [-J destination] [-l limit]
           [-o ssh_option] [-P port] [-S program] source ... target

2. 快速使用

Note

$local_path:本地文件路径
$username:用户名
$ip:主板ip
$target_path:目标路径

$ scp $local_path usrname@$ip:$target_path

操作示例:

$ scp .\1.wav linaro@192.168.77.165:/home/linaro/Desktop/

屏幕显示方向配置

Debian11

  • 获取使用帮助
xrandr -help
  • 查看屏幕信息
(console)/# xrandr
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
HDMI-1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1920x1080     60.00*+  60.00    50.00    50.00    59.94
   1920x1080i    60.00    50.00    50.00    59.94
   1680x1050     59.88
   1280x1024     75.02    60.02
   1440x900      59.90
   1280x960      60.00
   1360x768      60.02
   1152x864      75.00
   1280x720      60.00    50.00    50.00    59.94
   1024x768      75.03    70.07    60.00
   832x624       74.55
   800x600       72.19    75.00    60.32    56.25
   720x576       50.00    50.00    50.00
   720x480       60.00    60.00    59.94    59.94
   640x480       75.00    72.81    66.67    60.00    59.94    59.94
   720x400       70.08
DSI-1 connected (normal left inverted right x axis y axis)
   800x1280      60.51 +
DP-1 disconnected (normal left inverted right x axis y axis)
  • 旋转屏幕显示方向

操作示例: 根据xrandr,已知目前已连接显示设备 HDMI-1,对 HDMI-1 进行旋转设置

画面正常显示

(console)$ xrandr --output HDMI-1 --rotate normal   

向右旋转,顺时针旋转90度

(console)$ xrandr --output HDMI-1 --rotate right    

向左旋转,顺时针旋转270度

(console)$ xrandr --output HDMI-1 --rotate left     

反转,顺时针旋转180度

(console)$ xrandr --output HDMI-1 --rotate inverted         
  • 触摸校准

1. 安装工具

$ apt update
$ apt install xinput
$ apt install xinput-calibrator

2. 查看 Device 和 ID,可知 goodix-ts 设备id 为 10

$ xinput_calibrator --list 
Device "goodix-ts" id=10

3. 重置转置矩阵和校准矩阵,这是关键操作,转置矩阵需要根据屏幕旋转,校准矩阵设置默认值即可

$ xinput set-prop $id --type=float "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1
// xinput set-prop 10 --type=float "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1

$ xinput set-prop $id --type=float "libinput Calibration Matrix" 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0
// xinput set-prop 10 --type=float "libinput Calibration Matrix" 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0

修改触摸方向(可根据名字修改) 默认方向

$ xinput set-prop $id 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
// xinput set-prop 10 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1

修改触摸方向(可根据名字修改) 向左90度

$ xinput set-prop $id 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1
// xinput set-prop 10 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1

修改触摸方向(可根据名字修改) 向右90度

$ xinput set-prop $id 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1
// xinput set-prop 10 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1

修改触摸方向(可根据名字修改) 旋转180度

$ xinput set-prop $id 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
// xinput set-prop 10 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1

4. 开始校准

$ xinput_calibrator -v --device $id
// xinput_calibrator -v --device 10

语言配置

Debian11

修改系统语言,请打开命令行终端,执行以下命令。重新启动使修改生效

  • 设置英文
$ /usr/sbin/locale-gen en_US.UTF-8
$ sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen
$ echo "LANG=en_US.UTF-8" > /etc/default/locale
$ echo "export LC_ALL=en_US.UTF-8" > /etc/profile.d/zh_CN.sh
$ echo "export LANG=en_US.UTF-8" >> /etc/profile.d/zh_CN.sh
$ echo "export LANGUAGE=en_US:en" >> /etc/profile.d/zh_CN.sh
$ reboot
  • 设置中文
$ /usr/sbin/locale-gen zh_CN.UTF-8
$ sed -i 's/^# *\(zh_CN.UTF-8\)/\1/' /etc/locale.gen
$ echo "LANG=zh_CN.UTF-8" > /etc/default/locale
$ echo "export LC_ALL=zh_CN.UTF-8" > /etc/profile.d/zh_CN.sh
$ echo "export LANG=zh_CN.UTF-8" >> /etc/profile.d/zh_CN.sh
$ echo "export LANGUAGE=zh_CN:zh" >> /etc/profile.d/zh_CN.sh
$ reboot

Note

若出现中文显示乱码问题,可执行以下命令安装中文字体包,完成后重启设备即可恢复
apt install -y fonts-wqy-microhei fonts-wqy-zenhei

时区配置

Tip

命令执行完成后,需重启才能生

  • 设置时区亚洲/上海
$ ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime     
  • 设置时区美国/纽约
$ ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

网络配置

  • 临时配置:使用 ifconfigroute 命令(临时设置),这种方法在系统重启后会失效,但可以快速测试固定 IP 的配置。

1. 使用 ifconfig 命令设置 IP 地址、子网掩码和广播地址:

sudo ifconfig eth0 <IP> netmask <netmask_num> broadcast <broadcast ip>

操作示例:

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255

Note

命令解析:
sudo:以管理员权限运行命令。
ifconfig:用于配置网络接口。
eth0:网络接口名称,通过 ifconfig -a 网络接口名称,可能是 eth0ens33 或其他名称。
<IP 地址>:你想要设置的固定 IP 地址。
<子网掩码>:通常是 255.255.255.0 或其他子网掩码。
<广播地址>:根据 IP 地址和子网掩码计算得出,对于 192.168.1.100255.255.255.0 的子网掩码,广播地址是 192.168.1.255

2. 使用 route 命令设置网关:

sudo route add default gw <gw addr> eth0

Note

route:用于配置路由。
add default gw <网关地址>:添加默认网关。
<网关地址>:你的网络网关地址。

操作示例:

sudo route add default gw 192.168.1.1 eth0
  • 长期配置:使用 /etc/network/interfaces 文件(长期设置)可以实现长期稳定的固定 IP 配置。

1. 编辑 /etc/network/interfaces 文件

sudo vi /etc/network/interfaces

2. 添加或修改网络接口配置:

auto eth0
iface eth0 inet static
   address 192.168.1.100
   netmask 255.255.255.0
   gateway 192.168.1.1
   # 如果需要设置 DNS 服务器,可以添加以下行
   dns-nameservers 8.8.8.8 8.8.4.4

Note

auto eth0:表示在系统启动时自动启用 eth0 接口。
iface eth0 inet static:表示 eth0 接口使用静态 IP 配置。
address:设置 IP 地址。
netmask:设置子网掩码。
gateway:设置网关。
dns-nameservers:设置 DNS 服务器,这里使用了 Google 的 DNS 服务器,你可以使用其他 DNS 服务器,如 114.114.114.114 等。

3. 保存并退出编辑器,在 vi 中,点击键盘 ESC 键,输入:wq ,ENTER键保存并退出。

4. 重启网络服务或系统

sudo service networking restart

或直接重启系统

sudo reboot

WIFI热点

Debian11

  • 图像化界面配置

1.确保主板已经连接以太网,进入Debian 11 图形化界面,右键单击网络图标打开图像化网络配置界面。

NFS配置

Debian11

  • 环境配置

1. 创建缺失的 /run/rpcbind目录

$ sudo mkdir -p /run/rpcbind

2. 强制创建 _rpc 系统用户(解决目录+用户名规则问题)

$ sudo id -u _rpc >/dev/null 2>&1 || sudo adduser --force-badname --system --home /run/rpcbind --no-create-home _rpc

3. 验证 _rpc 用户创建成功

$ id _rpc

创建成功则会输出如下类似内容:

root@localhost:/home/kickpi# id _rpc
uid=111(_rpc) gid=65534(nogroup) groups=65534(nogroup)

4. 安装 NFS 内核级服务端软件包

$ sudo apt install nfs-kernel-server
  • 服务器端

1. 配置共享文件

$ mkdir /home/kickpi/nfs_share
$ chmod 777 /home/kickpi/nfs_share
$ vi /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
#               to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
# 
/home/kickpi/nfs_share *(rw,sync,no_subtree_check,insecure)

2. 启动服务

$ sudo service nfs-kernel-server restart

3. 查看当前服务器共享文件,证明共享成果

$  showmount -e localhost
Export list for localhost:
/home/kickpi/nfs_share *
  • 客户端

1. 查看服务器共享文件

showmount -e 192.168.19.173
Export list for 192.168.19.173:
/home/kickpi/nfs_share *

2. 挂载文件夹

$ mkdir nfs_tmp
$ sudo mount -t nfs 192.168.19.173:/home/kickpi/nfs_share nfs_tmp/

3. 挂载成功

$ ls nfs_tmp/
1.txt

4G/5G配置

脚本配置

4G/5G移动模块开机配置,检测模块是否存在,进行配置拨号:

Tip

开机默认仅会拨号一次,在信号不好或通讯异常情况下,可能会存在拨号失败的情况,若无网络,可运行拨号脚本进行重试。

(console)$ cat /usr/bin/hardware-optimization 
4g_config() {
    wait_time=30
        for((i=1;i<=$wait_time;i++));
        do 
                if [ -c /dev/ttyUSB2 ]; then
                        echo "$i: 4g /dev/ttyUSB2 exists and is a character device." >> $LOG_FILE
                        /usr/bin/4G_dialing.sh
            break;
                else
                        echo "$i: 4g /dev/ttyUSB2 does not exist or is not a character device." >> $LOG_FILE
                        sleep 1
                fi
        done
}

拨号脚本,已适配 RG200U / EC200 / EC20

(console)$ ls /usr/bin/4G_monitor.sh

网络测试

1. 查看日志判断是否接入模块

Tip

/dev/ttyUSB2 exists and is a character device.代表设备识别成功

$ cat /tmp/kickpi-hardware.log 
1: 4g /dev/ttyUSB2 does not exist or is not a character device.
2: 4g /dev/ttyUSB2 does not exist or is not a character device.
...
24: 4g /dev/ttyUSB2 does not exist or is not a character device.
25: 4g /dev/ttyUSB2 exists and is a character device.

或查看 /dev/ttyUSB2 是否存在

$ ls /dev/ttyUSB*
/dev/ttyUSB0  /dev/ttyUSB1  /dev/ttyUSB2  /dev/ttyUSB3  /dev/ttyUSB4

2. 判断是否拨号成功

Tip

设备名称格式为 wwan** 为可变后缀),具体名称请参照实际环境。

(console)$ ifconfig
wwan0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1500
        inet 10.19.100.160  netmask 255.255.255.192  destination 10.19.100.160
        inet6 fe80::5445:bdd7:623b:3db3  prefixlen 64  scopeid 0x20<link>
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)
        RX packets 2  bytes 612 (612.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16  bytes 3070 (2.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

3. ping网络测试

Tip

指定设备 wwan0进行ping网络测试。

(console)$ ping www.baidu.com -I wwan0
PING www.wshifen.com (103.235.46.115) from 10.138.192.102 enxca7f24fb0e94: 56(84) bytes of data.
64 bytes from 103.235.46.115 (103.235.46.115): icmp_seq=1 ttl=45 time=1094 ms
64 bytes from 103.235.46.115 (103.235.46.115): icmp_seq=2 ttl=45 time=3924 ms
64 bytes from 103.235.46.115 (103.235.46.115): icmp_seq=3 ttl=45 time=1870 ms

常见问题

  • Linux系统XFCE桌面版镜像烧录后,首次开机重启时出现服务异常问题 ?

目前发现XFCE桌面版镜像烧录后,首次开机存在显示异常问题,需手动重启显示服务;后续开机无需再次执行该操作。