Linux 内核中“.type”的含义

本文详细介绍了Linux系统中type命令的用途、参数与使用示例,帮助用户理解命令的类型(如alias、keyword、function等),并指导如何根据不同类型获取相应帮助,包括使用help命令与man或info查看外部命令的帮助文档。

用途说明

type命令用来显示指定命令的类型。一个命令的类型可以是如下之一

  • alias 别名
  • keyword 关键字,Shell保留字
  • function 函数,Shell函数
  • builtin 内建命令,Shell内建命令
  • file 文件,磁盘文件,外部命令
  • unfound 没有找到

它是Linux系统的一种自省机制,知道了是那种类型,我们就可以针对性的获取帮助。比如内建命令可以用help命令来获取帮助,外部命令用man或者info来获取帮助。

常用参数

type命令的基本使用方式就是直接跟上命令名字。

type -a可以显示所有可能的类型,比如有些命令如pwd是shell内建命令,也可以是外部命令。

type -p只返回外部命令的信息,相当于which命令。

type -f只返回shell函数的信息。

type -t 只返回指定类型的信息。

使用示例

示例一 type自己是什么类型的命令

[root@new55 ~]# type -a type
type is a shell builtin
[root@new55 ~]# help type
type: type [-afptP] name [name ...]
    For each NAME, indicate how it would be interpreted if used as a
    command name.
   
    If the -t option is used, `type' outputs a single word which is one of
    `alias', `keyword', `function', `builtin', `file' or `', if NAME is an
    alias, shell reserved word, shell function, shell builtin, disk file,
    or unfound, respectively.
   
    If the -p flag is used, `type' either returns the name of the disk
    file that would be executed, or nothing if `type -t NAME' would not
    return `file'.
   
    If the -a flag is used, `type' displays all of the places that contain
    an executable named `file'.  This includes aliases, builtins, and
    functions, if and only if the -p flag is not also used.
   
    The -f flag suppresses shell function lookup.
   
    The -P flag forces a PATH search for each NAME, even if it is an alias,
    builtin, or function, and returns the name of the disk file that would
    be executed.
typeset: typeset [-afFirtx] [-p] name[=value] ...
    Obsolete.  See `declare'.
[root@new55 ~]#

示例二 常见命令的类型

[root@new55 ~]# type -a cd
cd is a shell builtin
[root@new55 ~]# type -a pwd
pwd is a shell builtin
pwd is /bin/pwd
[root@new55 ~]# type -a time
time is a shell keyword
time is /usr/bin/time
[root@new55 ~]# type -a date
date is /bin/date
[root@new55 ~]# type -a which
which is aliased to `alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
which is /usr/bin/which
[root@new55 ~]# type -a whereis
whereis is /usr/bin/whereis
[root@new55 ~]# type -a whatis
whatis is /usr/bin/whatis
[root@new55 ~]# type -a function
function is a shell keyword
[root@new55 ~]# type -a ls
ls is aliased to `ls --color=tty'
ls is /bin/ls
[root@new55 ~]# type -a ll
ll is aliased to `ls -l --color=tty'
[root@new55 ~]# type -a echo
echo is a shell builtin
echo is /bin/echo
[root@new55 ~]# type -a bulitin
-bash: type: bulitin: not found
[root@new55 ~]# type -a builtin
builtin is a shell builtin
[root@new55 ~]# type -a keyword
-bash: type: keyword: not found
[root@new55 ~]# type -a command
command is a shell builtin
[root@new55 ~]# type -a alias
alias is a shell builtin
[root@new55 ~]# type -a grep
grep is /bin/grep  

本文链接:http://codingstandards.iteye.com/blog/831504 

