Skip to content

build-dtb-image/build-kernel-deb: drop root requirement - #223

Open
Xinzheng Long (xinlon-z) wants to merge 2 commits into
qualcomm-linux:mainfrom
xinlon-z:no-sudo-requirement
Open

build-dtb-image/build-kernel-deb: drop root requirement#223
Xinzheng Long (xinlon-z) wants to merge 2 commits into
qualcomm-linux:mainfrom
xinlon-z:no-sudo-requirement

Conversation

@xinlon-z

@xinlon-z Xinzheng Long (xinlon-z) commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

In some environments, such as AI-driven workflows, sudo privileges may not be available, which makes it difficult to run the existing scripts. To make things a bit more flexible, I did some update in kernel/scripts/build-dtb-image.sh and kernel/scripts/build-kernel-deb.sh so they can be executed without requiring root privileges, bringing their behavior just like Yocto.

The script previously needed root because it used losetup + mount to
write the combined DTB / FIT image into a FAT image. Replace that
pipeline with mkfs.vfat formatting the image file directly and mcopy
from mtools to populate it, which removes every privileged operation.

Switch the kernel .deb extraction from `dpkg-deb -R` to
`dpkg-deb --fsys-tarfile | tar -x --no-same-owner --no-same-permissions`
so non-root extraction is reliable (dpkg-deb -R warns/fails on chown
when not run as root). Drop the EUID guard, simplify the cleanup trap
(no more umount / losetup -d / mountpoint), and remove the now-unused
MNT_DIR / LOOP_DEV variables.

The CLI is unchanged; existing callers that wrap the script in sudo
continue to work -- sudo is now allowed but no longer required.

Tooling change:
  Add mcopy (mtools) -- always
  Add tar -- only in --kernel-deb mode
  Remove losetup, mount, umount, mountpoint

Signed-off-by: Xinzheng Long <xinzheng.long@oss.qualcomm.com>
The script previously self-elevated via `exec sudo "$0" "$@"`, but every
operation it performs is local: it stages files under `$DEB_DIR` in the
current working directory and runs `dpkg-deb --build`. None of those
need root.

Pass `--root-owner-group` to `dpkg-deb --build` so all entries in the
resulting `.deb` are recorded as `root:root` regardless of the build
user's uid/gid. This is the standard mechanism for building Debian
packages without fakeroot or a real root shell, and matches what the
postinst/preinst scripts assume at install time on the target.

Drop the `EUID` guard and the self-sudo block. The CLI is unchanged;
existing callers that wrap the script in sudo continue to work -- sudo
is now allowed but no longer required.

Verified by building a synthetic `out/` tree (Image, .config, modules,
.dtb, .dtbo) and running the script as a normal user; `dpkg-deb
--contents` on the resulting package shows every entry owned by
`root/root`, and the preinst/postinst/postrm maintainer scripts are
intact and executable.

Signed-off-by: Xinzheng Long <xinzheng.long@oss.qualcomm.com>
@bjordiscollaku

Copy link
Copy Markdown
Contributor

Xinzheng Long (@xinlon-z) it has been quite a while that build-dtb-image tool moved to qcom-dtb-metadata: https://github.com/qualcomm-linux/qcom-dtb-metadata/blob/main/build-dtb-image.sh. Please consider this tool in build-utils depricated.

@xinlon-z

Copy link
Copy Markdown
Contributor Author

has been quite a while that build-dtb-image tool moved to qcom-dtb

Xinzheng Long (Xinzheng Long (@xinlon-z)) it has been quite a while that build-dtb-image tool moved to qcom-dtb-metadata: https://github.com/qualcomm-linux/qcom-dtb-metadata/blob/main/build-dtb-image.sh. Please consider this tool in build-utils depricated.

sure, thanks for providing this info, will update this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants