在路上 ……

Linux系统运维与架构

前言

因为要给家里老人装台电脑,出于简单省事又便宜的考虑,咸鱼上收了个Intel NUC7i5BNK,CPU是Intel 7代i5-7260U,集成的显卡是Iris 620,可intel官网只给出了win10的驱动,看来是彻底不支持在NUC上装win7了啊。可家里老人能会用win7已经不容易了,再让他们去学习适应win10,实在是太辛苦,于是就有了这篇折腾的记录。

一,准备工作

下载需要的文件及驱动

  1. windows 7 SP1 原版ISO,cn_windows_7_ultimate_with_sp1_x64_dvd_u_677408.iso
  2. 两个win7的补丁程序,一个是 2990941,用于给win7添加NVME驱动。一个是 3087873,修复打了上面补丁后可能出现的蓝屏情况。
    BTW: 现在微软居然不直接提供下载了,还要把下载地址发到邮箱再去下载,下载是两个exe文件,执行后会解压出来是msu格式的补丁文件,留待使用。
  3. Intel NMVE驱动,因为我买的是Intel 760P m2接口NVME ssd,所以需要准备相应的驱动,如果你们用其他品牌的NVME ssd,也需要下载相应的驱动。
    官方网址:https://downloadcenter.intel.com/zh-cn/download/27518/-ssd-NVMe-Microsoft-windows-?product=129831,下载地址:https://downloadmirror.intel.com/27518/eng/Client-x64.zip
  4. Intel 200系列芯片组 USB3.0驱动,官方网址:https://downloadcenter.intel.com/download/22824/Intel-USB-3-0-eXtensible-Host-Controller-Driver-for-Intel-8-9-100-Series-and-Intel-C220-C610-Chipset-Family,下载地址:https://downloadmirror.intel.com/22824/eng/Intel(R)_USB_3.0_eXtensible_Host_Controller_Driver_5.0.4.43_v2.zip

准备工作目录及文件

  1. 找一个剩余空间至少15G的硬盘分区,推荐使用ssd,否则后面mount镜像文件时会很慢,这里我以D盘为例,新建工作目录w7sp2
  2. 在D:\w7sp2目录下新建 mount,driver,hotfix 三个目录
  3. 将上面第二步下载的两个补丁文件放入hotfix目录
  4. 将上面第三第四步下载的驱动,解压后放入driver目录
  5. 使用UltraISO打开windows 7 原版ISO,进入sources目录,将boot.wim和install.wim两个文件提取到D:\w7sp2目录下

二,正式开始封装

打开CMD命令行窗口,切换到D:w7sp2工作目录下

D:
cd D:\w7sp2

给win7boot程序添加NVME驱动和USB3驱动

dism /mount-wim /wimfile:D:\w7sp2\boot.wim /index:2 /mountdir:D:\W7SP2\mount
dism /image:D:\w7sp2\mount /add-driver /driver:D:\w7sp2\driver /Recurse
dism /unmount-wim /mountdir:D:\w7sp2\mount /commit

给win7安装程序添加补丁及驱动

dism /mount-wim /wimfile:D:\w7sp2\install.wim /index:4 /mountdir:D:\W7SP2\mount
dism /image:D:\w7sp2\mount /add-package /packagepath:D:\w7sp2\hotfix
dism /image:D:\w7sp2\mount /add-driver /driver:D:\w7sp2\driver /Recurse
dism /unmount-wim /mountdir:D:\w7sp2\mount /commit

将w7sp2目录下封装好的boot.wim和install.wim通过UltraISO添加回win7原版 ISO
将ISO另存为一个新文件,别直接覆盖原版ISO

三,制作U盘,安装系统

这时就可以用UltraISO打开新生成的ISO,写入硬盘镜像功能制作win7安装U盘了
安装过程就和普通的安装无任何区别了。

四,安装后

安装后,大部分驱动都可以用驱动精灵之类的搞定,唯独Intel核心显卡驱动搞不定,使用for win10的驱动会提示不支持的CPU。
经过搜索,终于找到了安装方法:
先在系统-设备管理器-标准VGA显示-属性-详细信息-硬件ID,查看当前设备的信息,记录下来,类似于“PCIVEN_8086&DEV_5926”这样的,重要的是DEV后面的这四位数字。
下载intel核心显卡驱动zip包版本,下载地址:https://downloadmirror.intel.com/26836/eng/win64_154519.4678.zip,解压后,在Graphics目录下,找到igdlh64.inf文件,用记事本打开,查找刚才记下的DEV后的数字5926,找到这样一行“%iKBLULTGT3E15% = iKBLD_w10, PCIVEN_8086&DEV_5926”
igdlh64-1.PNG
将这行复制下来,然后向上查找“iSKLWSGT4”,在这行的下面添加一行,把刚才复制的内容贴上来,然后修改一下,修改为“%iKBLULTGT3E15% = iSKLD_w7, PCIVEN_8086&DEV_5926”
改完后应该是这个样子
igdlh64-2.PNG
保存后,就可以回到上一层目录,执行setup安装显卡驱动了


pre-install:安装依赖包:

apt install lcov pandoc autoconf-archive liburiparser-dev libdbus-1-dev libglib2.0-dev dbus-x11 libssl-dev \
autoconf automake libtool pkg-config gcc  libcurl4-gnutls-dev libgcrypt20-dev libcmocka-dev uthash-dev

一,下载及安装TPM 模拟器

IBMTPM模拟器项目页面:https://sourceforge.net/projects/ibmswtpm2/files/
下载最新的版本wget https://jaist.dl.sourceforge.net/project/ibmswtpm2/ibmtpm1332.tar.gz

