nixOSOnnuc11

1. 安装

启动光盘引导系统,进入到安装界面,更换nixos用户的密码后,远程ssh进入到安装界面后:

nix-channel --add https://mirrors.ustc.edu.cn/nix-channels/nixpkgs-unstable nixpkgs
nix-channel --add https://mirrors.ustc.edu.cn/nix-channels/nixos-24.05 nixos
nix-channel --list
nix-channel --update
nixos-rebuild --option substituters http://mirror.sjtu.edu.cn/nix-channels/store switch --upgrade

对512G的nvme ssd进行分区:

parted /dev/nvme0n1
(可选) rm 2
(可选) rm 1
mklabel gpt
mkpart ESP fat32 1MiB 256MiB
set 1 esp on
mkpart primary 256MiB -2GiB
unit s
mkpart primary linux-swap 972580864 100%
quit

磁盘分区如下:

nvme0n1     259:0    0 465.8G  0 disk 
├─nvme0n1p1 259:4    0   255M  0 part 
├─nvme0n1p2 259:5    0 463.5G  0 part 
└─nvme0n1p3 259:6    0     2G  0 part 

创建文件系统:

mkfs.fat -F32 /dev/nvme0n1p1 
mkfs.btrfs -L nixos /dev/nvme0n1p2 
mkswap -L swap /dev/nvme0n1p3

创建btrfs的子卷:

mount /dev/nvme0n1p2 /mnt
btrfs subvolume create /mnt/root 
btrfs subvolume create /mnt/home
btrfs subvolume create /mnt/nix 
umount /mnt 
mount -o compress=zstd,subvol=root /dev/nvme0n1p2 /mnt
mkdir /mnt/{home,nix,boot}
mount -o compress=zstd,subvol=home /dev/nvme0n1p2 /mnt/home/
mount -o compress=zstd,noatime,subvol=nix  /dev/nvme0n1p2  /mnt/nix
mount /dev/nvme0n1p1 /mnt/boot
swapon /dev/nvme0n1p3

创建硬件配置文件并修改之:

nixos-generate-config --root /mnt

vim /mnt/etc/nixos/hardware-configuration.nix, 更改以下的几行:

19c19
<       options = [ "subvol=root" "compress=zstd"];
---
>       options = [ "subvol=root" ];
25c25
<       options = [ "subvol=home" "compress=zstd"];
---
>       options = [ "subvol=home" ];
31c31
<       options = [ "subvol=nix" "compress=zstd" "noatime"];
---
>       options = [ "subvol=nix" ];

配置configuration.nix文件,下面记录它的内容,值得注意的是,这里禁用了某些后面需要打开的选项,因为如果一开始打开,则有可能安装失败:

# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page, on
# https://search.nixos.org/options and in the NixOS manual (`nixos-help`).

{ config, lib, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  # Use the systemd-boot EFI boot loader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  networking.hostName = "gen11"; # Define your hostname.
  # Pick only one of the below networking options.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.
  networking.networkmanager.enable = true;  # Easiest to use and most distros use this by default.

  # Set your time zone.
  time.timeZone = "Asia/Shanghai";

  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";

  # Select internationalisation properties.
  i18n.defaultLocale = "en_US.UTF-8";
  # console = {
  #   font = "Lat2-Terminus16";
  #   keyMap = "us";
  #   useXkbConfig = true; # use xkb.options in tty.
  # };

  # Enable the X11 windowing system.
  services.xserver.enable = true;
  # Autologin for user dash
  services.displayManager.sddm.enable = true;
  services.displayManager.sddm.wayland.enable = true;
  #services.displayManager.autoLogin.enable = true;
  #services.displayManager.autoLogin.user = "dash";
  # Hyprland
  #programs.hyprland.enable = true;
  # zsh
  programs.zsh.enable = true;
  users.defaultUserShell = pkgs.zsh;

  # Configure keymap in X11
  # services.xserver.xkb.layout = "us";
  # services.xserver.xkb.options = "eurosign:e,caps:escape";

  # Enable CUPS to print documents.
  services.printing.enable = true;

  # Enable sound.
  # hardware.pulseaudio.enable = true;
  # OR
  services.pipewire = {
    enable = true;
    pulse.enable = true;
  };

  # Enable touchpad support (enabled default in most desktopManager).
  # services.libinput.enable = true;

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.dash = {
    isNormalUser = true;
    extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
    packages = with pkgs; [
      firefox
      tree
    ];
  };

  security.sudo.extraRules= [
    {  users = [ "dash" ];
      commands = [
         { command = "ALL" ;
           options= [ "NOPASSWD" ]; # "SETENV" # Adding the following could be a good idea
        }
      ];
    }
  ];

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
    vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
    wget
    git
    dconf
  ];

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  # programs.gnupg.agent = {
  #   enable = true;
  #   enableSSHSupport = true;
  # };

  # List services that you want to enable:

  # Enable the OpenSSH daemon.
  services.openssh.enable = true;

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ ... ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  # networking.firewall.enable = false;

  # Copy the NixOS configuration file and link it from the resulting system
  # (/run/current-system/configuration.nix). This is useful in case you
  # accidentally delete configuration.nix.
  # system.copySystemConfiguration = true;

  # This option defines the first version of NixOS you have installed on this particular machine,
  # and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
  #
  # Most users should NEVER change this value after the initial install, for any reason,
  # even if you've upgraded your system to a new NixOS release.
  #
  # This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
  # so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how
  # to actually do that.
  #
  # This value being lower than the current NixOS release does NOT mean your system is
  # out of date, out of support, or vulnerable.
  #
  # Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
  # and migrated your data accordingly.
  #
  # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
  system.stateVersion = "24.11"; # Did you read the comment?

  nix.settings.substituters = [
    "http://mirror.sjtu.edu.cn/nix-channels/store"
  ];

  nixpkgs.config.allowUnfree = true;
  nixpkgs.config.permittedInsecurePackages = [
  #  "qtwebkit-5.212.0-alpha4"
  ];
