Solution for VS Code and KWallet Integration Issues on Ubuntu

“You’re running in a KDE environment but the OS keyring is not available for encryption. Ensure you have kwallet running.”, follow these steps to configure VS Code to use gnome-libsecret instead of KWallet:

1. Create Configuration File:

touch ~/.config/Code/User/argv.json

then write the content:

{
  "password-store": "gnome-libsecret"
}

2. Install Prerequisites:

Install gnome-keyring by running:

sudo apt install gnome-keyring -y

3. Launch VS Code with gnome-libsecret:

code --password-store="gnome-libsecret"

Using UFW Firewall with Docker Containers

Running Docker containers with UFW firewall setup can be challenging because Docker manipulates iptables rules by default. However, with some configuration, you can ensure both Docker and UFW work well together. Below is a step-by-step guide to configure Docker to not interfere with iptables and manually set up UFW rules.

1. Configure Docker Daemon, make “iptables”: false

sudo vi /etc/docker/daemon.json

should like below:

{
    "runtimes": {
        "nvidia": {
            "path": "nvidia-container-runtime",
            "runtimeArgs": []
        }
    },
    "iptables": false
}

2. Restart Docker

sudo systemctl restart docker

3. Modify UFW Forward Policy

sudo sed -i -e 's/DEFAULT_FORWARD_POLICY="DROP"/DEFAULT_FORWARD_POLICY="ACCEPT"/g' /etc/default/ufw

4. Reload UFW to apply the changes:

sudo ufw reload

Reference:

How to Install CUDA12.5 on Ubuntu 22.04.4 LTS

1. Download and Install CUDA Keyring:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb

2. Update system and Install CUDA Toolkit:

sudo apt-get update -y
sudo apt-get install cuda-toolkit -y

3. Reboot:

sudo sync; sudo /sbin/shutdown -r now

4. Configure Environment Variables:

Add the following lines to the end of your ~/.bashrc file to set the environment variables:

export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-12.5/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

then:

source ~/.bashrc

5. Verify the Installation

nvcc -V

You should see an output similar to:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Jun__6_02:18:23_PDT_2024
Cuda compilation tools, release 12.5, V12.5.82
Build cuda_12.5.r12.5/compiler.34385749_0

Additional Notes:

Persistence Daemon: If you want to enable the NVIDIA Persistence Daemon for better GPU management, you can start it as root:

/usr/bin/nvidia-persistenced --verbose

Deploy GPU-accelerated applications in containers:

sudo apt-get install -y nvidia-docker2

Then test:

sudo docker run --rm --gpus all nvidia/cuda:12.5.0-base-ubuntu22.04 nvidia-smi

Install nvidia driver:

sudo apt-get install nvidia-driver-555

Then, test:

nvidia-smi

reference:

CUDA Toolkit 12.5 Update 1 Downloads

Installing the NVIDIA Container Toolkit

NVIDIA CUDA Installation Guide for Linux

How to Install CUDA on Ubuntu 22.04 | Step-by-Step

NVIDIA Driver Downloads

Optimizing Video Compression with ffmpeg and hevc_nvenc

ffmpeg -i fileName.mp4 -c:v hevc_nvenc -preset slow -rc:v vbr -cq:v 24 -b:v 0 -c:a aac -b:a 128k -vf scale=1280:-1 -movflags +faststart fileName_compressed.mp4
FlagExplanation
-i fileName.mp4Specifies the input file as fileName.mp4
-c:v hevc_nvencSets the video codec to NVIDIA’s HEVC encoder
-preset slowSets the encoding preset to “slow” for better compression efficiency
-rc:v vbrSets the rate control mode to variable bitrate
-cq:v 24Sets the Constant Quality (CQ) value to 24 (lower values mean higher quality)
-b:v 0Sets the target bitrate to 0, allowing CQ mode to determine the bitrate
-c:a aacSets the audio codec to AAC
-b:a 128kSets the audio bitrate to 128 kbps
-vf scale=1280:-1Scales the video width to 1280 pixels, height scaled proportionally
-movflags +faststartOptimizes the file for web streaming, allowing faster video startup
fileName_compressed.mp4Specifies the output filename
This command utilizes your NVIDIA GPU for encoding, which can be significantly faster than CPU encoding. The quality control is managed through the CQ (Constant Quality) value, where lower values result in higher quality but larger file sizes.

smaller:

ffmpeg -i 1.mp4 -c:v hevc_nvenc -preset slow -rc:v vbr -cq:v 29 -b:v 450k -c:a aac -b:a 96k -vf scale=960:-1 -movflags +faststart 2.mp4