mkdir ibmtpm1332
cd ibmtpm1332/
tar zxvf  ../ibmtpm1332.tar.gz
cd src/
make
cp tpm_server /usr/local/bin/

增加tpm-server.service
vi /lib/systemd/system/tpm-server.service

[Unit]
Description=TPM2.0 Simulator Server Daemon
Before=tpm2-abrmd.service

[Service]
ExecStart=/usr/local/bin/tpm_server 
Restart=always
Environment=PATH=/usr/bin:/usr/local/bin

[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl start tpm-server.service

确认tpm模拟器启动正常

二,安装TPM2相关软件包

1,安装tpm2_tss

添加TSS用户
useradd --system --user-group tss

下载地址:
wget https://github.com/tpm2-software/tpm2-tss/releases/download/2.1.0/tpm2-tss-2.1.0.tar.gz

tar zxvf tpm2-tss-2.1.0.tar.gz
cd tpm2-tss-2.1.0/
./configure --enable-unit --enable-integration
make check
make install
ldconfig
cd ..

2,安装tpm2_abrmd

下载地址:
wget https://github.com/tpm2-software/tpm2-abrmd/releases/download/2.0.2/tpm2-abrmd-2.0.2.tar.gz

tar zxvf tpm2-abrmd-2.0.2.tar.gz
cd tpm2-abrmd-2.0.2/
ldconfig
./configure --with-dbuspolicydir=/etc/dbus-1/system.d --with-systemdsystemunitdir=/lib/systemd/system
make
make install

cp /usr/local/share/dbus-1/system-services/com.intel.tss2.Tabrmd.service /usr/share/dbus-1/system-services/

重启 DBUS
pkill -HUP dbus-daemon

修改system tpm2-abrmd.service服务配置
vi /lib/systemd/system/tpm2-abrmd.service
将“ExecStart=/usr/local/sbin/tpm2-abrmd”修改为“ExecStart=/usr/local/sbin/tpm2-abrmd --tcti="libtss2-tcti-mssim.so.0:host=127.0.0.1,port=2321"”

systemctl daemon-reload
systemctl start tpm2-abrmd.service
查看status,确认服务正常启动

3,安装tpm2_tools

git clone https://github.com/tpm2-software/tpm2-tools.git
cd tpm2-tools/
./bootstrap
./configure
make

测试tpm2-tools工具连接abrmd服务是否正常
./tools/tpm2_getrandom 4

没问题的话
make install

安装完毕

执行tpm2_pcrlist,查看是否正常输出

三,tpm2常用命令

设定tpm相关密码(-o ownership password,-e endorsement password,-l lockout password):tpm2_takeownership -o 1 -e 1 -l 1

Create a Primary Object in endorsement hierarchy, with objectpass as the object password, with RSA keys & SHA256 name hash algorithm, with object context saved in file po.ctx:
tpm2_createprimary -H e -K 11 -g 0x000b -G 0x0001 -C po.ctx -P 1

Create a RSA key under the previous primary key, with subobjectpass as the object password, with SHA256 name hash algorithm, with public portion saved in key.pub and private portion saved in key.priv:
tpm2_create -c po.ctx -P 11 -K 111 -g 0x000b -G 0x0001 -u key.pub -r key.priv

Load the created RSA key:
tpm2_load -c po.ctx -P 11 -u key.pub -r key.priv -n key.name -C obj.ctx

Encrypt file data.in with RSA key:
tpm2_rsaencrypt -c obj.ctx -o data.encrypt data.in

Decrypt with RSA key:
tpm2_rsadecrypt -c obj.ctx -I data.encrypt -P 111 -o data.decrypt

使用tpm2_quote对PCR签名,使用OpenSSL校验签名的步骤:

# Generate an ECC key
openssl ecparam -name prime256v1 -genkey -noout -out private.ecc.pem
openssl ec -in private.ecc.pem -out public.ecc.pem -pubout

# Load the private key for signing
tpm2_loadexternal -Q -G ecc -r private.ecc.pem -o key.ctx

# Sign in the TPM and verify with OSSL
tpm2_quote -C key.ctx -G sha256 -L sha256:16,17,18 -f plain -q 11aabb -s pcr.out.signed -m pcr.in.raw
openssl dgst -verify public.ecc.pem -keyform pem -sha256 -signature pcr.out.signed pcr.in.raw 

备注:在使用tpm2_quote时,会报错如下:

ERROR: Could not convert signature hash algorithm selection, got: "sha256"

google查了半天也没结果,最后只能看源码,发现在tools/tpm2_quote.c第191开始的这段代码:
tpm2-tools-quote.png
将命令行输入的-G参数后的值做个转换,然后与预定义的flags比较
但是不知道是什么情况,这里用了“tpm2_alg_util_flags_sig”,去lib/tpm2_alg_util.c里查了定义,flags_sig里并没有sha256,所以导致报错
tpm2_lib_alg_util.png
但是我尝试使用定义里的ecdsa之类的算法,也会报另外一个错:

ERROR: Tss2_Sys_Quote(0x2C3) - tpm:parameter(2):hash algorithm not supported or not appropriate
ERROR: Unable to run tpm2_quote

而这可能就是tpm模拟器不支持了,不知道真实物理tpm芯片是不是支持,以后有条件再测试下

解决办法:暂时只能修改tpm2_quote的代码,将192行 “tpm2_alg_util_flags_sig”改为“tpm2_alg_util_flags_hash”,然后重新编译即可


Typecho 强力驱动