Bug 15340

Summary: 'opkg remove' is deleting /lib directory when removing service file
Product: [Yocto Project Subprojects] opkg Reporter: Allan Jones <allan>
Component: opkgAssignee: Alex Stewart <alex.stewart>
Status: NEW --- QA Contact:
Severity: normal    
Priority: Undecided    
Version: 0.6.2   
Target Milestone: ---   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Allan Jones 2024-01-10 09:15:46 UTC
I'm building a package using CMake and adding a service file into /lib/systemd/system.  Installation works fine but when I remove the package it deletes the /lib directory.
Here's a minimum CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(simplePack)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS -pthread)
add_executable(${PROJECT_NAME} "main.cpp")
install(TARGETS ${PROJECT_NAME} DESTINATION /etc/simple)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
set(CPACK_PACKAGE_NAME "TEST-MODEL")
set(CPACK_PACKAGE_VENDOR InventDesignBuild)
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "2")
set(CPACK_PACKAGE_VERSION_PATCH "15")
set(CPACK_PACKAGE_CONTACT info@...)
set(CPACK_GENERATOR "DEB")
set(CPACK_SET_DESTDIR true)
set(CPACK_INSTALL_PREFIX "/")
install(FILES ${CMAKE_SOURCE_DIR}/hyperion-bridge.service DESTINATION lib/systemd/system)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "aarch64")
include(CPack)

This is a minimum build to reproduce the problem. The hyperion-bridge.service file is included at the end (I don't think its contents are relevant). 

The executable is a simple 'hello, world' - code at the end.

The package is installed correctly using;
# opkg -V4 install ./TEST-MODEL-1.2.15-Linux.deb


Here's the output for removing the package;

# opkg -V4 remove test-model                     
pkg_hash_load_status_files:
pkg_vec_insert_merge: Adding new pkg=test-model version=1.2.15 arch=aarch64.
pkg_info_preinstall_check: Updating file owner list.
Removing test-model (1.2.15) from root...
pkg_run_script: Running script //var/lib/opkg/info/test-model.prerm.
remove_data_files_and_list: Deleting /etc/simple/simplePack.
remove_data_files_and_list: Deleting /lib/systemd/system/hyperion-bridge.service.
remove_data_files_and_list: Deleting /etc/simple.
remove_data_files_and_list: Deleting /lib.
pkg_run_script: Running script //var/lib/opkg/info/test-model.postrm.
remove_maintainer_scripts: Deleting //var/lib/opkg/info/test-model.control.
remove_maintainer_scripts: Deleting //var/lib/opkg/info/test-model.md5sums.
write_status_files_if_changed: Writing status file.
pkg_write_changed_filelists: Saving changed filelists.
hash_table: pkg-hash, 24576 bytes
    n_buckets=1024, n_elements=1, n_collisions=0
    max_bucket_len=0, n_used_buckets=1, ave_bucket_len=1.00
    n_hits=1, n_misses=1
hash_table: file-hash, 24576 bytes
    n_buckets=1024, n_elements=7, n_collisions=0
    max_bucket_len=0, n_used_buckets=7, ave_bucket_len=1.00
    n_hits=10, n_misses=7
hash_table: dir-hash, 24576 bytes
    n_buckets=1024, n_elements=5, n_collisions=0
    max_bucket_len=0, n_used_buckets=5, ave_bucket_len=1.00
    n_hits=10, n_misses=5
hash_table: obs-file-hash, 1536 bytes
    n_buckets=64, n_elements=0, n_collisions=0
    max_bucket_len=0, n_used_buckets=0, ave_bucket_len=0.00
    n_hits=0, n_misses=0

For some reason opkg seems to be removing the /lib directory hence the Linux system becomes unusable. 

Initially I was using opkg 4.2 built as part of my 'buildroot' build. I also see exactly the same effect having built and tested version 6.3.

Interestingly the /etc/ directory is not deleted when removing the package.

// hyperion-bridge.service file //
[Unit]
Description=Hyperion MQTT bridge
Wants=network.target
Wants=mosquitto.service

[Service]
Type=simple
WorkingDirectory=/etc/hyperion
ExecStart=/etc/hyperion/hypBridge -c config/bridgeConfig.yaml
Restart=always
RestartSec=5s
WatchdogSec=120s

[Install]
WantedBy=multi-user.target

// Source for the executable //
#include <iostream>

int main()
{
	std::cout << "Hello World!" << std::endl;
	return 0;
}
Comment 1 Alex Stewart 2024-02-12 23:30:36 UTC
Hey Allan. Sorry for the delayed reply.

Clarification question. Are you instrumenting opkg via buildroot such that all the files in the rootfs are being installed with opkg? And therefore opkg has a complete manifest picture of what is installed to the system when you perform the `remove` operation? Or is it rather that something else is building the rootfs, and then you are installing-and-removing the service file package with opkg. (I'm not super familiar with buildroot.)

If it's the latter, then I can easily imagine how opkg believes that nothing else on the system is using /lib and it is safe to remove.
Comment 2 Alex Stewart 2026-09-29 21:33:57 UTC
Need someone to revisit this bug and determine if this is intended behavior, before we can triage it.