分类 技术 下的文章

RouterOS在ESXi8.0上以UEFI方式引导启动

最近新装了虚拟化平台esxi8.0b,在创建routeros虚拟机时遇到了一系列问题:
1,esxi8.0b默认创建的ESXi 8.0(虚拟硬件版本20)版本虚拟机使用了新的api,默认以uefi引导系统,在创建完成后不能修改为bios,报错“ACPI motherboard layout requires EFI”。
2,RouterOS的CHR版磁盘镜像默认以bios引导。使用x86的iso可以正常安装使用uefi引导虚拟机,但是系统显示的是x86架构,通过升降级不能切换架构,x86架构不启用open-vm-tools服务,这个服务不启动,在esxi控制面板看不到hostname和IP地址等信息。此外x86架构和chr架构的授权和有些功能也不相同。
3,RouterOS的CHR版磁盘镜像有两个分区,第一个是efi分区,文件系统是ext2,而非uefi标准的fat。
4,RouterOS的CHR版磁盘镜像有独立的mbr和gpt分区表,既不是gpt也不是Hybrid MBR。

以下是让routeros v7.8在ESXi8.0上以UEFI方式引导启动的方法,此方式只在routeros v7.8chr版测试通过,不确定后续版本升级是否可用。
1,创建没有硬盘的虚拟机。
2,下载routeros的vmdk虚拟机硬盘文件,解压上传到esxi。
3,ssh登录到esxi,转换routeros的vmdk磁盘格式,并扩展磁盘空间。

vmkfstools -i chr-7.8.vmdk routeros.vmdk -d thin
vmkfstools -X 20G routeros.vmdk

4,修改虚拟机配置,添加刚才生成的vmdk磁盘。
5,虚拟机挂载ubuntu的live-cd或其他有gdisk命令的系统iso到虚拟机。
6,开机进入ubuntu桌面,备份RouterOS Boot分区的全部文件
7,取消挂载,并使用fat格式化第一个分区

mkfs -t fat /dev/sda1

8,恢复步骤6中备份的文件到第一个分区后取消挂载routeros的两个磁盘
9,使用gdisk创建Hybrid MBR分区表,过程如下:

root@ubuntu:/home/ubuntu# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.8

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: present

Found valid MBR and GPT. Which do you want to use?
 1 - MBR
 2 - GPT
 3 - Create blank GPT

Your answer: 2
Using GPT and creating fresh protective MBR.

Command (? for help): t
Partition number (1-2): 1
Current type is EF00 (EFI system partition)
Hex code or GUID (L to show codes, Enter = EF00): 8300
Changed type of partition to 'Linux filesystem'

Command (? for help): r

Recovery/transformation command (? for help): h

WARNING! Hybrid MBRs are flaky and dangerous! If you decide not to use one,
just hit the Enter key at the below prompt and your MBR partition table will
be untouched.

Type from one to three GPT partition numbers, separated by spaces, to be
added to the hybrid MBR, in sequence: 1 2
Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N): n

Creating entry for GPT partition #1 (MBR partition #1)
Enter an MBR hex code (default 83): 
Set the bootable flag? (Y/N): y

Creating entry for GPT partition #2 (MBR partition #2)
Enter an MBR hex code (default 83): 
Set the bootable flag? (Y/N): n

Unused partition space(s) found. Use one to protect more partitions? (Y/N): n

Recovery/transformation command (? for help): w
Warning! Secondary header is placed too early on the disk! Do you want to
correct this problem? (Y/N): y
Have moved second header and partition table to correct location.

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
The operation has completed successfully.

10,重启系统即可以UEFI方式启动RouterOS CHR

附:
初始vmdk的mbr分区表:

root@ubuntu:/home/ubuntu# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.8

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: present

Found valid MBR and GPT. Which do you want to use?
 1 - MBR
 2 - GPT
 3 - Create blank GPT

Your answer: 1

