Skip to content

Blog

GitLab CI-CD with GitLab-Runner

Run GitLab-Runner in container for GitLab CI/CD.

podman run --detach \
--privileged \
--name gitlab-runner \
--network host \
-v ${PWD}/config:/etc/gitlab-runner:z \
docker.io/gitlab/gitlab-runner:latest
podman exec -it gitlab-runner gitlab-runner register

Config the runner with instructions.

[1]. https://docs.gitlab.com/runner/

[2]. https://zhuanlan.zhihu.com/p/385110311

[3]. Podman-Volumes-and-SELinux

[4]. Manage-Podman-Container-With-Systemd

Mount Disk in Linux on Boot

BrefAutomatically mount the hard drive at boot

Section titled “BrefAutomatically mount the hard drive at boot”

Before mounting the disk, you need to know the path orUUIDof each disk. At this time, you mainly rely on the two instructionsfdiskandblkid. The former instruction obtains the partition information, and the latter instruction obtains the attributes of theBlock deviceblock device.``` $ sudo blkid /dev/sda1: LABEL=“Win10” UUID=“C4A0E65EA0E65708” TYPE=“ntfs” PARTUUID=“6190c592-01” /dev/sda2: UUID=“AE3C137D3C133FAF” TYPE=“ntfs” PARTUUID=“6190c592-02” /dev/sdb1: LABEL=“Apps” UUID=“0000678400004823” TYPE=“ntfs” PARTLABEL=“Basic data partition” PARTUUID=“45ed07d2-c9e3-4167-8868-3e33f62784e1” /dev/sdb2: LABEL=“Data” UUID=“0000678400004823” TYPE=“ntfs” PARTLABEL=“Basic data partition” PARTUUID=“2a8b4bf1-8357-4d65-bed4-f73f01b96431” /dev/sdb3: LABEL=“Backup” UUID=“0000678400004823” TYPE=“ntfs” PARTLABEL=“Basic data partition” PARTUUID=“a7187083-2820-4eef-83ff-05d8899879a2”

From the above output results, the disk can be mapped to the specific block device path`/dev/sdax`. Because the computer contains two disks, it contains`sda`and`sdb`. The block device path and`UUID`here will be used in the following configuration parameters.
## 2. Temporary MountFor a temporary solution, you can use the following command to mount`/dev/sda1`to the`/mnt/c`directory```
sudo mkdir /mnt/c
sudo mount -t ntfs /dev/sda1 /mnt/c

(1). Modify configuration fileThe solution to automatically mount after booting requires modifying the configuration file/etc/fstab. After opening it with an editor, add a new mount item in the following format

Section titled “(1). Modify configuration fileThe solution to automatically mount after booting requires modifying the configuration file/etc/fstab. After opening it with an editor, add a new mount item in the following format”
$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sdb5 during installation
UUID=4d2e5a83-d9fe-47bb-aa02-fee9ac8535e3 / ext4 errors=remount-ro 0 1
# /boot was on /dev/sdb6 during installation
UUID=9b521dc2-ad85-4ca6-bb8b-f285b312aa49 /boot ext4 defaults 0 2
# /home was on /dev/sdb7 during installation
UUID=f6b796dd-9e59-4f79-b70a-c2c8e5977163 /home ext4 defaults 0 2
# swap was on /dev/sdb4 during installation
UUID=9430ea0e-7ff9-4167-9bf7-1f3e08d26d34 none swap sw 0 0
# /mnt/Data was on /dev/sdb2 during installation
/dev/sdb2 /mnt/Data ntfs defaults 0 2
# /mnt/Backup was on /dev/sdb3 during installation
/dev/sdb3 /mnt/Backup ntfs defaults 0 2

The last two items are used to mount the disk. Of course, the/dev/sdbxin front of each line can also be replaced byUUID=xxxxx. However, since theUUIDof the two disks are consistent, there may be problems. Maybe you can use thePARTUUIDoutput byblkid.

sudo mkdir /mnt/{Data,Backup}
sudo mount -a

Mount SMB/CIFSUse systemd to automatically mount smb at boot