<think>我们正在为第10代和第14代Intel CPU编译一个集成了initramfs的单一EFI内核文件(onefilelinux.efi)。需要特别注意: 1. 内核配置需启用EFI stub支持(CONFIG_EFI_STUB=y)以便直接由UEFI加载 2. 为支持10代和14代CPU的集成显卡,需确保i915驱动和相关固件正确包含 3. 使用CONFIG_CMDLINE和CONFIG_INITRAMFS_SOURCE构建内置命令行和initramfs 步骤: 1. 准备内核源码 2. 配置内核(特别关注EFI、CPU微码、显卡驱动等) 3. 构建内核并生成bzImage 4. 将bzImage转换为EFI可执行文件(onefilelinux.efi) 注意:引用[2]提到EFI stub支持可以直接由EFI固件加载内核,但需要在内核配置中设置命令行(CONFIG_CMDLINE)和initramfs(CONFIG_INITRAMFS_SOURCE)。 详细步骤:</think>### 编译适用于第10代和第14代CPU的Linux内核并生成onefilelinux.efi文件 以下是详细步骤,特别注意Intel第10代(Comet Lake)和第14代(Raptor Lake Refresh)CPU的硬件支持: --- #### 1. **准备编译环境** ```bash sudo apt update sudo apt install git build-essential flex bison libssl-dev libelf-dev ``` --- #### 2. **获取内核源码** ```bash git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git cd linux # 切换到支持14代CPU的6.5+内核分支 git checkout v6.5 ``` --- #### 3. **内核配置(关键步骤)** ```bash make menuconfig ``` 需启用的核心选项: | 配置项 | 路径 | 说明 | |--------|------|------| | **CONFIG_EFI_STUB** | Processor type and features → EFI stub support | 启用EFI直接启动[^2] | | **CONFIG_X86_INTEL_LPSS** | Device Drivers → MFD Core → Intel Low Power Subsystem | 第10/14代芯片组必需 | | **CONFIG_DRM_I915** | Device Drivers → Graphics support → Intel GPU | 集成显卡驱动 | | **CONFIG_INTEL_MEI** | Device Drivers → Misc devices → Intel MEI | 管理引擎接口 | | **CONFIG_SND_HDA_CODEC_HDMI** | Device Drivers → Sound → HD Audio → HDMI/DisplayPort | HDMI音频支持 | | **CONFIG_MICROCODE_INTEL** | Processor type and features → CPU microcode loading | CPU微码更新 | 针对第14代CPU额外启用: ```bash # 启用Xe显卡实验性支持 echo "CONFIG_DRM_XE_KMS=y" >> .config echo "CONFIG_DRM_XE_GUC=y" >> .config ``` --- #### 4. **集成initramfs到内核** 创建initramfs目录结构: ```bash mkdir initramfs cd initramfs mkdir -p bin dev proc sys cp /bin/busybox bin/ # 需提前安装busybox ``` 创建初始化脚本`init`: ```bash #!/bin/sh mount -t proc proc /proc mount -t sysfs sysfs /sys exec /bin/sh ``` ```bash chmod +x init find . | cpio -o -H newc | gzip > ../initramfs.cpio.gz ``` 配置内核包含initramfs: ```bash # 在.config文件中添加 CONFIG_INITRAMFS_SOURCE="initramfs.cpio.gz" CONFIG_INITRAMFS_COMPRESSION_GZIP=y ``` --- #### 5. **编译内核** ```bash make -j$(nproc) bzImage ``` 编译完成后生成`arch/x86/boot/bzImage` --- #### 6. **生成onefilelinux.efi** ```bash # 转换为EFI可执行文件 objcopy \ --add-section .osrel="/usr/lib/os-release" \ --add-section .cmdline="cmdline.txt" \ --add-section .linux="arch/x86/boot/bzImage" \ --add-section .initrd="initramfs.cpio.gz" \ /usr/lib/systemd/boot/efi/linuxx64.efi.stub \ onefilelinux.efi ``` > **注意**:`cmdline.txt`内容示例: > ```text > root=/dev/ram0 rw init=/init console=ttyS0 i915.force_probe=4690,4680 > ``` > - `i915.force_probe=4690`:强制加载第10代核显驱动 > - `i915.force_probe=4680`:强制加载第14代核显驱动 --- #### 7. **验证EFI文件** ```bash file onefilelinux.efi # 应显示:PE32+ executable (EFI application) x86-64 ``` --- #### 故障排除 1. **显卡驱动失败**: ```bash # 在内核参数添加 i915.enable_guc=2 drm.debug=0x1e ``` 2. **微码加载问题**: ```bash sudo apt install intel-microcode cp /lib/firmware/intel-ucode/* arch/x86/boot/microcode/ ``` 3. **EFI启动失败**: - 确保BIOS中关闭Secure Boot - 使用`efibootmgr`创建启动项: ```bash efibootmgr -c -d /dev/sda -p 1 -L "OneFileLinux" -l "\EFI\onefilelinux.efi" ``` > **硬件兼容性参考**: > - 第10代CPU:设备ID `0x9BC5` (UHD 630) > - 第14代CPU:设备ID `0x4680` (UHD 770) [^1]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值