Configuring a Static IP on Linux by Netplan Configuration Template

  1. Configuration File (/etc/netplan/01-network-manager-all.yaml):
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
      eth0:
          dhcp4: no
          addresses:
              - xx.xx.xx.xx/xx
          routes:
            - to: default
              via: yy.yy.yy.yy
          nameservers:
              addresses:
                  - zz.zz.zz.zz
                  - aa.aa.aa.aa
                  - bb.bb.bb.bb

xx.xx.xx.xx/xx: the static IP address assigned to the network interface with subnet mask information

yy.yy.yy.yy: the IP address of the gateway

zz.zz.zz.zz: Primary DNS server

aa.aa.aa.aa: Secondary DNS server

bb.bb.bb.bb: Tertiary DNS server

2. apply netplan and then rebooot

sudo netplan apply

Share Data Between Windows Server and Hyper-V Using VHDX Files

1. Creating a VHDX File on the Host:

Open Hyper-V Manager:

  • On the Windows Server host, search for and open “Hyper-V Manager”.

Create a New Virtual Hard Disk (VHDX):

  • In the right-hand action pane, choose “New” > “Hard Disk…”, to start the new virtual hard disk wizard.
  • Select the VHDX format, specify its size and save location (e.g., D:\Shared.vhdx).

Complete the Wizard:

  • Finish the wizard, ensuring you choose fixed size for better performance instead of dynamic expansion.

2. Attaching the VHDX File on the Host:

Open Disk Management:

  • Search for “Disk Management” or open it by running diskmgmt.msc.

Attach the VHDX File:

  • In the Disk Management menu, choose “Action” > “Attach VHD…”, select and attach the newly created VHDX file (D:\Shared.vhdx).
  • Initialize, partition, and format the VHDX file upon first attachment.
  • After this, the VHDX file will appear like a regular disk and can be written to.

3. Attaching the VHDX File to the Ubuntu Virtual Machine:

Open Hyper-V Manager:

  • Make sure to save any pending files and shut down the target virtual machine, and also unmount shared folder (as cannot use it meanwhile) in Windows Server side.

Access Virtual Machine Settings:

  • Right-click the target virtual machine and select “Settings”.
  • In the hardware section of the virtual machine, choose “SCSI Controller” or “IDE Controller” and click “Add Hard Drive…”.

Select the VHDX File:

  • In the pop-up dialog, choose “Use an existing virtual hard disk”, select the VHDX file created earlier (e.g., D:\Shared.vhdx).
  • Click “Apply” to save the changes.

4.confirm the VHDX File in Ubuntu:

Use the lsblk command in the terminal to check the new hard disk device.

Configuring a Static IP on Windows Server 2022 and Setting Up External Virtual Switch in Hyper-V

Configuring a Static IP on Windows Server 2022:

1. Open Network and Sharing Center:

In the left menu, select “Change adapter settings”.

2. Select and Right-Click Your Network Connection, then Select “Properties”

3. Select “Internet Protocol Version 4 (TCP/IPv4)”:

Click the item, then click “Properties”.

4. Configure IPv4 Settings:

Select “Use the following IP address” and enter the information provided by your network administrator: eg:

IP address: 10.x.x.x
Subnet mask: 255.255.254.0
Default gateway: 10.x.x.x

Select “Use the following DNS server addresses” and enter the DNS servers:

Preferred DNS server: 10.x.x.x
Alternate DNS server: 10.x.x.x or 10.x.x.x

5. Confirm and Apply Settings:

Click “OK” to complete, then click “OK” or “Close” again to close the properties window.

6. Restart Network Connection (Optional):

Right-click on the configured network connection and select “Disable”, then right-click again and select “Enable”.

Setting Up an External Virtual Switch in Hyper-V:

1. Launch Hyper-V Manager and select the host you wish to configure.

2. Create an External Virtual Switch:

In the “Actions” menu on the right, click “Virtual Switch Manager”.
Select “New virtual network switch”, then choose “External”.
Click “Create”.

3. Configure the External Virtual Switch:

In the “Name” field, give the switch a meaningful name, e.g., “ExternalSwitch”.
In the “Connection Type” section, select your only physical network adapter.
Check “Allow management operating system to share this network adapter”.

4.Apply and Confirm Settings:

Click “Apply” and “OK” to confirm.

This allows both the host and virtual machines to connect to the internet simultaneously.

ZeroTier Dockerfile Setup

1. Prepare these files in the same folder:

Dockerfile:

FROM debian:buster-slim as builder