#
#  home-manager.users.dash = { pkgs, ... }: {
#  home.stateVersion = "24.11";  
#  home.packages = [ ];
#  };

}

执行以下命令开始安装到磁盘:

nixos-install --option substituters https://mirror.sjtu.edu.cn/nix-channels/store

创建用户的密码:

nixos-enter
passwd dash

2. 配置

更改configuration.nix,并从历史文件中拷贝相关文件到/etc/nixos 目录下:

 vim configuration.nix
 cp /home/dash/nixos/flake.nix .
 cp /home/dash/nixos/hyprland.nix .
 cp /home/dash/nixos/home.nix .
 cp /home/dash/nixos/zsh.nix .

使用以下命令重新编译出新环境

dash@gen11:~/ > sudo nixos-rebuild switch --option substituers https://mirror.sjtu.edu.cn/nix-channels/store

3. 桌面切换(awesome-hyprland)

pikvmx86onubuntu2204

Steps:

git clone https://github.com/mofeng-git/One-KVM
cd One-KVM
sudo bash install-x86.sh

Configuration:

$ vim /etc/kvmd/override.yaml
...
kvmd:
    hid:
        ### add entries for use with the ch9329 serial HID
        type: ch9329
        speed: 9600     # default speed after loading ch9329 plugin is 9600
        device: /dev/ttyUSB0
...

Change to video0:

$ vim /etc/kvmd/main.yaml
...
                - 720x576
                - 720x480
                - 640x480
        cmd:
            - "/usr/bin/ustreamer"
            - "--device=/dev/video0"
            - "--persistent"
            - "--format=mjpeg"
            - "--resolution={resolution}"
...

Examine via:

kvmd -m

LinuxTips17

1. liquorix kernel(zen)

Install on Ubuntu 22.04 via:

curl -s 'https://liquorix.net/install-liquorix.sh' | sudo bash

2. pikvm for x86

Tips(comment the brltty related items and reboot, then ttyUSB0 is avaiable):

sudo vim /usr/lib/udev/rules.d/85-brltty.rules
# ENV{PRODUCT}=="1a86/7523/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"
sudo systemctl mask brltty.path
sudo reboot

Change to ubuntu22.04 and solved the problem.

3. socket 5 proxy

Open the proxy via:

ssh -N -D 0.0.0.0:10000 dash@localhost

Then set the proxy in other machine for yum usage:

$ vim /etc/yum.conf
#proxy=socks5://10.23.119.200:10000

4. ubuntu22.04 curl issue

Problem:

OpenSSL Error messages: error:0A000126:SSL routines::unexpected eof while reading

solved via:

apt remove curl
apt purge curl
apt-get update
apt-get install -y libssl-dev autoconf libtool make
cd /usr/local/src
wget https://curl.haxx.se/download/curl-7.88.1.zip
unzip curl-7.88.1.zip
cd curl-7.88.1
./buildconf
./configure --with-ssl 
make
sudo make install
sudo cp /usr/local/bin/curl /usr/bin/curl
sudo ldconfig
curl -V

5. nix-shell install

install via:

nix-shell '<home-manager>' -A install --option substituters https://mirrors.ustc.edu.cn/nix-channels/store

6. Workingtips for nix on ubuntu

简单步骤:

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
nix-channel --update
nix-shell '<home-manager>' -A install
nix run home-manager/master -- init --switch 
sudo apt install seatd
sudo usermod -a -G video $USER
reboot
nix profile install github:guibou/nixGL --impure
home-manager switch --option substituters https://mirrors.ustc.edu.cn/nix-channels/store
sudo apt-get install -y pipewire pipewire-pulse

Also edit the limitation of /etc/security/limits.conf, as following.

Modification for nix files:

$ vim ~/.config/home-manager/hyprland.nix
                monitor=,1920x1080@60,auto,1
