cmake_note

Note of cmake quick start

1.Install cmake

1
sudo pacman -S cmake

2.Write your cpp program

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

int main()
{
std::cout << "Hello cpp!" << std::endl;

int a = 10;
int b = a * 2;
std::cout << "b is " << b << std::endl;

return 0;
}

3.Write CMakeLists.txt in project directory

1
2
3
4
5
6
7
8
cmake_minimum_required(VERSION 3.15)

# set the project name
project(Maintest)

# add the executable
add_executable(Maintest main.cpp)

4.Make directory build and into it to init cmake, then build the project.

1
2
3
4
mkdir build
cd build
cmake ..
cmake --build .

Now, you can see all the build files in build directory, you can run program like this

1
./Maintest

hexo_settings

文章的存放和静态资源的处理

静态资源的处理

对于我这种习惯于将文档引用的静态资源存放在一个单独的文件中的人, 则需要使用更组织化的方式来管理资源

需要在_config.yml启用配置

1
2
3
4
post_asset_folder: true
marked:
prependRoot: true
postAsset: true

skip static sources render

1
skip_render: /static/*/**
  • ‘*’: Any file or directory in parent folder.
  • ‘**’: All the file and directory in parent folder and its child folder.
1
```

archlinux安装配置KVM虚拟机

archlinux安装配置KVM虚拟机

一、检查硬件支持

  1. 虚拟化支持检测
    执行命令:
1
2
grep -E "(vmx|svm)" --color=always /proc/cpuinfo  # 直接检测CPU虚拟化标志[2](@ref)
lsmod | grep kvm # 验证内核模块是否加载[2](@ref)
  1. 若 lsmod 无输出,需手动加载模块

(二选一)

1
2
sudo modprobe kvm_intel  # Intel CPU
sudo modprobe kvm_amd # AMD CPU


二、安装必要软件包

  • 安装核心组件
    1
    sudo pacman -S qemu-desktop libvirt virt-manager virt-viewer dmidecode ebtables iptables-nft dnsmasq bridge-utils openbsd-netcat ovmf

三、配置服务与用户权限

  1. 配置 libvirt 规则
    1
    sudo nano /etc/polkit-1/rules.d/50-libvirt.rules
    内容:
1
2
3
4
5
6
7
/* 允许 kvm 用户组成员无需认证即可管理 libvirt 守护进程 */
polkit.addRule(function(action, subject) {
if (action.id == "org.libvirt.unix.manage" &&
subject.isInGroup("kvm")) {
return polkit.Result.YES;
}
});
  1. 将用户加入必要用户组

    1
    sudo usermod -aG libvirt,kvm $(whoami)

    完成后需 重新登录(或重启) 或执行 newgrp libvirt 使配置生效

  2. 配置 Libvirt 权限(可选)
    编辑 /etc/libvirt/libvirtd.conf ,确保以下配置:

    1
    2
    unix_sock_group = "libvirt"
    unix_sock_rw_perms = "0770"
  3. 启动并启用 libvirtd 和 virtlogd 服务,不要开机自启 dnsmasq 服务,因为 libvirt 在创建和开启虚拟机时自动实例化一个 dnsmasq 进程

    1
    sudo systemctl enable --now libvirtd virtlogd

四、创建虚拟机

  1. 使用图形化工具(推荐)
    启动 virt-manager
    1
    virt-manager
    • 点击“新建虚拟机”,选择 ISO 镜像或网络安装源。
    • 配置 CPU、内存、磁盘大小等参数。

五、管理虚拟机

常用命令

1
2
3
4
virsh list --all      # 查看所有虚拟机
virsh start arch-vm # 启动虚拟机
virsh shutdown arch-vm # 正常关机
virsh destroy arch-vm # 强制关闭


六、常见问题

  1. 网络桥接配置失败
    确保 bridge-utils 已安装,并配置 /etc/netctlsystemd-networkd 的网络桥接。

  2. 权限不足错误
    检查用户是否在 libvirtkvm 组,并重启服务。


通过以上步骤,您可以在 Arch Linux 上顺利安装和管理 KVM 虚拟机。如需更详细的网络配置或性能优化,可参考 Arch Wiki 的 KVM 专题文档。