ophub / amlogic-s9xxx-armbian

Support for Armbian in Amlogic, Rockchip and Allwinner boxes. Support a311d, s922x, s905x3, s905x2, s912, s905d, s905x, s905w, s905, s905l, rk3588, rk3568, rk3399, rk3328, h6, etc.
GNU General Public License v2.0
5.92k stars 1.9k forks source link

通过验证,部分目录用户和组异常不是刷入导致 #1563

Closed daifiyum closed 1 year ago

daifiyum commented 1 year ago

Device Information | 设备信息

Armbian Version | 系统版本

Describe the bug | 问题描述 使用虚拟机Archlinux系统挂载U盘内的根目录分区,可以发现部分文件用户和组出现问题,表现为1001:123,其他文件为正常的root:root,这并非错误刷入导致,因为刚做好启动盘连N1盒子都没插进去!!!

Please provide a detailed description of the issue and, if necessary, attach a screenshot. 详细描述问题,并在必要时附上屏幕截图。

我对两个固件进行了测试,一个是本项目的固件,另一个是恩山论坛里找的一个,固件连接如下: 本项目固件:Armbian_23.08.0_amlogic_s905d_bullseye_6.1.39_server_2023.07.20.img.gz 恩山论坛固件:https://cloud.189.cn/web/share?code=ZvmEbyQV3yeq(访问码:hmn9

下面是在虚拟机Archlinux系统下分别挂载这两个固件的截图(都是在做完启动盘后,立即挂载的,中间未插入N1盒子,也未插入任何安卓系统)

挂载本项目固件: 屏幕截图 2023-07-23 090257

挂载恩山论坛固件: 屏幕截图 2023-07-23 085838

通过两图对比,可以发现本项目固件部分目录用户和组异常,也可以确定是本项目固件的bug,这个过程也很好复现,固件下载连接也已给出,希望作者能修复一下,非常感谢

7Ji commented 1 year ago

https://github.com/ophub/amlogic-s9xxx-armbian/blob/c8991cb8b389152f8a088e789480615376d81c25/rebuild#L732

The problem is caused by the cp command here, 1001:123 is the github actions runner user and sudoer group, the files under build-armbian/armbian_filez are copied as-is as this was run by root, a quick patch adding argument --no-preserve=ownership should fix it. I can submit a PR later.

ophub commented 1 year ago

搜cp -af,第一处可以保留,这个复制原Armbian镜像。把后四个改成cp -rpP就不改变所有者了。

在大多数情况下,-R和-r选项在cp命令中是等价的,用于递归复制目录和子目录。github的ubuntu22.04是GNU版本的cp,通常建议使用-r选项,因为它是更为常见和广泛支持的写法。你试试这样权限是否正确了,可以就pr一个吧。

https://github.com/ophub/amlogic-s9xxx-armbian/blob/c8991cb8b389152f8a088e789480615376d81c25/rebuild#L728-L749

daifiyum commented 1 year ago

搜cp -af,有五个,除了第一个,后面黄色高亮的四个只改前3个吗? 屏幕截图 2023-07-23 153322

ophub commented 1 year ago

第一个保留吧,这个是从原镜像保留全部权限和所有者、时间戳等进行初始化,这个保留。

其他的cp -af替换参数,用-p选项可以保留源文件的权限和时间戳,但不改变所有者。权限就不会被这个复制-f强改了。你fork修改,把actions里面的打包仓库也改成你的仓库,才能测试修改结果,打包的img还是用losetup挂载进去看看

7Ji commented 1 year ago

No, -p preserved ownership which is not what we want, --no-preserve=ownership is needed

nomad7ji@dsk /t/ownership> mkdir -p src/files
nomad7ji@dsk /t/ownership> touch src/files/randomFile
nomad7ji@dsk /t/ownership> tree
.
└── src
    └── files
        └── randomFile

3 directories, 1 file
nomad7ji@dsk /t/ownership> sudo mkdir target1 target2 target3
nomad7ji@dsk /t/ownership> sudo cp -af src/* target1
nomad7ji@dsk /t/ownership> ls -lh target1
Total 0
drwxr-xr-x 2 nomad7ji wheel 60  7月23日 15:35 files/
nomad7ji@dsk /t/ownership> sudo cp -rpP src/* target2
nomad7ji@dsk /t/ownership> ls -lh target2
Total 0
drwxr-xr-x 2 nomad7ji wheel 60  7月23日 15:35 files/
nomad7ji@dsk /t/ownership> sudo cp -af --no-preserve=ownership src/* target3
nomad7ji@dsk /t/ownership> ls -lh target3
Total 0
drwxr-xr-x 2 root root 60  7月23日 15:35 files/
7Ji commented 1 year ago

用-p选项可以保留源文件的权限和时间戳,但不改变所有者

This IS the problem, the ownership problem is actually caused by PRESERVING the ownership (which is the github action runner's 1001:123 instead of root that is running the building script.

daifiyum commented 1 year ago

要不,你们先讨论讨论,我再试试🤣

ophub commented 1 year ago

p选项:保留源文件的权限和时间戳,但不改所有者。所以复制后的文件执行权保留了,用户不复制。所以cp -rpP应该就可以了,你测试一下

daifiyum commented 1 year ago

好,试一下

ophub commented 1 year ago

一般来说用cp -rf即可,文件的执行权限可以保留,但不改变所有者。

但时间戳不继承的话,个别设备在不联网的情况下初次使用时,armbian-install会报一个时间不正确的错误,显示文件是未来日期的。

7Ji commented 1 year ago

p选项:保留源文件的权限和时间戳,但不改所有者。所以复制后的文件执行权保留了,用户不复制。所以cp -rpP应该就可以了,你测试一下

  1. https://www.gnu.org/software/coreutils/manual/coreutils.html#index-_002dP-1
    -P is for dereferencing the symbol links, what's its usage here?

  2. https://www.gnu.org/software/coreutils/manual/coreutils.html#index-_002dp-3
    And using -p, quote, "Using --preserve with no attribute_list is equivalent to --preserve=mode,ownership,timestamps."

ophub commented 1 year ago

-P这个保留符号链接的真实路径加上吧,/boot/dtb-xxx —> dtb可能用到。留着没负作用,并且可以兼顾需要。

-p我搜的文章看不改变,你测一下

7Ji commented 1 year ago

Isn't /boot on a MS filesystem, usually FAT32? They do not support symbol links, and the build script will break if you want to do anything symbol link-related on such filesystems.

ophub commented 1 year ago

rockchip里面,我是dtb真实目录,dtb-xxx是符号链接,f大是相反的。

这个仓库是另外一个op仓库的上游,为了兼容f大的以前的习惯,我尽量对已经习惯性的使用保留不变。

-P在几个复制了有几处目前用不到,可加可不加,加了给未来留了路,也可以支持用户更自由的添加文件。

ophub commented 1 year ago

https://github.com/ophub/amlogic-s9xxx-openwrt/blob/main/make

这个修复方案,帮这个也修一下吧