## Supports x86_64, x86, arm, and arm64
RUN sed -i 's|deb.debian.org/debian|archive.debian.org/debian|g; s|security.debian.org|archive.debian.org/|g' /etc/apt/sources.list
RUN apt-get update && apt-get install -y curl gnupg
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0x1657198823e52a61  && \
    echo "deb http://download.zerotier.com/debian/buster buster main" > /etc/apt/sources.list.d/zerotier.list
RUN sed -i 's|deb.debian.org/debian|archive.debian.org/debian|g; s|security.debian.org|archive.debian.org/|g' /etc/apt/sources.list
RUN apt-get update && apt-get install -y zerotier-one=1.14.0

FROM debian:buster-slim
LABEL version="1.14.0"
LABEL description="Containerized ZeroTier One for use on CoreOS or other Docker-only Linux hosts."

# ZeroTier relies on UDP port 9993
EXPOSE 9993/udp

# Install necessary libraries
RUN sed -i 's|deb.debian.org/debian|archive.debian.org/debian|g; s|security.debian.org|archive.debian.org/|g' /etc/apt/sources.list
RUN apt-get update && apt-get install -y libssl1.1

RUN mkdir -p /var/lib/zerotier-one
COPY --from=builder /usr/sbin/zerotier-cli /usr/sbin/zerotier-cli
COPY --from=builder /usr/sbin/zerotier-idtool /usr/sbin/zerotier-idtool
COPY --from=builder /usr/sbin/zerotier-one /usr/sbin/zerotier-one
COPY main.sh /var/lib/zerotier-one/main.sh

RUN chmod 0755 /var/lib/zerotier-one/main.sh
ENTRYPOINT ["/var/lib/zerotier-one/main.sh"]
CMD ["zerotier-one"]

main.sh:

#!/bin/sh

export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin

if [ ! -e /dev/net/tun ]; then
    echo 'FATAL: cannot start ZeroTier One in container: /dev/net/tun not present.'
    exit 1
fi

exec zerotier-one

2. build zerotier docker image:

docker build --no-cache -t zerotier-one:1.14.0 .

3. start the docker container:

docker run -d --name zerotier-one --cap-add=NET_ADMIN --device /dev/net/tun --network host --restart unless-stopped zerotier-one:1.14.0

4. join the network:

docker exec zerotier-one zerotier-cli join XXXXXXXXXX

Enabling GPU Acceleration in Shotcut for Faster Video Export

In Shotcut, the default encoder is usually libx264, which uses the CPU for encoding. To enable GPU-accelerated encoding, you need to select a hardware-accelerated encoder, such as NVIDIA’s NVENC or Intel’s Quick Sync.

Change Encoder to Enable GPU Acceleration:

Open Shotcut, then

Settings -> GPU Effects (select and restart Shotcut)

Export -> Advanced -> Codec -> Codec (select hevc_nvenc or h264_qsv)

Encoder Selection Based on Needs:

hevc_nvenc:

Advantages:

1.Higher compression efficiency, smaller file size for the same quality.
2.Suitable for high-quality and smaller file size outputs.

Disadvantages:

1.Slower encoding speed.
2.Lower compatibility, older devices or some platforms may not support HEVC (H.265).

h264_nvenc:

Advantages:

1.Broader compatibility, suitable for most devices and platforms.
2.Faster encoding speed, ideal for tasks requiring quick output.

Disadvantages:

1.Larger file size for the same quality.

Setting up C Environment in Visual Studio Code: Resolving ‘Launch: Program Path Does Not Exist’ Error

When setting up an embedded C development environment using Visual Studio Code (VSC), if you encounter the error “Can’t compile code ‘launch: program does not exist'”, the solution is as follows:

1. Place the following three files, launch.json, settings.json, tasks.json, in the project directory\.vscode.

launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "console": "externalTerminal"
        },
        {
            "name": "(Windows) Attach",
            "type": "cppvsdbg",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

settings.json:

{
    "files.associations": {
        "*.tcc": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cstddef": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "exception": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "iostream": "cpp",
        "istream": "cpp",
        "limits": "cpp",
        "new": "cpp",
        "ostream": "cpp",
        "streambuf": "cpp",
        "type_traits": "cpp",
        "typeinfo": "cpp"
    }
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build myfile",
            "type": "shell",
            "command": "g++",
            "args": [
                "-std=c++14",
                "-g",
                "-o",
                "${fileBasenameNoExtension}.exe",
                "${fileBasename}"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

2. compile the program:

gcc hello.c -o hello.exe

3. In VSC, File -> Open Folder, then click [Run] and select (Windows)Launch to proceed.

reference:

.vscode

Can’t compile code “launch: program <program_path> does not exist “

通过 WordPress.com 设计一个这样的站点
从这里开始