Section titled “Mount SMB/CIFSUse systemd to automatically mount smb at boot”
# This is a sample service script to mount CIFS/SAMBA shares.
# Please read carefully the comments in this file. For production usage
# you can remove all comments (lines beginning with "#") from this file.
[Unit]
# The description should be used to explain what this servicefile is for
Description=nas cifs mount home
# if we do network mounts like here we *require* 'network-online.service'
# which checks if the network is online
Requires=network-online.target
# our scripts must start *after* 'network-online.service', on timeout and if
# 'network-online.service' fails we can not mount and this scripts fails too
After=network-online.target
# usually we mount networks shares because we want they avaible *before* XBMC starts.
# so XBMC has access to this mounts from beginning. Note: this slows down the boot!
#Before=kodi.service
[Mount]
# The share we want mount
What=//IP_ADDRESS/Data
# Where we want mount this share
Where=/PATH_TO_MOUNT
# Any options you usually use with the "-o" parameter in the mount command
Options=username=haoran.qi,password=password,rw,vers=3.0,dir_mode=0775,file_mode=0664
# filesystem type
Type=cifs
[Install]
WantedBy=multi-user.target

VSCode C/CPP Environment

1. Install MinGWFor details, please refer to [C++ environment settings]

Section titled “1. Install MinGWFor details, please refer to [C++ environment settings]”

2. Configure VSCodeCreate a.vscodefolder under the source code folder, which containsc_cpp_properties.json,launch.json,tasks.json. For the specific meaning of each file, please refer to [VScode tasks.json and launch.json settings], [VSCode predefined variables]

Section titled “2. Configure VSCodeCreate a.vscodefolder under the source code folder, which containsc_cpp_properties.json,launch.json,tasks.json. For the specific meaning of each file, please refer to [VScode tasks.json and launch.json settings], [VSCode predefined variables]”

(1).c_cpp_properties.jsonNeed to change MinGW path to actual path