......
             master {
                 # See https://wiki.hyprland.org/Configuring/Master-Layout/ for more
# new_is_master = true
                 new_status = slave
$ vim ~/.config/home-manager/flake.nix
    #hyprland.url = "github:hyprwm/Hyprland";
    hyprland.url = "git+https://github.com/hyprwm/Hyprland?submodules=1";

7. limitation linux

enlarge via:

 /etc/security/limits.conf, add

* soft nofile 1000001
* hard nofile 1000001

8. nix dconf issue

problem:

Activating dconfSettings
dbus[13416]: Failed to start message bus: Configuration file needs one or more <listen> elements giving addresses
dbus-run-session: EOF reading address from bus daemon

Solved via:

not solved, for centos's dbus is pretty old
### 9. pactrap archlinux
Can't Pacstrap because of "Corrupted" packages, solved via:     

pacman -Sy archlinux-keyring sudo pacstrap -c /mnt base


### 10. nixos dhcpd issue
encounter following issue:      

   Failed assertions:
   - The option definition `services.dhcpd4' in `/nix/store/yq5mkfx3b97iczs5a6lhjm14gkjx9795-source/configuration.nix' no longer has any effect; please remove it.
   The dhcpd4 module has been removed because ISC DHCP reached its end of life.
   See https://www.isc.org/blogs/isc-dhcp-eol/ for details.
   Please switch to a different implementation like kea or dnsmasq.
switch to new implementation:     

### 11. sybench rocklinux
Install via:      

sudo yum install -y epel-release sudo yum install ./sysbench…..


### 12. x0vncserver
Using x0vncserver for replacing nxplayer:      

$ sudo pacman -S tigervnc $ vncpasswd $ vim ~/.xprofile x0vncserver -rfbauth ~/.vnc/passwd &


### 13. git clone via socks proxy
temp using socks proxy via:     

git -c “http.proxy=socks5h://127.0.0.1:21080” clone https://github.com/Limitex/ComfyUI-Diffusers.git


### 14. ignore ast kernel issue
issue:      

W: Possible missing firmware /lib/firmware/ast_dp501_fw.bin for module ast

Solved via:     

touch /lib/firmware/ast_dp501_fw.bin update-initramfs -u -k all


### 15. watch sync status
via:      

watch -d grep -e Dirty: -e Writeback: /proc/meminfo


### 15. g++ update
via:     

2019 sudo apt install -y g++-12 2020 ls -la /usr/bin | grep g++ 2021 sudo update-alternatives –install /usr/bin/g++ g++ /usr/bin/g++-11 10 2022 sudo update-alternatives –install /usr/bin/g++ g++ /usr/bin/g++-12 20 2023 sudo update-alternatives –install /usr/bin/c++ c++ /usr/bin/g++ 30


### 16. set default opener
Install:     

perl-file-mimeinfo Or perl538Packages.FileMimeInfo

Select the default opener for jpeg:     

mimeopen -d photo.jpeg


### 17. esxi usb nic
`https://avojak.com/blog/2024/01/17/installing-esxi-with-usb-nic/`, 参考。    



### 18. nixos citrix workspace
Download the tar file from citrix:     

sudo nixos-rebuild switch –option substituers https://mirror.sjtu.edu.cn/nix-channels/store nix-prefetch-url file:///home/dash/Downloads/linuxx64-24.5.0.76.tar.gz sudo nixos-rebuild switch –option substituers https://mirror.sjtu.edu.cn/nix-channels/store


### 19. Run llama3.1
Steps:       

curl -fsSL https://ollama.com/install.sh | sh ollama run llama3.1:8b


### 20. offline kubespray issues
Solved via:     

tar xzvf ../off.tar.gz cd kubespray-offline-2.25.0-0/ cd outputs/ ./setup-container.sh && ./start-nginx.sh && ./setup-offline.sh && ./setup-py.sh && ./start-registry.sh && ./load-push-all-images.sh && ./extract-kubespray.sh cd kubespray-2.25.0/ cd inventory/ cp -r sample/ rong cd rong/ vim inventory.ini cd ../../ python3.11 -m venv ~/.venv/3.11 source ~/.venv/3.11/bin/activate pip install -U pip pip install -r requirements.txt cp ../../offline.yml inventory/rong/group_vars/all/offline.yml vim inventory/rong/group_vars/all/offline.yml cp ~/new/kubespray-offline-2.25.0-0/outputs/playbook/offline-repo.yml . cp -r ~/new/kubespray-offline-2.25.0-0/outputs/playbook/roles/offline-repo/ roles/ ansible-playbook -i inventory/rong/inventory.ini offline-repo.yml ansible-playbook -i inventory/rong/inventory.ini –become –become-user=root cluster.yml kubectl get nodes kubectl get po –all-namespaces vim /etc/systemd/resolved.conf reboot


### 21. grep in linux root
via:    

grep -rli –exclude-dir={proc,boot,root,sys} ‘xmlns:qemu=’ /


### 22. one-kvm-docker
via:    

docker run -itd -p443:443 -p80:80 –name pikvm-docker –device=/dev/ttyUSB0:/dev/kvmd-hid –device=/dev/video0:/dev/kvmd-video pikvm-ch9329:0.61


![/images/20240821_095332_x.jpg](/images/20240821_095332_x.jpg)

should use relative mouse.   

### 23. cowsay issue
issue:    

cowsay: Could not find cowfile for ‘default.cow’!

Solved via:   

$ vim ~/.zshrc export ZSH=/home/dash/.oh-my-zsh COWPATH=/usr/share/cowsay/cows

recreate the terminal, this time cowsay works properly.   

### 24. flux1-dev-bnb-nf4-v2
Steps:    

models:
(base) dash@comfyvm:~/Code/ComfyUI/models/checkpoints$ mv ~/flux1-dev-bnb-nf4-v2.safetensors . (base) dash@comfyvm:~/Code/ComfyUI/models/checkpoints$ pwd /home/dash/Code/ComfyUI/models/checkpoint

Custom model:
(base) dash@comfyvm:~/Code/ComfyUI/custom_nodes$ mv ~/ComfyUI_bitsandbytes_NF4-master.zip . (base) dash@comfyvm:~/Code/ComfyUI/custom_nodes$ unzip ComfyUI_bitsandbytes_NF4-master.zip Archive: ComfyUI_bitsandbytes_NF4-master.zip 6c65152bc48b28fc44cec3aa44035a8eba400eb9 creating: ComfyUI_bitsandbytes_NF4-master/ inflating: ComfyUI_bitsandbytes_NF4-master/LICENSE.txt
inflating: ComfyUI_bitsandbytes_NF4-master/README.md
inflating: ComfyUI_bitsandbytes_NF4-master/init.py
extracting: ComfyUI_bitsandbytes_NF4-master/requirements.txt

$ conda activate comfyui (comfyui) dash@comfyvm:/opt/src/redsocks$ cd ~/Code/ComfyUI/ (comfyui) dash@comfyvm:~/Code/ComfyUI$ python -s -m pip install -U bitsandbytes

### 25. hygon win7
libvirt configuration:    

<memballoon model='virtio'>
  <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
</memballoon>
  <os>
    <type arch='x86_64' machine='pc-q35-8.2'>hvm</type>
    <boot dev='hd'/>
  </os>

hardware info:

root@idv-P860:~# lspci | grep -i vga
06:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Lexa PRO [Radeon 540/540X/550/550X / RX 540X/550/550X] (rev c7)

win7, only in bios with Win7_hygon.iso, select q35. and install specified old win7 driver.

26. archlinux cn

Edit the /etc/pacman.conf:

[archlinuxcn]
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch

Then:

$ sudo pacman -Sy archlinuxcn-keyring

27. bootrepair

via:

sudo add-apt-repository ppa:yannubuntu/boot-repair && sudo apt update
sudo apt install -y boot-repair && boot-repair

28. nvidia t4 qxl

Configuration items:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}
EnableMsHybrid 1
qxl: 
EnableMsHybrid 2
GridLicensedFeatures 7
AdapterType should be removed.

