环境配置说明
适用硬件:Intel NUC(NUC6CAYH) 配 Mediatek MT7922(RZ616) 无线网卡
编译系统:Ubuntu-20.04.5 LTS For WSL2
1 2 3 4 5 6 7 8 9 10 11 12 CPU : Intel® Celeron® Processor J3455 (2M Cache, up to 2.30 GHz, 4C4T) RAM : Samsung 4G x2 DDR3L-1866 1.35V SO-DIMM ROM : Crucial BX200 240GB ETH : Realtek r8169 5 G : Mediatek MT7922(RZ616) sudo apt updatesudo apt install build-essential clang flex g++ gawk gcc-multilib gettext \git libncurses5-dev libssl-dev python3-distutils rsync unzip zlib1g-dev
获取编译源码
注意:不要使用root用户编译,最好使用梯子来加速源码的下载速度
编译完成后把openwrt/bin/targets/x86/64/openwrt-x86-64-generic-ext4-combined-efi.img.gz解压后的img文件刷入U盘启动即可
可选lean版魔改源码替换官方源码:https://github.com/coolsnowwolf/lede
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 mkdir openwrt && cd openwrt/git clone https://github.com/openwrt/openwrt.git --depth=1 -b v22.03.2 ./ git pull ./scripts/feeds update -a ./scripts/feeds install -a make defconfig make menuconfig make kernel_menuconfig make download -j8 V=s make -j1 V=s make clean make dirclean make distclean
添加新的设备 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 # 在 openwrt/target/linux/x86/image/64.mk 文件后面添加如下: define Device/nuc6cayh $(call Device/generic) DEVICE_VENDOR := Intel DEVICE_MODEL := NUC6CAYH DEVICE_PACKAGES += \ kmod-fuse kmod-fs-ext4 kmod-fs-squashfs kmod-usb-storage-uas r8169-firmware kmod-kvm-intel kmod-tun \ kmod-usb-core kmod-usb-ehci kmod-usb-ohci kmod-usb-uhci kmod-usb-xhci-hcd kmod-usb-net-rtl8152 \ usb-modeswitch kmod-usb-serial kmod-usb-serial-option kmod-usb-serial-wwan kmod-usb-net-qmi-wwan \ kmod-usb-net kmod-usb-net-cdc-ether kmod-usb-net-cdc-mbim kmod-usb-net-cdc-ncm kmod-usb-net-rndis \ kmod-mt76-core kmod-mt76-connac kmod-mt7921-common kmod-mt7921e wpad-openssl wireless-tools \ luci luci-theme-material luci-i18n-base-zh-cn luci-i18n-opkg-zh-cn luci-i18n-firewall-zh-cn \ luci-app-samba4 luci-i18n-samba4-zh-cn usbutils pciutils htop smstools3 iconv curl parted endef TARGET_DEVICES += nuc6cayh # 添加完记得 `rm .config* && rm -rf tmp/` 清理缓存,然后可在如下位置选择添加的设备: Target System (x86) ---> Subtarget (x86_64) ---> Target Profile (Intel NUC6CAYH) ---> # 如果需要编译所有内核模块可选择如下,如不生效记得如上清理缓存 Global build settings ---> Select all kernel module packages by default
驱动无线网卡
MT7922与MT7921共用同一驱动,但驱动默认不包含MT7922的固件,需要自己拷贝到指定路径
7921只有E、U、S三种版本,E是PCIE的NGFF接口,U是USB的,S是SDIO集成到主板的,其他没别的分别
/lib/firmware/mediatek/WIFI_RAM_CODE_MT7922_1.bin | /lib/firmware/mediatek/WIFI_MT7922_patch_mcu_1_1_hdr.bin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 opkg install kmod-mt76-core kmod-mt76-connac kmod-mt7921-common kmod-mt7921e wpad-openssl wireless-tools define KernelPackage/mt7921e/install $(INSTALL_DIR) $(1)/lib/firmware/mediatek cp \ $(PKG_BUILD_DIR)/firmware/WIFI_MT7961_patch_mcu_1_2_hdr.bin \ $(PKG_BUILD_DIR)/firmware/WIFI_RAM_CODE_MT7961_1.bin \ + $(PKG_BUILD_DIR)/firmware/WIFI_MT7922_patch_mcu_1_1_hdr.bin \ + $(PKG_BUILD_DIR)/firmware/WIFI_RAM_CODE_MT7922_1.bin \ $(1)/lib/firmware/mediatek endef
自动配置无线
全局生效:openwrt/files
文件夹在构建的时候,会把files文件夹里的文件编译到固件的根目录,所有架构都会生效。
局部有效:openwrt/target/linux/x86/base-files/
文件夹在构建的时候,会把base-files文件夹里的文件编译到固件的根目录,仅x86平台有效。
在 openwrt/target/linux/x86/base-files/etc/config/
中新建无线配置文件wireless来提供无线接入可不插网线来初始配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 config wifi-device 'radio0' option type 'mac80211' option path 'pci0000:00/0000:00:13.1/0000:02:00.0' option channel '36' option band '5g' option htmode 'HE80' option cell_density '0' config wifi-iface 'default_radio0' option device 'radio0' option mode 'ap' option encryption 'none' option ssid 'Openwrt' option network 'lan'
短信自动转发 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 opkg install smstools3 iconv curl devices = GSM1 incoming = /var/spool/sms/incoming outgoing = /var/spool/sms/outgoing checked = /var/spool/sms/checked failed = /var/spool/sms/failed sent = /var/spool/sms/sent receive_before_send = no autosplit = 3 logfile = 1 loglevel = 5 [GSM1] init = AT+CPMS="ME" ,"ME" ,"ME" device = /dev/ttyUSB3 incoming = yes baudrate = 115200 check_network = no if [ "$1 " == "RECEIVED" ]; then FROM=$(grep "From:" $2 ) TEXT=$(sed -e '1,/^$/ d' < "$2 " | iconv -f UNICODEBIG -t UTF-8) curl -d "token=531c964f2fbe4879be2f1a4bba2695d3&title=$FROM &content=$TEXT " -X POST http://www.pushplus.plus/send fi echo $(sed -e '1,/^$/ d' < "/var/spool/sms/incoming/GSM1.PCMJai" | iconv -f UNICODEBIG -t UTF-8)
核显驱动报错
[ 64.622466] i915 0000:00:02.0: [drm] Failed to load DMC firmware i915/bxt_dmc_ver1_07.bin. Disabling runtime power management.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 CONFIG_64BIT=y 64-bit kernel CONFIG_DRM=y Device Drivers -> Graphics support -> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) CONFIG_DRM_I915=y Device Drivers -> Graphics support -> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) -> Intel 8xx/9xx/G3x/G4x/HD Graphics CONFIG_DRM_I915_GVT=y Device Drivers -> Graphics support -> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) -> Intel 8xx/9xx/G3x/G4x/HD Graphics -> Enable Intel GVT-g graphics virtualization host support CONFIG_DUMMY_CONSOLE=y make kernel_menuconfig
开启虚拟
在内核的字符配置界面 make kernel_menuconfig
根据下面参数来开启内核对KVM的相关支持
下面参数中符号 >
代表上下级菜单,符号 -
表示同级菜单下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 KVM :Virtualization > Kernel-based Virtual Machine (KVM) support Intel :Virtualization > KVM for Intel (and compatible) processors support AMD :Virtualization > KVM for AMD processors support PCI直通 :Device Drivers > PCI support > PCI Stub driver 能够将pci设备跟目前绑定的驱动分离,暂时由PCI Stub driver接管,最后交给虚拟机。 CONFIG_VIRTIO Device Drivers -> Virtio drivers CONFIG_VIRTIO_PCI Device Drivers -> Virtio drivers -> PCI driver for virtio devices CONFIG_VIRTIO_PCI_LEGACY Device Drivers -> Virtio drivers -> PCI driver for virtio devices -- Support for legacy virtio draft 0.9.X and older devices CONFIG_VIRTIO_BALLOON Device Drivers -> Virtio drivers -> Virtio balloon driver CONFIG_VIRTIO_INPUT Device Drivers -> Virtio drivers -> Virtio input driver CONFIG_VIRTIO_BLK Device Drivers -> Block devices -> Virtio block driver CONFIG_VIRTIO_NET Device Drivers -> Network device support -> Virtio network driver CONFIG_VIRTIO_CONSOLE Device Drivers -> Character devices -> Virtio console CONFIG_VIRTIO_VSOCKETS_COMMON Networking support > Networking options -> Virtual Socket protocol CONFIG_VIRTIO_VSOCKETS Networking support -> Networking options -> Virtual Socket protocol -> virtio transport for Virtual Sockets CONFIG_SCSI_VIRTIO Device Drivers -> SCSI device support -> SCSI low-level drivers -> virtio-scsi support CONFIG_HW_RANDOM_VIRTIO Device Drivers -> Character devices -> Hardware Random Number Generator Core support -> VirtIO Random Number Generator support CONFIG_DRM_VIRTIO_GPU Device Drivers -> Graphics support -> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) -> Virtio GPU driver CONFIG_VIRTIO_FS File systems -> FUSE (Filesystem in Userspace) support -> Virtio Filesystem CONFIG_CRYPTO_DEV_VIRTIO Cryptographic API > Hardware crypto devices > Virtio crypto driver CONFIG_NET_9P_VIRTIO Networking support > Plan 9 Resource Sharing Support > 9P Virtio Transport CONFIG_NET_9P_RDMA Device Drivers > InfiniBand support || Networking support > Plan 9 Resource Sharing Support > 9P Virtio Transport > 9P RDMA Transport CONFIG_CAIF Networking support > CAIF support CONFIG_CAIF_VIRTIO Device Drivers > Network device support > CAIF transport drivers -> CAIF virtio transport driver CONFIG_VHOST_NET Device Drivers > VHOST drivers -> Host kernel accelerator for virtio net CONFIG_VHOST_VSOCK Device Drivers -> VHOST drivers -> vhost virtio-vsock driver CONFIG_VFIO Device Drivers -> VFIO Non-Privileged userspace driver framework VIRTIO_MMIO Device Drivers > Virtio drivers > Platform bus driver for memory mapped virtio devices CONFIG_VFIO_PCI Device Drivers > VFIO Non-Privileged Userspace driver framework > VFIO support for PCI devices CONFIG_VFIO_MDEV Device Drivers > VFIO Non-Privileged Userspace driver framework > Mediated device driver framework CONFIG_VFIO_MDEV_DEVICE Device Drivers > VFIO Non-Privileged Userspace driver framework > Mediated device driver framework > VFIO driver for Mediated devices CONFIG_VFIO_IOMMU_TYPE1 Device Drivers > IOMMU Hardware Support - VFIO Non-Privileged Userspace driver framework CONFIG_ACPI Power management and ACPI options -> ACPI (Advanced Configuration and Power Interface) Support CONFIG_INTEL_IOMMU Device Drivers > IOMMU Hardware Support > Support for Intel IOMMU using DMA Remapping Devices
QEMU运行其他系统
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 opkg update opkg install kmod-kvm-amd kmod-kvm-intel kmod-kvm-x86 kmod-tun qemu-arm-softmmu \ qemu-bridge-helper qemu-firmware-efi qemu-firmware-pxe qemu-firmware-seabios \ qemu-firmware-seavgabios qemu-ga qemu-img qemu-keymaps qemu-nbd qemu-x86_64-softmmu Packages in utilities---virtualization category qemu-arm-softmmu qemu-bridge-helper qemu-firmware-efi qemu-firmware-pxe qemu-firmware-seabios qemu-firmware-seavgabios qemu-ga qemu-img qemu-keymaps qemu-nbd qemu-x86_64-softmmu virtio-console-helper