Section titled “(1).c_cpp_properties.jsonNeed to change MinGW path to actual path”
{
"configurations": [
{
"name": "RHEL7.2->Linux",
"includePath": [
"${workspaceFolder}/**",
"/opt/scadacom/current/**"
],
"forcedInclude": [],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [ //Release
"-std=c++11",
"-w",
"-O2",
"-pipe",
"-m64",
"-D_REENTRANT",
"-DQT_SHARED",
"-DQT_NO_DEBUG_OUTPUT",
"-DQT_NO_DEBUG",
"-DQT_GUI_LIB",
"-DQT_NETWORK_LIB",
"-DQT_CORE_LIB",
"-DQT_SHARED"
]
},
{
"name": "RHEL7.2-WindowsLocal",
"includePath": [
"${workspaceFolder}/**",
"~/Documents/Codes/include/RHEL7.2S5.8.10/**",
"C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include"
],
"forcedInclude": [],
"defines": [],
"compilerPath": "C:/ProgramData/chocolatey/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [ //Release
"-std=c++11",
"-w",
"-O2",
"-pipe",
"-m64",
"-D_REENTRANT",
"-DQT_SHARED",
"-DQT_NO_DEBUG_OUTPUT",
"-DQT_NO_DEBUG",
"-DQT_GUI_LIB",
"-DQT_NETWORK_LIB",
"-DQT_CORE_LIB",
"-DQT_SHARED"
],
"mergeConfigurations": false,
"browse": {
"path": [
"${workspaceFolder}/**",
"~/Documents/Codes/include/RHEL7.2S5.8.10/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}

(2).launch.jsonNeed to change MinGW path to actual path

Section titled “(2).launch.jsonNeed to change MinGW path to actual path”
{
"version": "0.2.0",
"configurations": [
{
"name": "QT-CPPGDB",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/wg_modbus_ats",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/debug/",
"environment": [],
//"symbolSearchPath": "C:\\Symbols",
"externalConsole": false,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"osx": {
"miDebuggerPath": "/Applications/Xcode.app/Contents/Developer/usr/bin/lldb-mi",
"MIMode": "lldb"
},
// "logging": {
// "moduleLoad": false,
// "trace": true
// },
"visualizerFile": "my.natvis"
},
{
"name": "CMake-CPPGDB",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/${workspaceFolderBasename}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build",
"environment": [],
//"symbolSearchPath": "C:\\Symbols",
"externalConsole": false,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"osx": {
"miDebuggerPath": "/Applications/Xcode.app/Contents/Developer/usr/bin/lldb-mi",
"MIMode": "lldb"
},
// "logging": {
// "moduleLoad": false,
// "trace": true
// },
"visualizerFile": "my.natvis"
}
]
}

(3). tasks.jsonYou can copy the file directly

Section titled “(3). tasks.jsonYou can copy the file directly”
{
"version": "2.0.0",
// "windows": {
// "options": {
// "shell": {
// "executable": "bash.exe",
// "args": ["-c"]
// }
// }
// },
"tasks": [
{
"label": "Qmake",
"type": "shell",
"command": "/usr/local/Trolltech/Qt-4.8.4/bin/qmake",
"args": [],
"group": "build",
"presentation": {
"reveal": "silent",
"clear": true
}
},
{
"label": "Clean",
"type": "shell",
"command": "make",
"args": [
"clean"
],
"group": "build",
"presentation": {
"reveal": "silent",
"clear": true
}
},
{
"label": "MakeCompile",
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
"Clean",
"Qmake"
],
"command": "/usr/bin/make",
"args": [
],
"group": "build",
"presentation": {
// "reveal": "silent",
"clear": true
}
},
]
}

[2]. https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables

[3]. https://zhuanlan.zhihu.com/p/92175757

[4]. https://www.cnblogs.com/bpf-1024/p/11597000.html

[5]. https://zhuanlan.zhihu.com/p/87864677

[C++ environment setup]: https://www.runoob.com/cplusplus/cpp-environment-setup.html[VSCode predefined variables]: https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables[Settings of VScode tasks.json and launch.json]: https://zhuanlan.zhihu.com/p/92175757

Windows 10 uses WIFI and wired network card at the same timeWhen the wired network card and the wireless network card are connected to two different networks at the same time, Windows will automatically disconnect the wireless network by default and use the wired network connection.

Section titled “1. Set hop count- What are hops> - Metrics is a value assigned to an IP route for a particular network interface that identifies the cost associated with using that route. For example, hop count can be calculated based on link speed, hop count, or time delay. Automatic metric counting is a new feature in Windows that automatically configures the metric count for local routing based on link speed. Automatic metric counting is enabled by default, but can be manually configured to give it a specific metric number.> - The Automatic Hop Counting feature is useful when the routing table contains multiple routes for the same destination. For example, if your computer has a 10 megabit (Mb) network interface and a 100 Mb network interface, and the computer has a default gateway configured on both network interfaces, the Automatic Hop Counting feature assigns a higher hop count to the slower network interface. This feature forces all traffic to the Internet, for example, to use the fastest network interface available.”

For details, please refer to:Instructions on the “Automatic Hop Counting” feature in IPv4 routing

Section titled “2. Setup steps### 1. Select the appropriate hop value based on the link above:”

2. Open Control Panel\Network and Internet\Network Connections and set the two network interfaces in sequence.

Section titled “2. Open Control Panel\Network and Internet\Network Connections and set the two network interfaces in sequence.”

[2] https://support.microsoft.com/zh-cn/help/299540/an-explanation-of-the-automatic-metric-feature-for-ipv4-routes

KVM PCI Passthrough

1. Enable IOMMU by editing the grub configuration file.

Section titled “1. Enable IOMMU by editing the grub configuration file.”

For Intel, boot the machine, and append intel_iommu=on to the end of the GRUB_CMDLINE_LINUX line in the grub configuration file.

vi /etc/default/grub
...
GRUB_CMDLINE_LINUX="nofb splash=quiet console=tty0 ... intel_iommu=on
...

For AMD, boot the machine, and append amd_iommu=on to the end of the GRUB_CMDLINE_LINUX line in the grub configuration file.

vi /etc/default/grub
...
GRUB_CMDLINE_LINUX="nofb splash=quiet console=tty0 ... amd_iommu=on
...

2. Refresh the grub.cfg file and reboot the host for these changes to take effect:

Section titled “2. Refresh the grub.cfg file and reboot the host for these changes to take effect:”
grub2-mkconfig -o /boot/grub2/grub.cfg
reboot

3. Prevent the driver from binding to the Device.

Section titled “3. Prevent the driver from binding to the Device.”
grubby --args="pci-stub.ids=10de:11fa" --update-kernel DEFAULT

10de:11fa: bus id of device, can be get by lspci -Dnn

If certain GPU functions, such as audio, cannot be passed through to the VM due to support limitations, you can modify the driver bindings of the endpoints within an IOMMU group to pass through only the necessary GPU functions.

  • Convert the GPU settings to XML and note the PCI address of the endpoints that you want to prevent from attaching to the host drivers.

  • Prevent the endpoints from attaching to the host driver.

  • driverctl set-override 0000:02:00.1 vfio-pci

[1]. https://access.redhat.com/documentation/en-us/red_hat_virtualization/4.0/html/installation_guide/appe-configuring_a_hypervisor_host_for_pci_passthrough#Enabling_IOMMU_Manually

[2]. https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/configuring_and_managing_virtualization/assembly_managing-gpu-devices-in-virtual-machines_configuring-and-managing-virtualization#proc_assigning-a-gpu-to-a-virtual-machine_assembly_managing-gpu-devices-in-virtual-machines

[3]. 命令行安装KVM虚拟化系统