29. take screenshot

via:

xfce4-screenshooter  -f --display=:2 -s /tmp/test3_5.jpg

30. kernel-lt

Install via:


[root@cc-shhsh-x86-controller-1 ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" install kernel-lt
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package kernel-lt.x86_64 0:5.4.278-1.el7.elrepo will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================
 Package                                   Arch                                   Version                                                Repository                                     Size
=============================================================================================================================================================================================
Installing:
 kernel-lt                                 x86_64                                 5.4.278-1.el7.elrepo                                   elrepo-kernel                                  50 M

Transaction Summary
=============================================================================================================================================================================================
Install  1 Package

Total download size: 50 M
Installed size: 230 M
Is this ok [y/d/N]: y
Downloading packages:
kernel-lt-5.4.278-1.el7.elrepo.x86_64.rpm                                                                                                                             |  50 MB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : kernel-lt-5.4.278-1.el7.elrepo.x86_64                                                                                       

Configure via:

[root@cc-shhsh-x86-controller-1 ~]# ls /boot/vmlinuz-5.4.278-1.el7.elrepo.x86_64 
/boot/vmlinuz-5.4.278-1.el7.elrepo.x86_64
[root@cc-shhsh-x86-controller-1 ~]# grubby --set-default /boot/vmlinuz-5.4.278-1.el7.elrepo.x86_64 
[root@cc-shhsh-x86-controller-1 ~]# grub2-mkconfig -o /boot/efi/EFI/
BOOT/   centos/ 
[root@cc-shhsh-x86-controller-1 ~]# grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.278-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.4.278-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-4.19.12-7_rc1.zdyun.x86_64
Found initrd image: /boot/initramfs-4.19.12-7_rc1.zdyun.x86_64.img
Found linux image: /boot/vmlinuz-4.19.12-1.ctyun.x86_64
Found initrd image: /boot/initramfs-4.19.12-1.ctyun.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-ad8ef31f6ef940a0b65f1f597ad06c3b
Found initrd image: /boot/initramfs-0-rescue-ad8ef31f6ef940a0b65f1f597ad06c3b.img
done
You have new mail in /var/mail/root/

31. lenovo bios issue

Install win7:

BIOS版本M31K开头的激活代码 AmiSetupWriter.efi 0x802 0x1 (CSM改为允许)
BIOS版本M31K开头的激活代码 AmiSetupWriter.efi 0x802 0x1 (CSM改为允许)
如果M31K开头的BIOS,独显为RTX 16系列和20系列输入以下三条命令
AmiSetupWriter.efi 0x808 0x0 
AmiSetupWriter.efi 0x80b 0x2
AmiSetupWriter.efi 0x80c 0x2

32. detectgpu fixed code

via:

# 1.7 remove pciroot related items
reserveid=`lspci | grep -i vga | awk -F ':' {'print $1'}`
prefixreserveid="0000:"$reserveid
echo "/^${prefixreserveid}/"'!d' > /tmp/sedcmd.txt
sed -i -f /tmp/sedcmd.txt /tmp/pciid
sed -i -f /tmp/sedcmd.txt /tmp/devicedriver
usermod -a -G kvm,libvirt idv
python3 -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install pyqt5==5.15.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
python3 -c "from PyQt5.Qt import PYQT_VERSION_STR; print(PYQT_VERSION_STR)"

34. macos usage

via:

test@tests-iMac-Pro-2 ~ % sysctl -n hw.ncpu

14
test@tests-iMac-Pro-2 ~ % sysctl hw.memsize | awk '{print $1/1073741824}'

0
test@tests-iMac-Pro-2 ~ % sysctl hw.memsize
hw.memsize: 24775753728
test@tests-iMac-Pro-2 ~ % sysctl hw.memsize | awk '{print $2/1073741824}'

23.0742

35. fh vfio items

Change vfio hooks via:

vfio-startup.sh:

systemctl stop graphical.target
sleep 3
systemctl stop gdm
sleep 3 
systemctl stop gdm3
sleep 3
killall --user idv
sleep 5
echo 0x1ec8 0x9810 | tee -a /sys/bus/pci/drivers/vfio-pci/new_id 
sleep 2
echo "End of startup!"

vfio-teardown.sh:

sleep 3
echo 0x1ec8 0x9810 > /sys/bus/pci/drivers/vfio-pci/remove_id 
sleep 1
echo 1 > /sys/bus/pci/devices/0000\:06\:00.0/remove 
sleep 3
echo 1 > /sys/bus/pci/rescan 
sleep 3
systemctl start gdm

echo "End of teardown!"

36. cuttlefish building

Building deb:

git clone https://github.com/google/android-cuttlefish
cd android-cuttlefish
tools/buildutils/build_packages.sh 
$ ls *.deb
cuttlefish-base_1.0.0_arm64.deb         cuttlefish-orchestration_1.0.0_arm64.deb
cuttlefish-common_1.0.0_arm64.deb       cuttlefish-user_1.0.0_arm64.deb
cuttlefish-integration_1.0.0_arm64.deb

Install deb:

sudo dpkg -i ./cuttlefish-base_*_*64.deb || sudo apt-get install -f
sudo dpkg -i ./cuttlefish-user_*_*64.deb || sudo apt-get install -f
sudo usermod -aG kvm,cvdnetwork,render $USER
sudo reboot

getprop:

dumpsys SurfaceFlinger | grep GLES
 ------------RE GLES------------

37. secure boot off

via:

<loader readonly='yes' secure='no' type='pflash'>/usr/share/OVMF/OVMF_CODE.fd</loader>
    <nvram>/var/lib/libvirt/qemu/nvram/centos-4.19-3_VARS.fd</nvram>

38. ubuntuOK

via:

  HOME=$PWD ./bin/launch_cvd  -gpu_mode  drm_virgl  -enable_gpu_udmabuf -cpus 4 -memory_mb  8192

39. update gcc in debian unstable

via:

sudo apt install -y gcc-12
sudo apt install g++-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 20
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set /usr/bin/gcc
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
sudo update-alternatives --config gcc
sudo update-alternatives --config g++

40. build gfxstream on ubuntu2204

problems:

test@ubuntu2204:~/Code/qemu/build/deps/gfxstream$ meson setup -Ddefault_library=static --prefix "${PREFIX}" build/ 
The Meson build system
Version: 0.61.2
Source dir: /home/test/Code/qemu/build/deps/gfxstream
Build dir: /home/test/Code/qemu/build/deps/gfxstream/build
Build type: native build
Project name: gfxstream
Project version: 0.1.2
C compiler for the host machine: cc (gcc 11.4.0 "cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0")
C linker for the host machine: cc ld.bfd 2.38
C++ compiler for the host machine: c++ (gcc 11.4.0 "c++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0")
C++ linker for the host machine: c++ ld.bfd 2.38
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program python3 found: YES (/usr/bin/python3)
WARNING: Python files installed by Meson might not be found by python interpreter.
 This warning can be avoided by setting "python.platlibdir" option.
WARNING: Python files installed by Meson might not be found by python interpreter.
 This warning can be avoided by setting "python.purelibdir" option.
Found pkg-config: /usr/bin/pkg-config (0.29.2)
Run-time dependency aemu_base found: YES 0.1.2
Run-time dependency aemu_host_common found: YES 0.1.2
Run-time dependency aemu_logging found: YES 0.1.2
Run-time dependency aemu_snapshot found: YES 0.1.2
Found CMake: /usr/bin/cmake (3.22.1)
Run-time dependency dl found: NO (tried pkgconfig and cmake)

host/meson.build:78:2: ERROR: Dependency "dl" not found, tried pkgconfig and cmake

41. problem solving with policykit

building issue:

terminal 1: 
$ echo $??
23783
$ pkttyagent --process 23783
Authentication is needed to run `/usr/bin/python3' as the super user
Authenticating as: test
Password: 
==== AUTHENTICATION COMPLETE ===
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/bin/python3' as the super user
Authenticating as: test
Password: 
==== AUTHENTICATION COMPLETE ===

42. qemu-kvm-ev installation

Steps:

sudo sed -i.bak   -e 's|^mirrorlist=|#mirrorlist=|g'   -e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.ustc.edu.cn/centos-vault/centos|g'   /etc/yum.repos.d/CentOS-Base.repo
sudo yum update
sudo yum install -y virt-manager
sudo yum install -y centos-release-qemu-ev
sudo vi /etc/yum.repos.d/CentOS-QEMU-EV.repo
...
baseurl=http://mirrors.ustc.edu.cn/centos-vault/centos/$releasever/virt/$basearch/kvm-common/
...
sudo yum makecache
sudo yum install -y qemu-kvm-ev

elrepo:

$ cat /etc/yum.repos.d/elrepo.repo
...
[elrepo-kernel]
name=ELRepo.org Community Enterprise Linux Kernel Repository - el7
#baseurl=http://elrepo.org/linux/kernel/el7/$basearch/
baseurl=https://mirrors.ustc.edu.cn/elrepo/archive/kernel/el7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
protect=0
...
$ sudo yum makecache
$ sudo yum install -y kernel-lt kernel-lt-devel kernel-lt-headers 

Create building kernel docker instance:

$ sudo docker run -it buidrockykernel:latest /bin/bash
[root@6daba91116b7 /]# useradd -m mockbuild
[root@6daba91116b7 /]# su - mockbuild

In building container:

wget https://elrepo.reloumirrors.net/kernel/el9/SRPMS/kernel-lt-6.1.112-1.el9.elrepo.nosrc.rpm
rpm -Uvh kernel-lt-6.1.112-1.el9.elrepo.nosrc.rpm 
cd rpmbuild/
cd SPECS/
vim kernel-lt-6.1.spec 
cd ../SOURCES/
wget https://mirrors.ustc.edu.cn/kernel.org/linux/kernel/v6.x/linux-6.1.112.tar.xz
cd ../SPECS/
time rpmbuild -ba kernel-lt-6.1.spec 

44. lxd to incus

via:

lxd-to-incus --ignore-version-check

45. find installed gpus

via:

 lspci -nn | grep -i -E 'VGA|Display|3d' | grep -i -v "intel"

remove grub default items:

cp -r /etc/default/grub.d/ /root
vim *.cfg  # remove all of the unnecessary items

remove all of the dkms:

mv /usr/src /root
mkdir -p /root/varlibdkms
mv /var/lib/dkms/* /root/varlibdkms

/usr/lib/dkms/dkms_autoinstaller start 5.4.0-100-generic

47. oneline dkms

via:

ls /boot/initrd.img-* | cut -d- -f2- | \
    sudo xargs -n1 /usr/lib/dkms/dkms_autoinstaller start

48. pve lxc download

tips:

# pveam update
# pveam available
# pveam download local ubuntu-22.04-standard_22.04-1_amd64.tar.zst
downloading http://download.proxmox.com/images/system/ubuntu-22.04-standard_22.04-1_amd64.tar.zst to /var/lib/vz/template/cache/ubuntu-22.04-standard_22.04-1_amd64.tar.zst

template:

root@pve:/var/lib/vz/template/cache# scp ubuntu-22.04-standard_22.04-1_amd64.tar.zst dash@192.168.1.7:/media/big/

via:

  188  sudo lxc-create -n ubuntu2204 -t download -- --dist ubuntu --release jammy --arch amd64

50. disable apparmor

via:

root@debianonlyroot:~# cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-6.1.0-25-amd64 root=UUID=d96e2a44-3ce5-4a4a-899a-0e47f1ad3e50 ro quiet ipv6.disable=1 apparmor=0
root@debianonlyroot:~# cat /sys/module/apparmor/parameters/enabled
N
root@debianonlyroot:~# aa-status
apparmor module is loaded.
apparmor filesystem is not mounted.
root@debianonlyroot:~# 

disable steps:

$ sudo mkdir -p /etc/default/grub.d
$ echo 'GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT apparmor=0"' \
  | sudo tee /etc/default/grub.d/apparmor.cfg
$ sudo update-grub
$ sudo reboot

51. fedora arm64 group

steps:

lvextend -l +100%FREE /dev/mapper/fedora-root
xfs_growfs /dev/fedora/root 

52. view sync status

via:

watch -d grep -e Dirty: -e Writeback: /proc/meminfo

/images/20241024_181125_x.jpg

53. Installation issue(ubuntu16.04)

Change the virtio to scsci disk, for arm64 installation.

54. lxc startup issue

problem:

Failed to mount cgroup at /sys/fs/cgroup/systemd: Operation not permitted

solved via:

Added cgroup parameter to boot cmdline:     
systemd.unified_cgroup_hierarchy=0
update-grub2 && reboot

55. kylin lightdm

configuration via:

# cat /etc/lightdm/lightdm.conf
[LightDM]
minimum-vt=8
[SeatDefaults]
autologin-guest=false
autologin-user=test
autologin-user-timeout=0

56. ubuntu startup

solved via:

test@server:~$ cat /etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service
[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/systemd-networkd-wait-online
RemainAfterExit=yes
TimeoutStartSec=2sec

[Install]
WantedBy=network-online.target
=======

57. lxc sound issue

solved via:

/usr/bin/pactl load-module module-alsa-card device_id=1 ; /usr/bin/pactl load-module module-alsa-card device_id=0

58. fedora autoload kernel module

via:

# vim /etc/modules-load.d/vfio.conf
vfio-pci
vfio_iommu_type1
vfio_pci
# systemctl status systemd-modules-load.service

59. git diff

steps:

1. get the source code
git init
git add .
git commit -m 'initial'
git tag -a initial HEAD -m "initial"
2. make changes
git add 
git commit -m 'second'
git tag -a second HEAD -m "second"
3. show tags
git tag
4. make diffs
git diff -p tag1 tag2 > my.patch

InstallingNixOS

steps

Enable sshd:

$ passwd 
Change the password
$ ssh nixos@xxx.xxx.xx.xx
......

Change channel:

$ sudo -i
nix-channel --add https://mirrors.ustc.edu.cn/nix-channels/nixpkgs-unstable nixpkgs
nix-channel --add https://mirrors.ustc.edu.cn/nix-channels/nixos-24.05 nixos
nix-channel --list
nix-channel --update
nixos-rebuild --option substituters https://mirrors.ustc.edu.cn/nix-channels/store switch --upgrade 

parted:

parted /dev/sda  # 分区该设备
mklabel gpt  # 创建 GPT 表
mkpart ESP fat32 1MiB 256MiB  # 在 1 MiB - 256 MiB 的位置创建引导分区
p  # 打印当前分区表
set 1 esp on  # 将序号为 1 的分区标识为可启动
mkpart primary 256MiB -2GiB
unit s
mkpart primary linux-swap 996022272 100%
p

lsblk:

nvme0n1     259:0    0 476.9G  0 disk 
├─nvme0n1p1 259:4    0   255M  0 part 
├─nvme0n1p2 259:5    0 474.7G  0 part 
└─nvme0n1p3 259:6    0     2G  0 part

make filesystem:

mkfs.fat -F32 /dev/nvme0n1p1 
mkfs.btrfs -L nixos /dev/nvme0n1p2 
mkswap -L swap /dev/nvme0n1p3 

mount sub volumes:

mount /dev/nvme0n1p2 /mnt
btrfs subvolume create /mnt/root 
btrfs subvolume create /mnt/home
btrfs subvolume create /mnt/nix 
umount /mnt 
mount -o compress=zstd,subvol=root /dev/nvme0n1p2 /mnt
mkdir /mnt/{home,nix,boot}
mount -o compress=zstd,subvol=home /dev/nvme0n1p2 /mnt/home/
mount -o compress=zstd,noatime,subvol=nix  /dev/nvme0n1p2  /mnt/nix
mount /dev/nvme0n1p1 /mnt/boot
swapon /dev/nvme0n1p3
# nixos-generate-config --root /mnt
# cat  /mnt/etc/nixos/hardware-configuration.nix
# Do not modify this file!  It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations.  Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:

{
  imports =
    [ (modulesPath + "/installer/scan/not-detected.nix")
    ];

  boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usbhid" "usb_storage" "sd_mod" "sr_mod" "sdhci_pci" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-intel" ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/aeb74833-b6fc-444f-bdc0-3ab931e7356a";
      fsType = "btrfs";
      options = [ "subvol=root" "compress=zstd" ];
    };

  fileSystems."/home" =
    { device = "/dev/disk/by-uuid/aeb74833-b6fc-444f-bdc0-3ab931e7356a";
      fsType = "btrfs";
      options = [ "subvol=home" "compress=zstd"];
    };

  fileSystems."/nix" =
    { device = "/dev/disk/by-uuid/aeb74833-b6fc-444f-bdc0-3ab931e7356a";
      fsType = "btrfs";
      options = [ "subvol=nix" "compress=zstd" "noatime"];
    };

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/2D3A-7086";
      fsType = "vfat";
      options = [ "fmask=0022" "dmask=0022" ];
    };

  swapDevices =
    [ { device = "/dev/disk/by-uuid/745d2fd3-c12b-4d15-a242-9283cac98c5d"; }
    ];

  # Enables DHCP on each ethernet and wireless interface. In case of scripted networking
  # (the default) this is the recommended approach. When using systemd-networkd it's
  # still possible to use this option, but it's recommended to use it in conjunction
  # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
  networking.useDHCP = lib.mkDefault true;
  # networking.interfaces.enp2s0.useDHCP = lib.mkDefault true;
  # networking.interfaces.wlp3s0.useDHCP = lib.mkDefault true;

  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

[root@nixos:~]# cat /mnt/etc/nixos/configuration.nix
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page, on
# https://search.nixos.org/options and in the NixOS manual (`nixos-help`).

{ config, lib, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  # Use the systemd-boot EFI boot loader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  networking.hostName = "nixos"; # Define your hostname.
  # Pick only one of the below networking options.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.
  networking.networkmanager.enable = true;  # Easiest to use and most distros use this by default.

  # Set your time zone.
  # time.timeZone = "Europe/Amsterdam";
  time.timeZone = "Asia/Shanghai";

  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";

  # Select internationalisation properties.
  # i18n.defaultLocale = "en_US.UTF-8";
  i18n.defaultLocale = "en_US.UTF-8";
  # console = {
  #   font = "Lat2-Terminus16";
  #   keyMap = "us";
  #   useXkbConfig = true; # use xkb.options in tty.
  # };

  # Enable the X11 windowing system.
  services.xserver.enable = true;
  services.xserver.displayManager.sddm.enable = true;
  services.xserver.desktopManager.plasma5.enable = true;


  

  # Configure keymap in X11
  # services.xserver.xkb.layout = "us";
  # services.xserver.xkb.options = "eurosign:e,caps:escape";

  # Enable CUPS to print documents.
  # services.printing.enable = true;

  # Enable sound.
  hardware.pulseaudio.enable = true;
  # OR
  # services.pipewire = {
  #   enable = true;
  #   pulse.enable = true;
  # };

  # Enable touchpad support (enabled default in most desktopManager).
  # services.libinput.enable = true;

  # Define a user account. Don't forget to set a password with ‘passwd’.
  # users.users.alice = {
  #   isNormalUser = true;
  #   extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
  #   packages = with pkgs; [
  #     firefox
  #     tree
  #   ];
  # };

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
     vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
     wget
     alacritty
   ];

  sound.enable = true;
  #hardware.pulseaudio.enable = true;


  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  # programs.gnupg.agent = {
  #   enable = true;
  #   enableSSHSupport = true;
  # };

  # List services that you want to enable:

  # Enable the OpenSSH daemon.
  # services.openssh.enable = true;

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ ... ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  # networking.firewall.enable = false;

  # Copy the NixOS configuration file and link it from the resulting system
  # (/run/current-system/configuration.nix). This is useful in case you
  # accidentally delete configuration.nix.
  # system.copySystemConfiguration = true;

  # This option defines the first version of NixOS you have installed on this particular machine,
  # and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
  #
  # Most users should NEVER change this value after the initial install, for any reason,
  # even if you've upgraded your system to a new NixOS release.
  #
  # This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
  # so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how
  # to actually do that.
  #
  # This value being lower than the current NixOS release does NOT mean your system is
  # out of date, out of support, or vulnerable.
  #
  # Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
  # and migrated your data accordingly.
  #
  # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .

  nix.settings.substituters = [ 
    "https://mirrors.cernet.edu.cn/nix-channels/store"
  ];
  system.stateVersion = "24.11"; # Did you read the comment?

}
# nixos-install --option substituters https://mirrors.ustc.edu.cn/nix-channels/store


Re-Create the password:

nixos-enter  # 进入部署好的系统,类似 arch 的 chroot
passwd root  # 重置 root 密码
useradd -m -G wheel dash  # 添加普通用户,并加入 wheel 组
passwd dash  # 设置普通账户密码

Install awesome:

nix-env -qaP awesome
sudo nix-env -iA nixpkgs.awesome

Not the right way, the right way should be:

$ sudo vim /etc/nixos/configuration.nix
  services.xserver = {
    enable = true;

  
    displayManager = {
        sddm.enable = true;
        defaultSession = "none+awesome";
    };

    windowManager.awesome = {
      enable = true;
      luaModules = with pkgs.luaPackages; [
        luarocks # is the package manager for Lua modules
        luadbi-mysql # Database abstraction layer
      ];

    };
  };



sudo nixos-rebuild switch --option substituters https://mirrors.ustc.edu.cn/nix-channels/store

InstallCryptedGentoo

Partition:

livecd ~ # lsblk
NAME  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0   7:0    0 479.7M  1 loop /mnt/livecd
sr0    11:0    1 527.4M  0 rom  /mnt/cdrom
vda   252:0    0    80G  0 disk 
zram0 253:0    0     0B  0 disk 
livecd ~ # parted /dev/vda
GNU Parted 3.6
Using /dev/vda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
(parted) unit MiB                                                         
(parted) mkpart primary 2 514
(parted) mkpart primary 515 -1                                            
(parted) name 1 boot                                                      
(parted) name 2 luks                                                      
(parted) set 1 boot on                                                    
(parted) q                                                                
Information: You may need to update /etc/fstab.

Setup crypts:

livecd ~ # cryptsetup luksFormat  /dev/vda2

WARNING!
========
This will overwrite data on /dev/vda2 irrevocably.

Are you sure? (Type 'yes' in capital letters): YES
Enter passphrase for /dev/vda2: 
Verify passphrase: 
livecd ~ # cryptsetup open /dev/vda2 ct0
Enter passphrase for /dev/vda2: 

Mount to specified position:

mkfs.btrfs /dev/mapper/ct0
mkfs.vfat -F32 /dev/vda1
mount /dev/mapper/ct0 /mnt/gentoo

Using btrfs’s subvolume function:

btrfs subvolume create /mnt/gentoo/subvol-root
btrfs subvolume create /mnt/gentoo/subvol-home
btrfs subvolume create /mnt/gentoo/subvol-snapshots
btrfs subvolume set-default /mnt/gentoo/subvol-root
umount /mnt/gentoo
mount /dev/mapper/ct0 /mnt/gentoo

prepare chroot:

cd /mnt/gentoo
wget ......stage3
tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner

specify jobs for building:

# nano /etc/portage/make.conf
MAKEOPTS="-j17"

select mirror:

mirrorselect -i -o >>/mnt/gentoo/etc/portage/make.conf

Setup ebuild repository sync address:

# mkdir etc/portage/repos.conf
# cp usr/share/portage/config/repos.conf etc/portage/repos.conf/gentoo.conf
# cat etc/portage/repos.conf/gentoo.conf | grep uri
sync-uri = rsync://rsync.mirrors.ustc.edu.cn/gentoo-portage
cp -L /etc/resolv.conf etc/

chroot-in:

livecd /mnt/gentoo # mount --types proc /proc /mnt/gentoo/proc
livecd /mnt/gentoo # mount --rbind /sys /mnt/gentoo/sys
livecd /mnt/gentoo # mount --rbind /dev /mnt/gentoo/dev
####  then
chroot /mnt/gentoo
. /etc/profile
PS1=(chroot)$PS1

Mount vda1 for kernel/bootloader installation:

mount /dev/vda1 /boot

Install gentoo ebuild repository:

emerge-webrsync
emerge --sync 

Install and set editor:

emerge -vj app-editors/vim
eselect editor set 2
. /etc/profile
PS1=(chroot)$PS1

update @world:

eselect profile set 21
USE="X initramfs cjk cups crypt udev alsa elogind zsh-completion bash-completion -consolekit"
emerge --ask --verbose --update --deep --changed-use @world

Select the locale and timezone:

echo "Asia/Shanghai" > /etc/timezone
emerge --config sys-libs/timezone-data
vim /etc/locale.gen
locale-gen 
eselect locale set 6
env-update && source /etc/profile && export PS1="(chroot) $PS1"

Install firmware:

mkdir -p /etc/portage/package.license
echo 'sys-kernel/linux-firmware linux-fw-redistributable no-source-code' >/etc/portage/package.license/linux-firmware
echo 'sys-kernel/installkernel dracut' >/etc/portage/package.use/installkernel
emerge --ask sys-kernel/gentoo-sources
emerge --ask sys-kernel/linux-firmware
emerge --ask sys-apps/pciutils
emerge --ask sys-kernel/genkernel

Set kernel:

(chroot) livecd / # readlink -v /usr/src/linux
readlink: /usr/src/linux: No such file or directory
(chroot) livecd / # eselect kernel list
Available kernel symlink targets:
  [1]   linux-6.6.30-gentoo
(chroot) livecd / # eselect kernel set 1
(chroot) livecd / # readlink -v /usr/src/linux
linux-6.6.30-gentoo

Build kernel:

cd /usr/src/linux
 make menuconfig
 make -j17
 make modules_install && make install
 genkernel --kernel-config=/usr/src/linux/.config initramfs
 blkid /dev/vda1>>/etc/fstab
 blkid /dev/mapper/ct0>>/etc/fstab
 vim /etc/fstab 
#/dev/vda1: UUID="3D3E-221D" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="boot" PARTUUID="e0e7d44b-d78f-4c27-808a-c859ce8ead64"
UUID="3D3E-221D"	/boot     vfat    rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 2
#/dev/mapper/ct0: UUID="5f574106-322e-4f9f-8efd-c3615fcb237a" UUID_SUB="0e96210f-49ac-4355-9237-dab1fb6eae93" BLOCK_SIZE="4096" TYPE="btrfs"
# rw,relatime,space_cache=v2,subvolid=256,subvol=/subvol-root
UUID="5f574106-322e-4f9f-8efd-c3615fcb237a"	/         btrfs   defaults,noatime,ssd,discard,subvolid=256,subvol=/subvol_root 0 1

Install system packages:

   66  emerge --ask sys-fs/cryptsetup
   67  emerge --ask sys-process/cronie
   68  emerge --ask app-admin/sysklogd
   69  emerge --ask sysfs/btrfs-progs
   70  emerge --ask sys-fs/btrfs-progs
   71  emerge --ask net-misc/dhcpcd
   72  emerge -av app-admin/sysklogd sys-fs/cryptsetup
   73  rc-update add sysklogd default
   74  rc-update add dhcpcd default
   76  echo GRUB_PLATFORMS="efi-64" >> /etc/portage/make.conf
   77  emerge -av sys-boot/grub:2
   79  mkdir /boot/efi/
   80  ls /dev/disk/by-uuid/
   81  ls /dev/disk/by-uuid/ -l -h
   82  cat /etc/fstab 
   83  vim /etc/default/grub 
   84  vim /etc/default/grub 
   85  mount -a
   86  grub-install --target=x86_64-efi --boot-directory=/boot --efi-directory=/boot/efi/ --bootloader-id=Gentoo --debug
   87  grub-mkconfig -o /boot/grub/grub.cfg
   89  ls /boot/grub/
   90  ls /boot/grub/grub.cfg