Command (? for help): p
Disk /dev/sda: 262144 sectors, 128.0 MiB
Model: VMware Virtual I
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): F1C07EE3-729F-4E5F-8C77-AEC9BC697BD3
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 262110
Partitions will be aligned on 2-sector boundaries
Total free space is 4063 sectors (2.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              34           65569   32.0 MiB    8300  Linux filesystem
   2           65570          258047   94.0 MiB    8300  Linux filesystem

Command (? for help): q

初始vmdk的gpt分区表:

root@ubuntu:/home/ubuntu# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.8

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: present

Found valid MBR and GPT. Which do you want to use?
 1 - MBR
 2 - GPT
 3 - Create blank GPT

Your answer: 2
Using GPT and creating fresh protective MBR.

Command (? for help): r

Recovery/transformation command (? for help): p
Disk /dev/sda: 262144 sectors, 128.0 MiB
Model: VMware Virtual I
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 197E76F1-9677-0D46-9C33-F00032DDDBB1
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 258047
Partitions will be aligned on 2-sector boundaries
Total free space is 0 sectors (0 bytes)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              34           65569   32.0 MiB    EF00  RouterOS Boot
   2           65570          258047   94.0 MiB    8300  RouterOS

Recovery/transformation command (? for help): q

创建hybrid mbr后的vmdk的gpt分区表:

Recovery/transformation command (? for help): p
Disk /dev/sda: 262144 sectors, 128.0 MiB
Model: VMware Virtual I
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 197E76F1-9677-0D46-9C33-F00032DDDBB1
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 258047
Partitions will be aligned on 2-sector boundaries
Total free space is 0 sectors (0 bytes)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              34           65569   32.0 MiB    8300  RouterOS Boot
   2           65570          258047   94.0 MiB    8300  RouterOS

Recovery/transformation command (? for help): o

Disk size is 262144 sectors (128.0 MiB)
MBR disk identifier: 0x00000000
MBR partitions:

Number  Boot  Start Sector   End Sector   Status      Code
   1      *             34        65569   primary     0x83
   2                 65570       258047   primary     0x83
   3                     1           33   primary     0xEE

参考:
1,Router OS 7 on UEFI
2,Hybrid MBR(MBR 混合分区表)
3,Manual:CHR VMWare installation

2022年使用Youtube TV收看美国电视直播情况

不了解youtube tv的可以参考:中国大陆收看美国电视直播总结(持续更新)
youtube tv发布以来的订阅费一直在涨价,基础套餐从最初的40刀一路涨到了现在的65刀。最近又想看discovery和国家地理的生肉了,所以重新订阅了youtube tv。
订阅其实很简单,美国原生ip,一个和ip对应的zip code,可以美区付费google账号。
以我使用的美国西雅图ip为例:
基础套餐65刀,总计106个频道,其中13个频道需要位置权限,我还加购了hbo max包15刀,4k包第一年10刀,总计90刀每月,有点肉疼。
跟之前分享的一样,zip code需要和ip所在位置一致才能稳定的收看,要不然会经常弹出所在位置与登记不符。
网页和移动设备需要定位权限才能看一些本地新闻频道,网页可以参考上面我之前分享的怎么收看美国电视直播的文章。
apple tv需要用网页定位一次,之后就随便看了。
iphone目前没有好用的虚拟定位,所以那13个频道没办法看了。
现在的youtube tv 越来越好用了,大部分可以看的剧集综艺都有vod,可以直接看点播,不需要再订阅其他了。
hbo max包订阅后可以在hbo max的app里收看。
订阅4k包,看4khdr冬奥会,效果很好。

nginx+php启用quic即http/3的方法

本站已支持http/3。
屏幕截图 2021-11-03 095321.png
支持HTTP/3

http/3quic参考wiki。

1.QUIC简单流程介绍
当浏览器向之前从未发过请求的服务端发出请求时,它不知道对方是否支持QUIC,因此先通过TCP发送第一个请求。服务器响应该请求以后,要发送 Alt-Svc 的HTTP响应头告诉浏览器它支持QUIC。浏览器知道服务端支持 QUIC后尝试使用 QUIC 来进行下一个请求。浏览器下一个请求采取QUIC和TCP竞争的方式与服务端建立连接,如果请求通过TCP发出,TCP赢得竞争,请求将通过TCP发出。后续如果QUIC连接成功,之后所有请求都将通过QUIC连接发送。
当浏览器向之前使用过QUIC的服务器发出请求时,它还会与TCP进行竞争。 对于启用QUIC并支持0-RTT握手的服务器,由于浏览器将能够进行0-RTT握手,因此QUIC还会立即获胜,并且继续在QUIC连接上发出请求。
如果QUIC握手失败,则浏览器会将QUIC标记为该主机broken。后续请求都将通过TCP重新发送。5分钟后,broken的QUIC标记为recently broken。当向服务器发出下一个请求时,浏览器又将继续让TCP和QUIC进行竞争。由于QUIC recently broken,因此将禁用0-RTT握手。如果握手再次失败,则QUIC将在此次再次标记为该连接已损坏10分钟,将QUIC标记为已损坏的前一周期的2倍,如此往后都会不断的标记为2倍。如果握手成功,请求将通过QUIC发送,QUIC将不再标记为recently broken。

2.浏览器启用QUIC或者HTTP/3
chrome浏览器,地址栏打开chrome://flags,搜索quic,Experimental QUIC protocol选择enabled,重启浏览器。edge等chromium内核浏览器类似。
safari浏览器,实验功能,启用HTTP/3,重启浏览器。
打开https://http3.is或者https://quic.nginx.org或者https://cloudflare-quic.com可以检查浏览器是否能使用quic。
chrome可以安装QUIC indicator插件检测网页是否以quic打开。

3.网站配置
启用http/3或者quic需要反代服务器支持即可,即nginx,caddy等支持http/3。nginx官方主线版本还未支持,可以使用cloudflare的插件quiche重新编译nginx源码实现支持。caddy可以通过实验功能开启http3,但是截至v2.4.5版还存在问题
所以这里使用docker-nginx-http3替换原nginx。
配置文件需要参考作者提供的nginx.conf和h3.nginx.conf

systemctl stop nginx
apt update
apt install docker.io
docker pull ranadeeppolavarapu/nginx-http3
docker run -d -t --restart always --name "nginx-http3" -p 80:80 -p 443:443/tcp -p 443:443/udp -v /var/run/php:/var/run/php -v [映射nginx的配置文件,网页代码文件,证书等] ranadeeppolavarapu/nginx-http3

修改php-fpm监听的unix socket的权限,修改www.conf的listen.mode = 0666,给映射进容器的php7.2-fpm.sock赋予权限。
然后重启php-fpm服务。

4.检查网站是否启用HTTP/3
https://http3check.net/

5.其他
quic使用的端口号需要和tcp相同,否则网页地址会变,网页会出现跨域问题。
通过使用chrome的quic indicator插件发现很多网站都启用了http/3,尤其使用cloudfare CDN的网站,比如www.google.com,youtube.com,cloudflare.com,whatismyipaddress.com,whatismyip.com,ip.sb等

M1芯片的macos使用H3C的inode连接SSL VPN

M1芯片的macos使用inode需要关闭SIP(System Integrity Protection系统完整性保护),安全性问题请自行评估。
以下方法在M1芯片的MacBook pro 13寸macos 11 big sur下经过测试验证。
1,进入恢复模式。关闭mac后长按开机键,直至出现《选项》
屏幕截图 2021-10-25 163805.png
2,恢复模式,左上角实用工具选择终端
3,输入“csrutil disable”,按提示输入密码。如果报错,输入“csrutil clear”,然后左上角苹果图标选择关机,然后再次进入恢复模式输入“csrutil disable”
4,左上角苹果图标选择重启
5,双击inode安装包,在设置-安全-通用允许运行
6,安装完成后重启电脑
7,打开inode,配置网关,账号密码。

ps:macos的app store里的inode sslvpn是ios版,在macos下可以安装但是不能连接。
下面附件是inode_for_macos_7.3(e0584)
iNodeClient_MacOS_2.zip

IPv4地址10进制转16进制IPv6地址批处理脚本

最近做IPv6项目时遇到了ipv4地址的十进制数字转ipv6地址的十六进制,用计算器换算太麻烦,所以撸了一个批处理轮子。
可以参考我之前的《批处理脚本封装成exe可执行文件》,转成exe方便使用。

此脚本可以实现对输入的ipv4地址格式做判断,只把v4的a.b.c.d转成v6的ff:ff格式。
注意批处理脚本要保存成ansi格式。

#batch_ipv4_trans_hex.bat
chcp 936&cls
@echo off&PUSHD %~DP0 &TITLE IPv4地址转IPv6
mode con cols=90 lines=30&COLOR f0

:input_ipv4_address
cls
echo;请输入IPv4地址:
setlocal enabledelayedexpansion
set /p ipv4=
set "s=[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*"
echo %ipv4%|findstr /be "%s%" >nul||set flag=a
set n=%ipv4:.= %
for %%a in (%n%) do (
   set /a var=1%%a 2>nul
   if !var! gtr 1255 set flag=a
)
if defined flag echo;IPv4地址格式错误,按任意键重新输入&pause>nul&endlocal&goto :input_ipv4_address
for /f "tokens=1 delims=." %%a in ("%ipv4%")  do ( set ipv4_a=%%a)
if not defined ipv4_a echo;IPv4地址格式错误,按任意键重新输入&pause>nul&goto :input_ipv4_address
for /f "tokens=2 delims=." %%a in ("%ipv4%")  do ( set ipv4_b=%%a)
if not defined ipv4_b echo;IPv4地址格式错误,按任意键重新输入&pause>nul&goto :input_ipv4_address
for /f "tokens=3 delims=." %%a in ("%ipv4%")  do ( set ipv4_c=%%a)
if not defined ipv4_c echo;IPv4地址格式错误,按任意键重新输入&pause>nul&goto :input_ipv4_address
for /f "tokens=4 delims=." %%a in ("%ipv4%")  do ( set ipv4_d=%%a)
if not defined ipv4_d echo;IPv4地址格式错误,按任意键重新输入&pause>nul&goto :input_ipv4_address
call :dec2hex %ipv4_a% ipv4_a_hex
call :dec2hex %ipv4_b% ipv4_b_hex
call :dec2hex %ipv4_c% ipv4_c_hex
call :dec2hex %ipv4_d% ipv4_d_hex
cls
echo;IPv4地址:%ipv4%
echo;IPv6地址:%ipv4_a_hex%%ipv4_b_hex%:%ipv4_c_hex%%ipv4_d_hex%
echo;按任意键重新输入,或按右上角X退出
pause>nul
set ipv4=
set ipv4_a=
set ipv4_b=
set ipv4_c=
set ipv4_d=
cls
goto :input_ipv4_address

:dec2hex
setlocal EnableDelayedExpansion
set n=%1
for /l %%i in (1,1,2) do set/a"H%%i=n&15,n>>=4"&set o=!H%%i!:!o!
for %%e in ("10:=A" "11:=B" "12:=C" "13:=D" "14:=E" "15:=F" ":=") do set o=!o:%%~e!
endlocal & set %2=%o%