1. Software operation and compilation
1.1 software related concepts
1.1.1 ABI
ABI : Application Binary Interface
Windows is incompatible with Linux
- ELF(Executable and Linkable Format)
- PE(Portable Executable)
Library level virtualization:
- Linux: WINE
- Windows: Cygwin
1.1.2 API
API is the Application Programming Interface. API can be implemented on various operating systems to provide the same interface for applications, but their implementation on these systems may be very different. There are two mainstream operating systems, one is Windows system and the other is Linux system. Due to different operating systems, APIs are divided into Windows API and Linux API. The software developed on Windows platform cannot run on Linux, and the software developed on Linux cannot run on windows, which leads to the difficulty of software transplantation. The emergence of POSIX standard is to solve this problem
POSIX: Portable Operating System Interface portable operating system interface defines the interface standards that the operating system should provide for applications. It is the general name of a series of API standards defined by IEEE for software to run on various UNIX operating systems.
Both Linux and windows should implement the basic posix standard, and the program is portable at the source code level
1.1.3 development language
System level development
- assembly language
- C
- C++
Application level development
- java
- Python
- go
- php
- perl
- delphi
- basic
- ruby
- bash
1.2 C language program compilation process
C program source code -- > preprocessing -- > compilation -- > assembly -- > link
The program compilation of C language mainly goes through four processes:
-
Pre processing
1) Delete all the #definitions and expand all the macro definitions
2) Handle all conditional precompiled instructions, such as #if #ifdef #elif #else #endif, etc
3) Process #include precompiled instructions and insert the included files into the location of the precompiled instructions.
4) Delete all comments "/ /" and "/ * * /"
5) Add line number and file ID to generate debugging line number and compilation error warning line number during compilation.
6) Keep all the #pragma compiler directives because the compiler needs to use them
-
Compiling
The compilation process is to perform a series of lexical analysis, syntax analysis, semantic analysis and Optimization on the preprocessed files, and finally generate the corresponding assembly code
-
Assembling
Assembler is to convert assembly code into machine executable commands. Almost every assembly statement corresponds to a machine instruction. Assembly is relatively simple compared with the compilation process. It can be translated one by one according to the comparison table of assembly instructions and machine instructions -
Linking
By calling the linker ld to link a large number of target files required for program operation and other library files, and finally generate executable files
Example: gcc compilation process
#Step by step compilation and operation gcc -E hello.c -o hello.i yes hello.c The file is preprocessed and generated hello.i file gcc -S hello.i -o hello.s The preprocessing file is compiled and the assembly file is generated gcc -c hello.s -o hello.o Compile the assembly file and generate the object file gcc hello.o -o hello Link the target file to generate an executable file #One step implementation of the compilation process gcc hello.c -o hello Directly compile and link to an executable object file
example:
[root@rocky8 ~]# cat hello.c #include <stdio.h> int main(void) { printf("Hello,world\n"); } [root@rocky8 ~]# gcc -bash: gcc: command not found [root@rocky8 ~]# dnf -y install gcc [root@rocky8 ~]# gcc hello.c -o hello #compile [root@rocky8 ~]# ll hello -rwxr-xr-x 1 root root 12848 Oct 13 13:55 hello [root@rocky8 ~]# file hello hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=06a605f75e95ed2eb0c8cc38730df3fdc4fff71b, not stripped [root@rocky8 ~]# ./hello Hello,world
1.3 static and dynamic links of software modules
The main function of link is to handle the parts referenced by each module, so that each module can be correctly connected, which is divided into static and dynamic links
1.3.1 static link
- Copy a copy of the dependent library corresponding to the program to the package
- Generate the module file libxxx.a
- Embedded package
- The upgrade is difficult and needs to be recompiled
- It takes up more space and is easy to migrate
1.3.2 dynamic link
- Only add dependencies as a dynamic link
- Generate the module file libxxx.so
- Connection pointing
- It takes up less space and is easy to upgrade
1.3.3 module (Library) files
View library files on which binaries depend
ldd /PATH/TO/BINARY_FILE
Manage and view locally loaded library files
#Loads the library file specified in the configuration file ldconfig #Displays all available library file names and file path mapping relationships that have been cached locally /sbin/ldconfig –p
Profile:
/etc/ld.so.conf, /etc/ld.so.conf.d/*.conf
Cache file:
/etc/ld.so.cache
example:
[root@rocky8 ~]# ldconfig [root@rocky8 ~]# ldconfig -p #View libraries loaded in memory 333 libs found in cache `/etc/ld.so.cache' p11-kit-trust.so (libc6,x86-64) => /lib64/p11-kit-trust.so libzstd.so.1 (libc6,x86-64) => /lib64/libzstd.so.1 libz.so.1 (libc6,x86-64) => /lib64/libz.so.1 libyaml-0.so.2 (libc6,x86-64) => /lib64/libyaml-0.so.2 libxtables.so.12 (libc6,x86-64) => /lib64/libxtables.so.12 libxslt.so.1 (libc6,x86-64) => /lib64/libxslt.so.1 libxml2.so.2 (libc6,x86-64) => /lib64/libxml2.so.2 libxmlsec1.so.1 (libc6,x86-64) => /lib64/libxmlsec1.so.1 libxmlsec1-openssl.so.1 (libc6,x86-64) => /lib64/libxmlsec1-openssl.so.1 libxmlsec1-openssl.so (libc6,x86-64) => /lib64/libxmlsec1-openssl.so libxkbcommon.so.0 (libc6,x86-64) => /lib64/libxkbcommon.so.0 libvmtools.so.0 (libc6,x86-64) => /lib64/libvmtools.so.0 libvgauth.so.0 (libc6,x86-64) => /lib64/libvgauth.so.0 libverto.so.1 (libc6,x86-64) => /lib64/libverto.so.1 libuuid.so.1 (libc6,x86-64) => /lib64/libuuid.so.1 libutil.so.1 (libc6,x86-64, OS ABI: Linux 3.2.0) => /lib64/libutil.so.1 libutil.so (libc6,x86-64, OS ABI: Linux 3.2.0) => /lib64/libutil.so libutempter.so.0 (libc6,x86-64) => /lib64/libutempter.so.0 libuser.so.1 (libc6,x86-64) => /lib64/libuser.so.1 libusb-1.0.so.0 (libc6,x86-64) => /lib64/libusb-1.0.so.0 libunistring.so.2 (libc6,x86-64) => /lib64/libunistring.so.2 libunbound.so.2 (libc6,x86-64) => /lib64/libunbound.so.2 libulockmgr.so.1 (libc6,x86-64) => /lib64/libulockmgr.so.1 libudev.so.1 (libc6,x86-64) => /lib64/libudev.so.1 libtss2-tctildr.so.0 (libc6,x86-64) => /lib64/libtss2-tctildr.so.0 libtss2-tcti-mssim.so.0 (libc6,x86-64) => /lib64/libtss2-tcti-mssim.so.0 libtss2-tcti-device.so.0 (libc6,x86-64) => /lib64/libtss2-tcti-device.so.0 libtss2-sys.so.0 (libc6,x86-64) => /lib64/libtss2-sys.so.0 libtss2-rc.so.0 (libc6,x86-64) => /lib64/libtss2-rc.so.0 libtss2-mu.so.0 (libc6,x86-64) => /lib64/libtss2-mu.so.0 libtss2-esys.so.0 (libc6,x86-64) => /lib64/libtss2-esys.so.0 libtspi.so.1 (libc6,x86-64) => /lib64/libtspi.so.1 libtirpc.so.3 (libc6,x86-64) => /lib64/libtirpc.so.3 libtinfo.so.6 (libc6,x86-64) => /lib64/libtinfo.so.6 libtinfo.so.5 (libc6,x86-64) => /lib64/libtinfo.so.5 libtic.so.6 (libc6,x86-64) => /lib64/libtic.so.6 libtic.so.5 (libc6,x86-64) => /lib64/libtic.so.5 libthread_db.so.1 (libc6,x86-64, OS ABI: Linux 3.2.0) => /lib64/libthread_db.so.1 libthread_db.so (libc6,x86-64, OS ABI: Linux 3.2.0) => /lib64/libthread_db.so libtevent.so.0 (libc6,x86-64) => /lib64/libtevent.so.0 libteamdctl.so.0 (libc6,x86-64) => /lib64/libteamdctl.so.0 libteam.so.5 (libc6,x86-64) => /lib64/libteam.so.5 libtdb.so.1 (libc6,x86-64) => /lib64/libtdb.so.1 libtasn1.so.6 (libc6,x86-64) => /lib64/libtasn1.so.6 libtalloc.so.2 (libc6,x86-64) => /lib64/libtalloc.so.2 libsystemd.so.0 (libc6,x86-64) => /lib64/libsystemd.so.0 libsysfs.so.2 (libc6,x86-64) => /lib64/libsysfs.so.2 libstdc++.so.6 (libc6,x86-64) => /lib64/libstdc++.so.6 libsss_sudo.so (libc6,x86-64) => /lib64/libsss_sudo.so libsss_nss_idmap.so.0 (libc6,x86-64) => /lib64/libsss_nss_idmap.so.0 libsss_idmap.so.0 (libc6,x86-64) => /lib64/libsss_idmap.so.0 libsss_certmap.so.0 (libc6,x86-64) => /lib64/libsss_certmap.so.0 libssl3.so (libc6,x86-64) => /lib64/libssl3.so libssl.so.1.1 (libc6,x86-64) => /lib64/libssl.so.1.1 libssh.so.4 (libc6,x86-64) => /lib64/libssh.so.4 libss.so.2 (libc6,x86-64) => /lib64/libss.so.2 libsqlite3.so.0 (libc6,x86-64) => /lib64/libsqlite3.so.0 libsolvext.so.1 (libc6,x86-64) => /lib64/libsolvext.so.1 libsolv.so.1 (libc6,x86-64) => /lib64/libsolv.so.1 libsoftokn3.so (libc6,x86-64) => /lib64/libsoftokn3.so libsnappy.so.1 (libc6,x86-64) => /lib64/libsnappy.so.1 libsmime3.so (libc6,x86-64) => /lib64/libsmime3.so libsmartcols.so.1 (libc6,x86-64) => /lib64/libsmartcols.so.1 libslapi-2.4.so.2 (libc6,x86-64) => /lib64/libslapi-2.4.so.2 libslang.so.2 (libc6,x86-64) => /lib64/libslang.so.2 libsigsegv.so.2 (libc6,x86-64) => /lib64/libsigsegv.so.2 libsgutils2.so.2 (libc6,x86-64) => /lib64/libsgutils2.so.2 libsepol.so.1 (libc6,x86-64) => /lib64/libsepol.so.1 libsemanage.so.1 (libc6,x86-64) => /lib64/libsemanage.so.1 libselinux.so.1 (libc6,x86-64) => /lib64/libselinux.so.1 libsecret-1.so.0 (libc6,x86-64) => /lib64/libsecret-1.so.0 libseccomp.so.2 (libc6,x86-64) => /lib64/libseccomp.so.2 libsasl2.so.3 (libc6,x86-64) => /lib64/libsasl2.so.3 librt.so.1 (libc6,x86-64, OS ABI: Linux 3.2.0) => /lib64/librt.so.1 librt.so (libc6,x86-64, OS ABI: Linux 3.2.0) => /lib64/librt.so ...
Example: after the library file is destroyed, the dependent program cannot run normally
[root@rocky8 ~]# ldd hello linux-vdso.so.1 (0x00007ffd533ae000) libc.so.6 => /lib64/libc.so.6 (0x00007f808d8f8000) /lib64/ld-linux-x86-64.so.2 (0x00007f808dcbd000) #View software dependency Libraries [root@rocky8 ~]# ls /lib64/libc.so.6 /lib64/libc.so.6 [root@rocky8 ~]# ll /bin/ls -rwxr-xr-x. 1 root root 143408 Mar 15 2021 /bin/ls [root@rocky8 ~]# ldd /bin/ls linux-vdso.so.1 (0x00007ffd0658b000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fb89285c000) libcap.so.2 => /lib64/libcap.so.2 (0x00007fb892656000) libc.so.6 => /lib64/libc.so.6 (0x00007fb892291000) libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007fb89200d000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fb891e09000) /lib64/ld-linux-x86-64.so.2 (0x00007fb892ca9000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb891be9000) [root@rocky8 ~]# mv /lib64/libc.so.6 /data [root@rocky8 ~]# ls ls: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory [root@rocky8 ~]# ./hello ./hello: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory [root@rocky8 ~]# mv /data/libc.so.6 /lib64/ mv: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
Enter CD rescue mode
Press ESC and select CD-ROM Drive
Enter troubleshooting
Rescue mode
Input 1
Prompt that the system is mounted to / mnt/sysimage. Press enter
The system root is in / mnt/sysimage
mv /mnt/sysimage/data/libc.s0.6 /mnt/sysimage/lib64
Move the file and exit to restart
[root@rocky8 ~]# ls hello hello [root@rocky8 ~]# ll /lib64/libc.so.6 lrwxrwxrwx. 1 root root 12 May 19 04:41 /lib64/libc.so.6 -> libc-2.28.so #This file is a soft link. If you delete and recreate the soft link, you can restore it
2. Software package and package manager
2.1 software package introduction
Open source software initially provided only the packaged source file of. tar.gz. Users must compile each software they want to run on GNU/Linux. Users urgently need the system to provide a more convenient way to manage these software. When Debian was born, such a management tool dpkg came into being, which can be used to manage the "package" files with deb suffix. Therefore, the famous "package" concept first appeared in GNU/Linux system. Later, Red Hat developed its own rpm package management system
2.1.1 document classification in software package
- Binary file
- Library file
- configuration file
- Help file
Example: use the cpio tool to view the package file list
rpm2cpio Package file|cpio –itv Preview files in package rpm2cpio Package file|cpio –id "*.conf" Release files in package
example:
[root@rocky8 ~]# ls /misc ls: cannot access '/misc': No such file or directory [root@rocky8 ~]# ls /misc/cd ls: cannot access '/misc/cd': No such file or directory [root@rocky8 ~]# rpm -qa autofs [root@rocky8 ~]# rpm -ql autofs package autofs is not installed [root@rocky8 ~]# dnf -y install autofs [root@rocky8 ~]# ls /misc/cd ls: cannot access '/misc/cd': No such file or directory [root@rocky8 ~]# systemctl enable --now autofs Created symlink /etc/systemd/system/multi-user.target.wants/autofs.service → /usr/lib/systemd/system/autofs.service. [root@rocky8 ~]# ls /misc/cd AppStream BaseOS EFI images isolinux LICENSE media.repo TRANS.TBL [root@rocky8 ~]# cd /misc/cd [root@rocky8 cd]# ls AppStream BaseOS EFI images isolinux LICENSE media.repo TRANS.TBL [root@rocky8 cd]# cd BaseOS/ [root@rocky8 BaseOS]# ls Packages repodata [root@rocky8 BaseOS]# cd Packages/ [root@rocky8 Packages]# ls aajohan-comfortaa-fonts-3.001-2.el8.noarch.rpm libnetfilter_conntrack-1.0.6-5.el8.x86_64.rpm accel-config-2.8-1.el8.i686.rpm libnetfilter_cthelper-1.0.0-15.el8.i686.rpm accel-config-2.8-1.el8.x86_64.rpm libnetfilter_cthelper-1.0.0-15.el8.x86_64.rpm accel-config-libs-2.8-1.el8.i686.rpm libnetfilter_cttimeout-1.0.0-11.el8.i686.rpm accel-config-libs-2.8-1.el8.x86_64.rpm libnetfilter_cttimeout-1.0.0-11.el8.x86_64.rpm acl-2.2.53-1.el8.1.x86_64.rpm libnetfilter_queue-1.0.4-3.el8.i686.rpm acpica-tools-20180629-3.el8.x86_64.rpm libnetfilter_queue-1.0.4-3.el8.x86_64.rpm adcli-0.8.2-9.el8.x86_64.rpm libnfnetlink-1.0.1-13.el8.i686.rpm adcli-doc-0.8.2-9.el8.noarch.rpm libnfnetlink-1.0.1-13.el8.x86_64.rpm alsa-sof-firmware-1.6.1-2.el8.noarch.rpm libnfsidmap-2.3.3-41.el8.i686.rpm alsa-sof-firmware-debug-1.6.1-2.el8.noarch.rpm libnfsidmap-2.3.3-41.el8.x86_64.rpm ... #There are a lot of rpm packages here root@ubuntu1804:~# ls /misc ls: cannot access '/misc': No such file or directory root@ubuntu1804:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 953M 0 part /boot ├─sda2 8:2 0 93.1G 0 part / ├─sda3 8:3 0 46.6G 0 part /data └─sda4 8:4 0 3.7G 0 part [SWAP] sr0 11:0 1 964M 0 rom root@ubuntu1804:~# mount /dev/sr0 /mnt mount: /mnt: WARNING: device write-protected, mounted read-only. root@ubuntu1804:~# cd /mnt/ root@ubuntu1804:/mnt# ls boot dists doc EFI install isolinux md5sum.txt pool preseed ubuntu root@ubuntu1804:/mnt# cd pool/ root@ubuntu1804:/mnt/pool# ls main root@ubuntu1804:/mnt/pool# cd main/ root@ubuntu1804:/mnt/pool/main# ls a c e g i k liba libc libe libg libi libk libm libo libq libs libu libw liby m o q s u w y b d f h j l libb libd libf libh libj libl libn libp libr libt libv libx libz n p r t v x z root@ubuntu1804:/mnt/pool/main# cd a root@ubuntu1804:/mnt/pool/main/a# ls aalib acl aide alsa-utils angular.js apport apr-util aptitude asn1crypto at augeas automat accountsservice acpid alabaster amavisd-new apache2 apport-symptoms apt apt-setup aspell attr authbind avahi acct adduser alsa-lib amd64-microcode apparmor apr apt-clone argon2 aspell-en audit autofs root@ubuntu1804:/mnt/pool/main/a# cd aide/ root@ubuntu1804:/mnt/pool/main/a/aide# ls aide_0.16-3_amd64.deb aide-common_0.16-3_all.deb [root@rocky8 Packages]# cp xz-5.2.4-3.el8.1.x86_64.rpm /data [root@rocky8 Packages]# cd /data [root@rocky8 data]# ls xz-5.2.4-3.el8.1.x86_64.rpm [root@rocky8 data]# rpm2cpio xz-5.2.4-3.el8.1.x86_64.rpm | cpio -tv #View the files in the package -rw-r--r-- 1 root root 162 Jun 14 22:48 ./etc/profile.d/colorxzgrep.csh -rw-r--r-- 1 root root 183 Jun 14 22:48 ./etc/profile.d/colorxzgrep.sh lrwxrwxrwx 1 root root 2 Jun 14 22:50 ./usr/bin/unxz -> xz -rwxr-xr-x 1 root root 84128 Jun 14 22:50 ./usr/bin/xz lrwxrwxrwx 1 root root 2 Jun 14 22:50 ./usr/bin/xzcat -> xz lrwxrwxrwx 1 root root 6 Jun 14 22:50 ./usr/bin/xzcmp -> xzdiff -rwxr-xr-x 1 root root 16864 Jun 14 22:50 ./usr/bin/xzdec -rwxr-xr-x 1 root root 6632 Jun 14 22:50 ./usr/bin/xzdiff lrwxrwxrwx 1 root root 6 Jun 14 22:50 ./usr/bin/xzegrep -> xzgrep lrwxrwxrwx 1 root root 6 Jun 14 22:50 ./usr/bin/xzfgrep -> xzgrep -rwxr-xr-x 1 root root 5628 Jun 14 22:50 ./usr/bin/xzgrep -rwxr-xr-x 1 root root 1802 Jun 14 22:50 ./usr/bin/xzless -rwxr-xr-x 1 root root 2161 Jun 14 22:50 ./usr/bin/xzmore drwxr-xr-x 1 root root 0 Jun 14 22:50 ./usr/lib/.build-id drwxr-xr-x 1 root root 0 Jun 14 22:50 ./usr/lib/.build-id/43 lrwxrwxrwx 1 root root 22 Jun 14 22:50 ./usr/lib/.build-id/43/059ad54ba42a7e5b29db2741a82b96cd80db82 -> ../../../../usr/bin/xz drwxr-xr-x 1 root root 0 Jun 14 22:50 ./usr/lib/.build-id/cd lrwxrwxrwx 1 root root 25 Jun 14 22:50 ./usr/lib/.build-id/cd/a20bf178f12c3ab7bb39d0291d38e2ec9d7d6a -> ../../../../usr/bin/xzdec drwxr-xr-x 1 root root 0 Jun 14 22:50 ./usr/share/doc/xz -rw-r--r-- 1 root root 1043 Apr 29 2018 ./usr/share/doc/xz/AUTHORS -rw-r--r-- 1 root root 2775 Apr 29 2018 ./usr/share/doc/xz/COPYING -rw-r--r-- 1 root root 18092 Apr 29 2018 ./usr/share/doc/xz/COPYING.GPLv2 -rw-r--r-- 1 root root 21413 Apr 29 2018 ./usr/share/doc/xz/NEWS -rw-r--r-- 1 root root 13526 Apr 29 2018 ./usr/share/doc/xz/README -rw-r--r-- 1 root root 2487 Apr 29 2018 ./usr/share/doc/xz/THANKS -rw-r--r-- 1 root root 4040 Apr 29 2018 ./usr/share/doc/xz/TODO -rw-r--r-- 1 root root 9411 Apr 29 2018 ./usr/share/doc/xz/faq.txt -rw-r--r-- 1 root root 7427 Apr 29 2018 ./usr/share/doc/xz/history.txt -rw-r--r-- 1 root root 5689 Apr 29 2018 ./usr/share/doc/xz/lzma-file-format.txt -rw-r--r-- 1 root root 43305 Apr 29 2018 ./usr/share/doc/xz/xz-file-format.txt -rw-r--r-- 1 root root 21945 Apr 29 2018 ./usr/share/locale/cs/LC_MESSAGES/xz.mo -rw-r--r-- 1 root root 26890 Apr 29 2018 ./usr/share/locale/de/LC_MESSAGES/xz.mo -rw-r--r-- 1 root root 24677 Apr 29 2018 ./usr/share/locale/fr/LC_MESSAGES/xz.mo -rw-r--r-- 1 root root 26091 Apr 29 2018 ./usr/share/locale/it/LC_MESSAGES/xz.mo -rw-r--r-- 1 root root 25679 Apr 29 2018 ./usr/share/locale/pl/LC_MESSAGES/xz.mo -rw-r--r-- 1 root root 27593 Apr 29 2018 ./usr/share/locale/vi/LC_MESSAGES/xz.mo lrwxrwxrwx 1 root root 7 Jun 14 22:50 ./usr/share/man/man1/unxz.1.gz -> xz.1.gz -rw-r--r-- 1 root root 20347 Apr 29 2018 ./usr/share/man/man1/xz.1.gz lrwxrwxrwx 1 root root 7 Jun 14 22:50 ./usr/share/man/man1/xzcat.1.gz -> xz.1.gz lrwxrwxrwx 1 root root 11 Jun 14 22:50 ./usr/share/man/man1/xzcmp.1.gz -> xzdiff.1.gz -rw-r--r-- 1 root root 1283 Apr 29 2018 ./usr/share/man/man1/xzdec.1.gz -rw-r--r-- 1 root root 664 Apr 29 2018 ./usr/share/man/man1/xzdiff.1.gz lrwxrwxrwx 1 root root 11 Jun 14 22:50 ./usr/share/man/man1/xzegrep.1.gz -> xzgrep.1.gz lrwxrwxrwx 1 root root 11 Jun 14 22:50 ./usr/share/man/man1/xzfgrep.1.gz -> xzgrep.1.gz -rw-r--r-- 1 root root 700 Apr 29 2018 ./usr/share/man/man1/xzgrep.1.gz -rw-r--r-- 1 root root 743 Apr 29 2018 ./usr/share/man/man1/xzless.1.gz -rw-r--r-- 1 root root 636 Apr 29 2018 ./usr/share/man/man1/xzmore.1.gz 842 blocks [root@rocky8 data]# rpm2cpio xz-5.2.4-3.el8.1.x86_64.rpm | cpio -idv ./usr/bin/xz #Unpack ./usr/bin/xz 842 blocks [root@rocky8 data]# ls usr xz-5.2.4-3.el8.1.x86_64.rpm [root@rocky8 data]# cd usr/ [root@rocky8 usr]# ls bin [root@rocky8 usr]# cd bin/ [root@rocky8 bin]# ls xz [root@rocky8 bin]# ll /bin/xz ./xz -rwxr-xr-x. 1 root root 84128 Jun 14 22:50 /bin/xz -rwxr-xr-x 1 root root 84128 Oct 13 18:42 ./xz
2.1.2 package manager
Package manager functions:
Package each component file of the compiled application into one or several package files. The package manager can easily and quickly realize the management operations such as package installation, uninstall, query, upgrade and verification
Mainstream package manager
- redhat: rpm file, RPM Package Manager, rpm: Redhat Package Manager, RPM Package Manager
- debian: deb file, dpkg package manager
2.1.3 package naming
Source code packaging file naming:
name-VERSION.tar.gz|bz2|xz VERSION: major.minor.release
Example: lines of C source code of the latest Linux kernel
[root@rocky8 ~]# tar xf linux-5.14.12.tar.xz [root@rocky8 ~]# cd linux-5.14.12 [root@rocky8 linux-5.14.12]# for file in `find -name "*.c"`;do line=`cat $file|wc -l`;let sum+=line;done;echo $sum 20930776 [root@rocky8 linux-5.14.12]# cat `find -name "*.c"` |wc -l 20930776 [root@rocky8 linux-5.14.12]# find -name "*.c" | xargs cat |wc -l 20930776
rpm package naming method:
name-VERSION-release.arch.rpm VERSION: major.minor.release release: release.OS
Common arch:
- x86: i386, i486, i586, i686
- x86_64: x64, x86_64, amd64
- powerpc: ppc
- Platform independent: noarch
example:
bash-3.2-32.el5_9.1.i386.rpm bash-4.2.46-19.el7.x86_64.rpm bash-4.4.19-7.el8.x86_64.rpm bash-4.4.19-7.el8.aarch64.rpm bash-4.4.19-7.el8.ppc64le.rpm bc_1.07.1-2_amd64.deb bc_1.07.1-2_s390x.deb
Example: count the architecture type of rpm and the corresponding number of packages
[root@rocky8 bin]# cd /misc/cd/ [root@rocky8 cd]# ls AppStream BaseOS EFI images isolinux LICENSE media.repo TRANS.TBL [root@rocky8 cd]# cd BaseOS/ [root@rocky8 BaseOS]# ls Packages repodata [root@rocky8 BaseOS]# cd Packages/ [root@rocky8 Packages]# ls *.rpm |sed -rn 's/(.*)\.([^.]+)\.rpm$/\2/p' |sort |uniq -c 401 i686 226 noarch 1082 x86_64 [root@rocky8 Packages]# ls *.rpm |sed -rn 's/.*\.([^.]+)\.rpm$/\1/p' |sort |uniq -c 401 i686 226 noarch 1082 x86_64 [root@rocky8 Packages]# ls *.rpm |rev |cut -d. -f2|rev|sort |uniq -c 401 i686 226 noarch 1082 x86_64
2.1.4 classification and unpacking
In order to facilitate the management and use of software packages, a large software will be classified and placed in different sub packages.
Classification of packages
- Application-VERSION-ARCH.rpm: main package
- Application-devel-VERSION-ARCH.rpm development sub package
- Application-utils-VERSION-ARHC.rpm other sub packages
- Application-libs-VERSION-ARHC.rpm other sub packages
example:
[root@rocky8 ~]# ls /misc/cd/AppStream/Packages/nginx-* /misc/cd/AppStream/Packages/nginx-1.14.1-9.module+el8.4.0+542+81547229.x86_64.rpm /misc/cd/AppStream/Packages/nginx-1.16.1-2.module+el8.4.0+543+efbf198b.1.x86_64.rpm /misc/cd/AppStream/Packages/nginx-1.18.0-3.module+el8.4.0+544+e40554cf.1.x86_64.rpm /misc/cd/AppStream/Packages/nginx-all-modules-1.14.1-9.module+el8.4.0+542+81547229.noarch.rpm /misc/cd/AppStream/Packages/nginx-all-modules-1.16.1-2.module+el8.4.0+543+efbf198b.1.noarch.rpm /misc/cd/AppStream/Packages/nginx-all-modules-1.18.0-3.module+el8.4.0+544+e40554cf.1.noarch.rpm /misc/cd/AppStream/Packages/nginx-filesystem-1.14.1-9.module+el8.4.0+542+81547229.noarch.rpm /misc/cd/AppStream/Packages/nginx-filesystem-1.16.1-2.module+el8.4.0+543+efbf198b.1.noarch.rpm /misc/cd/AppStream/Packages/nginx-filesystem-1.18.0-3.module+el8.4.0+544+e40554cf.1.noarch.rpm /misc/cd/AppStream/Packages/nginx-mod-http-image-filter-1.14.1-9.module+el8.4.0+542+81547229.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-http-image-filter-1.16.1-2.module+el8.4.0+543+efbf198b.1.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-http-image-filter-1.18.0-3.module+el8.4.0+544+e40554cf.1.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-http-perl-1.14.1-9.module+el8.4.0+542+81547229.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-http-perl-1.16.1-2.module+el8.4.0+543+efbf198b.1.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-http-perl-1.18.0-3.module+el8.4.0+544+e40554cf.1.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-http-xslt-filter-1.14.1-9.module+el8.4.0+542+81547229.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-http-xslt-filter-1.16.1-2.module+el8.4.0+543+efbf198b.1.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-http-xslt-filter-1.18.0-3.module+el8.4.0+544+e40554cf.1.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-mail-1.14.1-9.module+el8.4.0+542+81547229.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-mail-1.16.1-2.module+el8.4.0+543+efbf198b.1.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-mail-1.18.0-3.module+el8.4.0+544+e40554cf.1.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-stream-1.14.1-9.module+el8.4.0+542+81547229.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-stream-1.16.1-2.module+el8.4.0+543+efbf198b.1.x86_64.rpm /misc/cd/AppStream/Packages/nginx-mod-stream-1.18.0-3.module+el8.4.0+544+e40554cf.1.x86_64.rpm
2.1.5 package dependency
There may be dependencies or even circular dependencies between software packages, that is, package A depends on package B, package B depends on package C, and package C depends on package A
When installing a software package, it will fail due to the lack of dependent packages.
Resolve dependency package management tools:
- Front end tools for yum: rpm package manager
- dnf: Fedora 18+ rpm package manager front end management tool, CentOS version 8 instead of yum
- apt: deb package manager front end tool
- rpm front end management tool on zypper: suse
2.1.6 package manager related documents
1. Package file composition (unique to each package)
- Files in package
- Metadata, such as package name, version, dependency, description, etc
- There may be scripts that run when the package is installed or uninstalled
2. Database (public): / var/lib/rpm
- Package name and version
- Dependency
- Function description
- File path and check code information generated after package installation
example:
[root@rocky8 ~]# ll /var/lib/rpm total 72948 -rw-r--r--. 1 root root 1822720 Oct 13 18:33 Basenames -rw-r--r--. 1 root root 8192 Oct 13 18:33 Conflictname -rw-r--r-- 1 root root 270336 Oct 13 18:33 __db.001 -rw-r--r-- 1 root root 81920 Oct 13 18:33 __db.002 -rw-r--r-- 1 root root 1318912 Oct 13 18:33 __db.003 -rw-r--r--. 1 root root 622592 Oct 13 18:33 Dirnames -rw-r--r--. 1 root root 8192 Oct 6 19:16 Enhancename -rw-r--r--. 1 root root 8192 Oct 6 19:17 Filetriggername -rw-r--r--. 1 root root 12288 Oct 13 18:33 Group -rw-r--r--. 1 root root 12288 Oct 13 18:33 Installtid -rw-r--r--. 1 root root 24576 Oct 13 18:33 Name -rw-r--r--. 1 root root 16384 Oct 13 13:54 Obsoletename -rw-r--r--. 1 root root 67461120 Oct 13 18:33 Packages -rw-r--r--. 1 root root 2895872 Oct 13 18:33 Providename -rw-r--r--. 1 root root 8192 Oct 11 19:56 Recommendname -rw-r--r--. 1 root root 155648 Oct 13 18:33 Requirename -rw-r--r--. 1 root root 45056 Oct 13 18:33 Sha1header -rw-r--r--. 1 root root 32768 Oct 13 18:33 Sigmd5 -rw-r--r--. 1 root root 8192 Oct 11 21:01 Suggestname -rw-r--r--. 1 root root 8192 Oct 6 19:16 Supplementname -rw-r--r--. 1 root root 8192 Oct 11 21:01 Transfiletriggername -rw-r--r--. 1 root root 8192 Oct 13 18:33 Triggername [root@rocky8 ~]# rpm -qa #View packages installed on the system iptables-1.8.4-17.el8.x86_64 python3-setuptools-wheel-39.2.0-6.el8.noarch rpm-plugin-selinux-4.14.3-13.el8.x86_64 rocky-release-8.4-26.el8.noarch python3-configobj-5.0.6-11.el8.noarch basesystem-11-5.el8.noarch authselect-libs-1.2.2-2.el8.x86_64 libselinux-2.9-5.el8.x86_64 dbus-glib-0.110-2.el8.x86_64 glibc-2.28-151.el8.x86_64 libsecret-0.18.6-1.el8.x86_64 xz-libs-5.2.4-3.el8.1.x86_64 dracut-squash-049-135.git20210121.el8.x86_64 libgpg-error-1.31-1.el8.x86_64 ...
2.1.7 access to packages
The software package needs to compile and package the source code in advance. The ways to obtain the package are as follows:
2.1.7.1 CD or official website of system release
CentOS image:
https://www.centos.org/download/
http://mirrors.aliyun.com
https://mirrors.huaweicloud.com/
https://mirror.tuna.tsinghua.edu.cn/
http://mirrors.sohu.com
http://mirrors.163.com
Ubuntu image:
http://cdimage.ubuntu.com/releases/
http://releases.ubuntu.com
nginx package:
http://nginx.org/packages/centos/8/x86_64/RPMS/
2.1.7.2 provided by a third party organization
-
Fedora-EPEL: Extra Packages for Enterprise Linux
https://fedoraproject.org/wiki/EPEL
https://mirrors.aliyun.com/epel/
-
Rpmforge: Official Website: http://repoforge.org/ Recommended by RHEL, the package is complete and will be closed soon
-
Community Enterprise Linux Repository: http://www.elrepo.org , support the latest kernel and hardware related packages
2.1.7.3 official website of software project
http://yum.mariadb.org/10.4/centos8-amd64/rpms/
http://repo.mysql.com/yum/mysql-8.0-community/el/8/x86_64/
2.1.7.4 search engine
http://pkgs.org
http://rpmfind.net
http://rpm.pbone.net
https://sourceforge.net/
Note: it is recommended to check the legitimacy, source legitimacy and package integrity of the third-party package
2.1.7.5 self made
Make the source code file into rpm package file by using tools such as rpmbuild and fpm
3. Package manager rpm
Managing packages using the rpm command on CentOS systems
Function:
Installation, uninstall, upgrade, query, verification and database maintenance
3.1 installation
Format:
rpm {-i|--install} [install-options] PACKAGE_FILE...
Options:
-v: verbose -vv: -h: with#Displays the progress of package management execution
Common combinations:
rpm -ivh PACKAGE_FILE ...
rpm package installation [install options]
--test: Test the installation, but do not actually perform the installation, i.e dry run pattern --nodeps: Ignore dependencies --replacepkgs | replacefiles --nosignature: Do not check source legitimacy --nodigest: Do not check package integrity --noscripts: Do not execute package scripts %pre: Pre installation script --nopre %post: Post installation script --nopost %preun: Pre uninstall script --nopreun %postun: Post uninstall script --nopostun
example:
[root@rocky8 ~]# rpm -ivh /misc/cd/BaseOS/Packages/dos2unix-7.4.0-3.el8.x86_64.rpm Verifying... ################################# [100%] Preparing... ################################# [100%] Updating / installing... 1:dos2unix-7.4.0-3.el8 ################################# [100%]
3.2 upgrade and downgrade
rpm package upgrade
rpm {-U|--upgrade} [install-options] PACKAGE_FILE... rpm {-F|--freshen} [install-options] PACKAGE_FILE...
Corresponding options:
upgrade: Upgrade if a legacy package is installed, or install if no legacy package exists freshen: If a legacy package is installed, click upgrade. If there is no legacy package, the upgrade operation will not be performed --oldpackage: Demotion --force: Forced installation
Common combination
rpm -Uvh PACKAGE_FILE ... rpm -Fvh PACKAGE_FILE ...
Upgrade notes:
(1) Do not upgrade the kernel; Linux supports the coexistence of multiple kernel versions, so install the new version of the kernel directly
(2) If the configuration file of the original package has been modified after installation, when upgrading, the same configuration file provided by the new version will not directly overwrite the configuration file of the old version, but will be retained after renaming the new version file (FILENAME.rpmnew)
3.3 package query
rpm {-q|--query} [select-options] [query-options]
[select-options] -a: All packages -f: View which package installation generated the specified file -p rpmfile: Query the package files that have not been installed [query-options] --changelog: query rpm Wrapped changelog -c: Query the configuration file of the program -d: Query program documentation -i: information -l: View all files generated after the specified package is installed --scripts: Package's own script #Related to CAPABILITY --whatprovides CAPABILITY: Query specified CAPABILITY By which package --whatrequires CAPABILITY: Query specified CAPABILITY By which package --provides: Lists the services provided by the specified package CAPABILITY -R: Queries the on which the specified package depends CAPABILITY
Common query usage:
-qa -q PACKAGE -qi PACKAGE -qc PACKAGE -ql PACKAGE -qd PACKAGE -q --scripts PACKAGE -qf FILE -qpi PACKAGE_FILE -qpl PACKAGE_FILE, ...
example:
[root@rocky8 ~]# rpm -q dos2unix dos2unix-7.4.0-3.el8.x86_64 #-q query whether the package is installed [root@rocky8 ~]# rpm -qa |grep dos dos2unix-7.4.0-3.el8.x86_64 [root@rocky8 ~]# rpm -qa "*dos*" dos2unix-7.4.0-3.el8.x86_64 [root@rocky8 ~]# rpm -e dos2unix #-e unloading [root@rocky8 ~]# rpm -q dos2unix package dos2unix is not installed [root@rocky8 ~]# rpm -ivh https://mirrors.nju.edu.cn/rocky/8/BaseOS/x86_64/os/Packages/dos2unix-7.4.0-3.el8.x86_64.rpm Retrieving https://mirrors.nju.edu.cn/rocky/8/BaseOS/x86_64/os/Packages/dos2unix-7.4.0-3.el8.x86_64.rpm Verifying... ################################# [100%] Preparing... ################################# [100%] Updating / installing... 1:dos2unix-7.4.0-3.el8 ################################# [100%] #The network can also be installed [root@rocky8 ~]# rpm -ivh /misc/cd/AppStream/Packages/httpd-2.4.37-39.module+el8.4.0+571+fd70afb1.x86_64.rpm error: Failed dependencies: /etc/mime.types is needed by httpd-2.4.37-39.module+el8.4.0+571+fd70afb1.x86_64 httpd-filesystem is needed by httpd-2.4.37-39.module+el8.4.0+571+fd70afb1.x86_64 httpd-filesystem = 2.4.37-39.module+el8.4.0+571+fd70afb1 is needed by httpd-2.4.37-39.module+el8.4.0+571+fd70afb1.x86_64 httpd-tools = 2.4.37-39.module+el8.4.0+571+fd70afb1 is needed by httpd-2.4.37-39.module+el8.4.0+571+fd70afb1.x86_64 libapr-1.so.0()(64bit) is needed by httpd-2.4.37-39.module+el8.4.0+571+fd70afb1.x86_64 libaprutil-1.so.0()(64bit) is needed by httpd-2.4.37-39.module+el8.4.0+571+fd70afb1.x86_64 mod_http2 is needed by httpd-2.4.37-39.module+el8.4.0+571+fd70afb1.x86_64 system-logos-httpd >= 82.0 is needed by httpd-2.4.37-39.module+el8.4.0+571+fd70afb1.x86_64 #could not be installed [root@rocky8 ~]# rpm -qi httpd package httpd is not installed [root@rocky8 ~]# rpm -q tree package tree is not installed [root@rocky8 ~]# dnf -y install tree [root@rocky8 ~]# rpm -q tree tree-1.7.0-15.el8.x86_64 [root@rocky8 ~]# rpm -qi tree Name : tree Version : 1.7.0 Release : 15.el8 Architecture: x86_64 Install Date: Wed 13 Oct 2021 07:39:43 PM CST Group : Unspecified Size : 108563 License : GPLv2+ Signature : RSA/SHA256, Mon 12 Apr 2021 05:23:54 PM CST, Key ID 15af5dac6d745a60 Source RPM : tree-1.7.0-15.el8.src.rpm Build Date : Mon 12 Apr 2021 04:38:17 PM CST Build Host : ord1-prod-x86build003.svc.aws.rockylinux.org Relocations : (not relocatable) Packager : infrastructure@rockylinux.org Vendor : Rocky URL : http://mama.indstate.edu/users/ice/tree/ Summary : File system tree viewer Description : The tree utility recursively displays the contents of directories in a tree-like format. Tree is basically a UNIX port of the DOS tree utility. #-qi viewing software information [root@rocky8 ~]# rpm -ql tree /usr/bin/tree /usr/lib/.build-id /usr/lib/.build-id/47 /usr/lib/.build-id/47/6e749c56abc75d25e3bc5c29e83507a605fd53 /usr/share/doc/tree /usr/share/doc/tree/LICENSE /usr/share/doc/tree/README /usr/share/man/man1/tree.1.gz #-ql view the file path information in the package [root@rocky8 ~]# rpm -qd tree /usr/share/doc/tree/LICENSE /usr/share/doc/tree/README /usr/share/man/man1/tree.1.gz #-qd query document [root@rocky8 ~]# rpm -qf /etc/issue rocky-release-8.4-26.el8.noarch #-qf query dependent package [root@rocky8 ~]# which tree /usr/bin/tree [root@rocky8 ~]# rm -f /usr/bin/tree [root@rocky8 ~]# rpm -qf /usr/bin/tree tree-1.7.0-15.el8.x86_64 [root@rocky8 ~]# ll /usr/bin/tree ls: cannot access '/usr/bin/tree': No such file or directory #You can still find it after deleting it [root@rocky8 ~]# ll /var/lib/rpm total 65308 -rw-r--r--. 1 root root 1634304 Oct 13 19:39 Basenames -rw-r--r--. 1 root root 8192 Oct 13 19:38 Conflictname -rw-r--r-- 1 root root 270336 Oct 13 19:42 __db.001 -rw-r--r-- 1 root root 81920 Oct 13 19:42 __db.002 -rw-r--r-- 1 root root 1318912 Oct 13 19:42 __db.003 -rw-r--r--. 1 root root 593920 Oct 13 19:39 Dirnames -rw-r--r--. 1 root root 8192 Oct 6 19:16 Enhancename -rw-r--r--. 1 root root 8192 Oct 6 19:17 Filetriggername -rw-r--r--. 1 root root 12288 Oct 13 19:39 Group -rw-r--r--. 1 root root 12288 Oct 13 19:39 Installtid -rw-r--r--. 1 root root 24576 Oct 13 19:39 Name -rw-r--r--. 1 root root 16384 Oct 6 19:22 Obsoletename -rw-r--r--. 1 root root 59822080 Oct 13 19:39 Packages -rw-r--r--. 1 root root 2887680 Oct 13 19:39 Providename -rw-r--r--. 1 root root 8192 Oct 6 19:17 Recommendname -rw-r--r--. 1 root root 151552 Oct 13 19:39 Requirename -rw-r--r--. 1 root root 40960 Oct 13 19:39 Sha1header -rw-r--r--. 1 root root 24576 Oct 13 19:39 Sigmd5 -rw-r--r--. 1 root root 8192 Oct 6 19:17 Suggestname -rw-r--r--. 1 root root 8192 Oct 6 19:16 Supplementname -rw-r--r--. 1 root root 8192 Oct 6 19:17 Transfiletriggername -rw-r--r--. 1 root root 8192 Oct 13 19:38 Triggername #Because he has a database in this directory to record the installation information [root@rocky8 ~]# mv /var/lib/rpm /opt [root@rocky8 ~]# rpm -qf /usr/bin/tree error: file /usr/bin/tree: No such file or directory #If you remove it, you can't check it [root@rocky8 ~]# rpm -qa [root@rocky8 ~]# rpm -ivh /misc/cd/BaseOS/Packages/dos2unix-7.4.0-3.el8.x86_64.rpm warning: /misc/cd/BaseOS/Packages/dos2unix-7.4.0-3.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 6d745a60: NOKEY error: Failed dependencies: libc.so.6()(64bit) is needed by dos2unix-7.4.0-3.el8.x86_64 libc.so.6(GLIBC_2.2.5)(64bit) is needed by dos2unix-7.4.0-3.el8.x86_64 libc.so.6(GLIBC_2.3.4)(64bit) is needed by dos2unix-7.4.0-3.el8.x86_64 libc.so.6(GLIBC_2.4)(64bit) is needed by dos2unix-7.4.0-3.el8.x86_64 rtld(GNU_HASH) is needed by dos2unix-7.4.0-3.el8.x86_64 #You can't check or install the software [root@rocky8 ~]# rpm -ivh /misc/cd/BaseOS/Packages/tree-1.7.0-15.el8.x86_64.rpm Verifying... ################################# [100%] Preparing... ################################# [100%] Updating / installing... 1:tree-1.7.0-15.el8 ################################# [100%] [root@rocky8 ~]# rpm -ivh /misc/cd/BaseOS/Packages/tree-1.7.0-15.el8.x86_64.rpm --force Verifying... ################################# [100%] Preparing... ################################# [100%] Updating / installing... 1:tree-1.7.0-15.el8 ################################# [100%] #--force forced installation [root@rocky8 ~]# rpm -q --scripts tree [root@rocky8 ~]# rpm -q --scripts bash postinstall scriptlet (using <lua>): nl = '\n' sh = '/bin/sh'..nl bash = '/bin/bash'..nl f = io.open('/etc/shells', 'a+') if f then local shells = nl..f:read('*all')..nl if not shells:find(nl..sh) then f:write(sh) end if not shells:find(nl..bash) then f:write(bash) end f:close() end postuninstall scriptlet (using <lua>): -- Run it only if we are uninstalling if arg[2] == "0" then t={} for line in io.lines("/etc/shells") do if line ~= "/bin/bash" and line ~= "/bin/sh" then table.insert(t,line) end end f = io.open("/etc/shells", "w+") for n,line in pairs(t) do f:write(line.."\n") end f:close() end #rpm -q --scripts query whether the package has scripts [root@rocky8 ~]# rpm -qpl /misc/cd/BaseOS/Packages/tree-1.7.0-15.el8.x86_64.rpm /usr/bin/tree /usr/lib/.build-id /usr/lib/.build-id/47 /usr/lib/.build-id/47/6e749c56abc75d25e3bc5c29e83507a605fd53 /usr/share/doc/tree /usr/share/doc/tree/LICENSE /usr/share/doc/tree/README /usr/share/man/man1/tree.1.gz [root@rocky8 ~]# rpm -ql /misc/cd/BaseOS/Packages/tree-1.7.0-15.el8.x86_64.rpm /usr/bin/tree /usr/lib/.build-id /usr/lib/.build-id/47 /usr/lib/.build-id/47/6e749c56abc75d25e3bc5c29e83507a605fd53 /usr/share/doc/tree /usr/share/doc/tree/LICENSE /usr/share/doc/tree/README /usr/share/man/man1/tree.1.gz #centos 8 can be viewed directly through - ql without adding the p option #Query the files contained in the file [root@centos7 ~]# ls /misc/cd/Packages/tree-1.6.0-10.el7.x86_64.rpm /misc/cd/Packages/tree-1.6.0-10.el7.x86_64.rpm [root@centos7 ~]# rpm -ivh /misc/cd/Packages/tree-1.6.0-10.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:tree-1.6.0-10.el7 ################################# [100%] [root@centos7 ~]# rpm -ql /misc/cd/Packages/tree-1.6.0-10.el7.x86_64.rpm package /misc/cd/Packages/tree-1.6.0-10.el7.x86_64.rpm is not installed [root@centos7 ~]# rpm -qpl /misc/cd/Packages/tree-1.6.0-10.el7.x86_64.rpm /usr/bin/tree /usr/share/doc/tree-1.6.0 /usr/share/doc/tree-1.6.0/LICENSE /usr/share/doc/tree-1.6.0/README /usr/share/man/man1/tree.1.gz #You can only check the files contained in the package file by adding the p option to centos 7
3.4 package unloading
Format:
rpm {-e|--erase} [--allmatches] [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME ...
Note: when the package is unloaded, the corresponding configuration file will not be deleted and will be retained in the form of FILENAME.rpmsave
Example: forcibly delete the rpm package and restore it
[root@rocky8 ~]# rpm -e rpm --nodeps [root@rocky8 ~]# rpm -bash: /usr/bin/rpm: No such file or directory [root@rocky8 ~]# dnf -y install rpm error: Unable to open /usr/lib/rpm/rpmrc for reading: No such file or directory. Traceback (most recent call last): File "/usr/bin/dnf", line 57, in <module> from dnf.cli import main File "/usr/lib/python3.6/site-packages/dnf/__init__.py", line 30, in <module> import dnf.base File "/usr/lib/python3.6/site-packages/dnf/base.py", line 32, in <module> from dnf.comps import CompsQuery File "/usr/lib/python3.6/site-packages/dnf/comps.py", line 27, in <module> from dnf.exceptions import CompsError File "/usr/lib/python3.6/site-packages/dnf/exceptions.py", line 22, in <module> import dnf.util File "/usr/lib/python3.6/site-packages/dnf/util.py", line 29, in <module> import dnf.callback File "/usr/lib/python3.6/site-packages/dnf/callback.py", line 22, in <module> import dnf.yum.rpmtrans File "/usr/lib/python3.6/site-packages/dnf/yum/rpmtrans.py", line 26, in <module> import rpm File "/usr/lib64/python3.6/site-packages/rpm/__init__.py", line 39, in <module> from rpm.transaction import * File "/usr/lib64/python3.6/site-packages/rpm/transaction.py", line 5, in <module> from rpm._rpm import ts as TransactionSetCore ImportError: cannot import name 'ts' #Recovery process #Restart and enter the rescue mode #mkdir /mnt/cdrom #mount /dev/sr0 /mnt/cdrom #rpm -ivh /mnt/cdrom/BaseOS/Packages/rpm-4.14.3-13.el8.x86_64.rpm --root=/mnt/sysimage #reboot
3.5 package verification
When installing a package, the system will also check whether the source of the package is legal
Check the integrity and signature of the package
rpm -K|--checksig rpmfile
example:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 rpm -qa "gpg-pubkey*"
Example: CentOS 8
[root@rocky8 ~]# rpm -K /misc/cd/AppStream/Packages/httpd-2.4.37-39.module+el8.4.0+571+fd70afb1.x86_64.rpm /misc/cd/AppStream/Packages/httpd-2.4.37-39.module+el8.4.0+571+fd70afb1.x86_64.rpm: digests SIGNATURES NOT OK #Prompt: no key imported [root@rocky8 ~]# cat /etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial -----BEGIN PGP PUBLIC KEY BLOCK----- mQINBGAofzYBEAC6yS1azw6f3wmaVd//3aSy6O2c9+jeetulRQvg2LvhRRS1eNqp /x9tbBhfohu/tlDkGpYHV7diePgMml9SZDy1sKlI3tDhx6GZ3xwF0fd1vWBZpmNk D9gRkUmYBeLotmcXQZ8ZpWLicosFtDpJEYpLUhuIgTKwt4gxJrHvkWsGQiBkJxKD u3/RlL4IYA3Ot9iuCBflc91EyAw1Yj0gKcDzbOqjvlGtS3ASXgxPqSfU0uLC9USF uKDnP2tcnlKKGfj0u6VkqISliSuRAzjlKho9Meond+mMIFOTT6qp4xyu+9Dj3IjZ IC6rBXRU3xi8z0qYptoFZ6hx70NV5u+0XUzDMXdjQ5S859RYJKijiwmfMC7gZQAf OkdOcicNzen/TwD/slhiCDssHBNEe86Wwu5kmDoCri7GJlYOlWU42Xi0o1JkVltN D8ZId+EBDIms7ugSwGOVSxyZs43q2IAfFYCRtyKHFlgHBRe9/KTWPUrnsfKxGJgC Do3Yb63/IYTvfTJptVfhQtL1AhEAeF1I+buVoJRmBEyYKD9BdU4xQN39VrZKziO3 hDIGng/eK6PaPhUdq6XqvmnsZ2h+KVbyoj4cTo2gKCB2XA7O2HLQsuGduHzYKNjf QR9j0djjwTrsvGvzfEzchP19723vYf7GdcLvqtPqzpxSX2FNARpCGXBw9wARAQAB tDNSZWxlYXNlIEVuZ2luZWVyaW5nIDxpbmZyYXN0cnVjdHVyZUByb2NreWxpbnV4 Lm9yZz6JAk4EEwEIADgWIQRwUcRwqSn0VM6+N7cVr12sbXRaYAUCYCh/NgIbDwUL CQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRAVr12sbXRaYLFmEACSMvoO1FDdyAbu 1m6xEzDhs7FgnZeQNzLZECv2j+ggFSJXezlNVOZ5I1I8umBan2ywfKQD8M+IjmrW k9/7h9i54t8RS/RN7KNo7ECGnKXqXDPzBBTs1Gwo1WzltAoaDKUfXqQ4oJ4aCP/q /XPVWEzgpJO1XEezvCq8VXisutyDiXEjjMIeBczxb1hbamQX+jLTIQ1MDJ4Zo1YP zlUqrHW434XC2b1/WbSaylq8Wk9cksca5J+g3FqTlgiWozyy0uxygIRjb6iTzKXk V7SYxeXp3hNTuoUgiFkjh5/0yKWCwx7aQqlHar9GjpxmBDAO0kzOlgtTw//EqTwR KnYZLig9FW0PhwvZJUigr0cvs/XXTTb77z/i/dfHkrjVTTYenNyXogPtTtSyxqca 61fbPf0B/S3N43PW8URXBRS0sykpX4SxKu+PwKCqf+OJ7hMEVAapqzTt1q9T7zyB QwvCVx8s7WWvXbs2d6ZUrArklgjHoHQcdxJKdhuRmD34AuXWCLW+gH8rJWZpuNl3 +WsPZX4PvjKDgMw6YMcV7zhWX6c0SevKtzt7WP3XoKDuPhK1PMGJQqQ7spegGB+5 DZvsJS48Ip0S45Qfmj82ibXaCBJHTNZE8Zs+rdTjQ9DS5qvzRA1sRA1dBb/7OLYE JmeWf4VZyebm+gc50szsg6Ut2yT8hw== =AiP8 -----END PGP PUBLIC KEY BLOCK----- [root@rocky8 ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial #Import key [root@rocky8 ~]# rpm -K /misc/cd/AppStream/Packages/httpd-2.4.37-39.module+el8.4.0+571+fd70afb1.x86_64.rpm /misc/cd/AppStream/Packages/httpd-2.4.37-39.module+el8.4.0+571+fd70afb1.x86_64.rpm: digests signatures OK #We can find it now [root@rocky8 ~]# rpm -qa "gpg-pubkey*" #Check whether the key is imported gpg-pubkey-6d745a60-60287f36 [root@rocky8 ~]# rpm -qi gpg-pubkey-6d745a60-60287f36 #View key information Name : gpg-pubkey Version : 6d745a60 Release : 60287f36 Architecture: (none) Install Date: Wed 06 Oct 2021 07:22:44 PM CST Group : Public Keys Size : 0 License : pubkey Signature : (none) Source RPM : (none) Build Date : Sun 14 Feb 2021 09:39:02 AM CST Build Host : localhost Relocations : (not relocatable) Packager : Release Engineering <infrastructure@rockylinux.org> Summary : gpg(Release Engineering <infrastructure@rockylinux.org>) Description : -----BEGIN PGP PUBLIC KEY BLOCK----- Version: rpm-4.14.3 (NSS-3) mQINBGAofzYBEAC6yS1azw6f3wmaVd//3aSy6O2c9+jeetulRQvg2LvhRRS1eNqp /x9tbBhfohu/tlDkGpYHV7diePgMml9SZDy1sKlI3tDhx6GZ3xwF0fd1vWBZpmNk D9gRkUmYBeLotmcXQZ8ZpWLicosFtDpJEYpLUhuIgTKwt4gxJrHvkWsGQiBkJxKD u3/RlL4IYA3Ot9iuCBflc91EyAw1Yj0gKcDzbOqjvlGtS3ASXgxPqSfU0uLC9USF uKDnP2tcnlKKGfj0u6VkqISliSuRAzjlKho9Meond+mMIFOTT6qp4xyu+9Dj3IjZ IC6rBXRU3xi8z0qYptoFZ6hx70NV5u+0XUzDMXdjQ5S859RYJKijiwmfMC7gZQAf OkdOcicNzen/TwD/slhiCDssHBNEe86Wwu5kmDoCri7GJlYOlWU42Xi0o1JkVltN D8ZId+EBDIms7ugSwGOVSxyZs43q2IAfFYCRtyKHFlgHBRe9/KTWPUrnsfKxGJgC Do3Yb63/IYTvfTJptVfhQtL1AhEAeF1I+buVoJRmBEyYKD9BdU4xQN39VrZKziO3 hDIGng/eK6PaPhUdq6XqvmnsZ2h+KVbyoj4cTo2gKCB2XA7O2HLQsuGduHzYKNjf QR9j0djjwTrsvGvzfEzchP19723vYf7GdcLvqtPqzpxSX2FNARpCGXBw9wARAQAB tDNSZWxlYXNlIEVuZ2luZWVyaW5nIDxpbmZyYXN0cnVjdHVyZUByb2NreWxpbnV4 Lm9yZz6JAk4EEwEIADgWIQRwUcRwqSn0VM6+N7cVr12sbXRaYAUCYCh/NgIbDwUL CQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRAVr12sbXRaYLFmEACSMvoO1FDdyAbu 1m6xEzDhs7FgnZeQNzLZECv2j+ggFSJXezlNVOZ5I1I8umBan2ywfKQD8M+IjmrW k9/7h9i54t8RS/RN7KNo7ECGnKXqXDPzBBTs1Gwo1WzltAoaDKUfXqQ4oJ4aCP/q /XPVWEzgpJO1XEezvCq8VXisutyDiXEjjMIeBczxb1hbamQX+jLTIQ1MDJ4Zo1YP zlUqrHW434XC2b1/WbSaylq8Wk9cksca5J+g3FqTlgiWozyy0uxygIRjb6iTzKXk V7SYxeXp3hNTuoUgiFkjh5/0yKWCwx7aQqlHar9GjpxmBDAO0kzOlgtTw//EqTwR KnYZLig9FW0PhwvZJUigr0cvs/XXTTb77z/i/dfHkrjVTTYenNyXogPtTtSyxqca 61fbPf0B/S3N43PW8URXBRS0sykpX4SxKu+PwKCqf+OJ7hMEVAapqzTt1q9T7zyB QwvCVx8s7WWvXbs2d6ZUrArklgjHoHQcdxJKdhuRmD34AuXWCLW+gH8rJWZpuNl3 +WsPZX4PvjKDgMw6YMcV7zhWX6c0SevKtzt7WP3XoKDuPhK1PMGJQqQ7spegGB+5 DZvsJS48Ip0S45Qfmj82ibXaCBJHTNZE8Zs+rdTjQ9DS5qvzRA1sRA1dBb/7OLYE JmeWf4VZyebm+gc50szsg6Ut2yT8hw== =AiP8 -----END PGP PUBLIC KEY BLOCK-----
Example: verifying package files
[root@rocky8 ~]# cp /misc/cd/BaseOS/Packages/tree-1.7.0-15.el8.x86_64.rpm /data [root@rocky8 ~]# cd /data [root@rocky8 data]# ll total 60 -r--r--r-- 1 root root 59636 Oct 13 20:40 tree-1.7.0-15.el8.x86_64.rpm [root@rocky8 data]# echo >>tree-1.7.0-15.el8.x86_64.rpm [root@rocky8 data]# ll total 60 -r--r--r-- 1 root root 59637 Oct 13 20:40 tree-1.7.0-15.el8.x86_64.rpm [root@rocky8 data]# rpm -K /data/tree-1.7.0-15.el8.x86_64.rpm /data/tree-1.7.0-15.el8.x86_64.rpm: DIGESTS SIGNATURES NOT OK #If the package is changed, it can still be checked. It checks the signature and does not verify the integrity of the package
When installing the software, the metadata of each file in the package, such as size, permission, owner, time, etc., will be recorded in the database related to rpm, which can be used to check whether the files in the package are different from those in the original installation
rpm {-V|--verify} [select-options] [verify-options] #Example: [root@centos8 ~]#rpm -V centos-release S.5....T. c /etc/issue S file Size differs M Mode differs (includes permissions and file type) 5 digest (formerly MD5 sum) differs D Device major/minor number mismatch L readLink(2) path mismatch U User ownership differs G Group ownership differs T mTime differs P capabilities differ . (spot) Indicates that the characters represented by the current position have the same meaning c The location indicates the file type c configuration file d File data file g The file does not belong to a file(Few cases) l License file(license file) r readme file(READ ME)
example:
[root@rocky8 data]# rpm -ql tree /usr/bin/tree /usr/lib/.build-id /usr/lib/.build-id/47 /usr/lib/.build-id/47/6e749c56abc75d25e3bc5c29e83507a605fd53 /usr/share/doc/tree /usr/share/doc/tree/LICENSE /usr/share/doc/tree/README /usr/share/man/man1/tree.1.gz [root@rocky8 data]# ll /usr/share/doc/tree/README -rw-r--r-- 1 root root 5620 Apr 22 2014 /usr/share/doc/tree/README [root@rocky8 data]# chown raymond /usr/share/doc/tree/README [root@rocky8 data]# ll /usr/share/doc/tree/README -rw-r--r-- 1 raymond root 5620 Apr 22 2014 /usr/share/doc/tree/README [root@rocky8 data]# rpm -V tree .....U... d /usr/share/doc/tree/README #U indicates that the owner of the file has been changed #-V view file integrity [root@rocky8 data]# chown root /usr/share/doc/tree/README [root@rocky8 data]# rpm -V tree #Not after recovery
3.6 database
The information generated during the installation of the rpm package is placed in the rpm database
/var/lib/rpm
You can rebuild the database
rpm {--initdb|--rebuilddb} initdb: Initialization. If the database does not exist in advance, it will be created. Otherwise, no operation will be performed rebuilddb: Rebuild the database index directory of the installed package header