------------------------------------------------------------------------------- Get various variables from rpm I have found no FAST solution for $releasever This is especially a problem for RHEL Servers which includes a 'Server' Varient, of say "7Server" for large RHEL 7 installs Few solutions below generate that specific string correctly. rpm -E %fedora # fedora version (eg: 38 ) rpm -E %rhel # RHEL release version (Eg: 7, 8, 9) lsb_release -rs | cut -d. -f1 # The release version (RHEL: 7, 8, 9 Fedora: 38) # this works on all systems tried! basearch=$( uname -m ) # should be -i but not on fedora, -m works! basearch=$( rpm -E '%{_arch}' ) basearch=$( rpm --query --queryformat '%{ARCH}\n' "kernel-$(uname --kernel-release)" ) # Using yum-debug-dump works (getting "7Server") but can be slow... releasever=$( yum-debug-dump --norepos /dev/stdout | grep -oP '^ releasever:\s*\K\S+' ) basearch=$( yum-debug-dump --norepos /dev/stdout | grep -oP '^ basearch:\s*\K\S+' ) --- On "dnf" systems... # python get both $releasever and $basearch ... eval $( python3 -c 'import dnf; b = dnf.Base(); print( "basearch=%s\nreleasever=%s" % (b.conf.basearch, b.conf.releasever) )' ) # depends on the repos... yum-config-manager --dump-variables | grep 'releasever = ' yum-config-manager --dump-variables | grep 'basearch = ' On "yum" systems.... releasever=$( rpm -q --provides $(rpm -q --whatprovides /etc/system-release) | grep -oP 'releasever.*=\s\K\S+' ) yum version nogroups # extract it from " {releasever}/{basearch} " # depends on the repos... yum-config-manager | grep 'releasever = ' yum-config-manager | grep 'basearch = ' # python releasever=$( python -c 'import yum; yb=yum.YumBase( ); yb.doConfigSetup(init_plugins=False ); print(yb.conf.yumvar["releasever"])' ) # alternative (all variables) python -c 'import yum, pprint; yb = yum.YumBase( ); pprint.pprint(yb.conf.yumvar, width=1)' ------------------------------------------------------------------------------- DNF / YUM / RPM General What is installed locally dnf -C list installed rpm -qa --queryformat '%{NAME}-%{VERSION}-%{RELEASE}:%{SUMMARY}\n' | sort | awk -F: '{printf "%-30s %s\n",$1,$2}' What is on a specific repo dnf --disablerepo=\* --enablerepo=adobe\* list available Local Install (yum also gets dependencies) dnf localinstall /path/to/package-1.0.0-1.i386.rpm Dependencies (requires and is required by) rpm -q --requires xyzzy rpm -q --whatrequires xyzzy What package will install file or library "xyzzy" (if needed by another package). Install the rpmdb-redhat package then use rpm -q --whatprovides xyzzy rpm -q --redhatprovides xyzzy What is a package dnf info xyzzy List other versions of a pack (not just latest) dnf --showduplicates list docker-ce dnf history list # When did it install dnf history info {transaction-id} # more info about that action What files are in the package (without installing) repoquery -l xyzzy dnf repoquery -l xyzzy Problem Packages... Resolve any ".rpmnew" and ".rpmsave" files created yum install rpmconf rpmconf -a See packages with broken dependencies dnf repoquery --unsatisfied See duplicated packages dnf repoquery --duplicated Remove unneeded packages dnf autoremove Reinstall package dnf reinstall httpd Install History dnf history dnf history info 13 dnf history undo 13 dnf history redo 13 ------------------------------------------------------------------------------- Yum Variables This is set in... /etc/yum/vars/releasever ------------------------------------------------------------------------------- DNF Metadata cache Manual... You can prevent a metadata cache using -C (if already downloaded) dnf -C list ansible-\* Or force a download using dnf --refresh list ansible-\* --- https://www.getpagespeed.com/server-setup/ fixing-dnf-annoyances-in-centos-rhel-usability-or-bandwidth-choose-your-destiny Unlimited Bandwidth.... You want to keep the cache totall fresh at all times. First enable auto-matic refresh... systemctl enable --now dnf-makecache.timer List it with systemctl status dnf-makecache.timer # LONG LINE but includes time of last run systemctl list-timers -l dnf-makecache.timer Fix a bug in CentOS/RHEL 8 (metadata_timer_sync default is 3 hours!) max_parallel_downloads defaults to 3 vi /etc/dnf/dnf.conf metadata_timer_sync=3600 max_parallel_downloads=10 Alternative... Make timer run once every 3 hours This DOES NOT work, file gets reset on patching sed -i '/^OnUnitInactiveSec=.*$/s//OnUnitInactiveSec=1h/' \ /usr/lib/systemd/system/dnf-makecache.timer systemctl daemon-reload systemctl enable --now dnf-makecache.timer Limited Bandwidth... You do not want to refresh the cache regular, only when needed. First disable the timer systemctl disable dnf-makecache.timer For gnome user disable PackageKit updates. gsettings set org.gnome.software download-updates false and prevent metadata refreshes (default 3hr) NOTE: This also prevents 'makecache and the timer from working vi /etc/dnf/dnf.conf metadata_expire=-1 When you need to use either first run dnf clean expire-cache or dnf clean all or include --refresh in the DNF command. dnf update --refresh dnf install --refresh {package} Once a day update ... Limit updates vi /etc/dnf/dnf.conf # DNF only to update once a day metadata_expire=86400 max_parallel_downloads=10 Slow down the the timer (from 1hr to once a day) This DOES NOT work, file gets reset on patching # sed -i '/^OnUnitInactiveSec=,*$/s//OnUnitInactiveSec=1d/' \ # /usr/lib/systemd/system/dnf-makecache.timer # systemctl daemon-reload # systemctl enable --now dnf-makecache.timer ------------------------------------------------------------------------------- General RPM List package and info rpm -qilp {package}.rpm What dependencies (requirements) does it need rpm -qRp {package}.rpm Install with progress bar rpm -ihv {package}.rpm Follow dependency's (in same directory, using "rpmdb" database) rpm -hiv --aid {package}.rpm List permissions of files in package rpm -q --qf "[%-15{=NAME} %-36{FILENAMES} %{FILEMODES:perms}\n]" \ {package} or -p {package}.rpm Reset file permissions of installed Package rpm --setperms {package} Reset ownership rpm --setugids {package} Reset permissions on all install packages for p in $(rpm -qa); do rpm --setperms $p; done for p in $(rpm -qa); do rpm --setugids $p; done List files and there install permissions form package rpm -q --dump {package} rpm -qp --dump {package.rpm} Checksum installed files test string: S:size M:mode(perms/type) 5:md5sum T:time file type: c:config d:doc r:readme rpm -Va {package} # or checksum all packages (takes a long time) for p in $(rpm -qa); do rpm -Va $p; done # check the whole package that this file belongs too! rpm -Vf {file} Rebuild the 'installed' database rpm -vv --rebuilddb ------------------------------------------------------------------------------- RPM GPG keys Import the keys on system rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY* List the keys rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release} --> %{summary}\n' Erase a key rpm -e gpg-pubkey-e15e78f4-55310c0e ------------------------------------------------------------------------------- General YUM Clean up Cache sudo dnf clean all sudo dnf makecache Yum Variables python -c 'import yum, pprint; yb = yum.YumBase(); pprint.pprint(yb.conf.yumvar, width=1)' Other than system variables you can set others in directory /etc/yum/vars EG: echo "AT" > /etc/yum/vars/foorelease https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/sec-using_yum_variables On just one repo yum --disablerepo=\* --enablerepo=epel list available yum --disablerepo=\* --enablerepo=google-chrome list available yum --disablerepo=\* --enablerepo=adobe\* list available What is installed (marks as user installed and not auto-removable) yum list installed What packages the user installed (not dependencies) yum history userinstalled List available packages yum list xine yum list '*mp3*' yum grouplist Install package_group sudo yum groupinstall 'MySQL Database' --- Update All sudo yum update Update just one package and dependancies sudo yum update xine Remove the package and any dependancys sudo yum remove rhythmbox Download the RPM package (to install on another system) yum download httpd Local copy install sudo yum localinstall ImageMagick-6.2.5-5.i386.rpm List recent history of installs yum history | head Remove a installs using history yum history undo 118 --- List description for a package yum info junit What files are in the package (without installing) repoquery -l xv yum repoquery -l xv search for string in package name and description yum search mp3 --- look for a package providing a library yum provides */{file} yum xkbcommon.h */{file} Turn on auto updates... chkconfig yum on service yum start NOTE: this does not actually run a service, it just enables the "/etc/cron.daily/yum.conf" cron job to auto-update the system at 4am ------------------------------------------------------------------------------- Manual Repo handling... * get baseurl of repo Substitute $basearch => x86_64 * Append "repodata/repomd.xml" and download that * Look for "primary" and append that to the baseurl downloading the "primary.xml.gz" * That gives you the list of RPMs, available, watch for version numbers to add to the baseurl to download zgrep "location.*$package" primary.xml.gz Manual RPM handling * unpack the RPM using "rpm2cpio" (alternative is "alien") rpm2cpio.sh package.rpm > payload * format of payload file payload * uncompress if needed xz -d payload * unpack cpio -id payload ------------------------------------------------------------------------------- Downgrade Packages dnf downgrade firefox dependency hell rpm -Uvh --oldpackage packagename When updating skip packages and associated packages dnf --exclude=firefox --skip-broken update You will also want to add a line to /etc/yum.conf vi /etc/yum.conf exclude=firefox ------------------------------------------------------------------------------- DNF install on different partition (no ISO or USB boot disk needed) https://antofthy.gitlab.io/info/usage/fedora_on_new_partition.txt ------------------------------------------------------------------------------- RPM from SRPM sources Build a RPM directly from a source RPM rpmbuild --rebuild {package}.src.rpm Then install rpm -ihv ~/rpmbuild/RPMS/i386/{package}.i386.rpm NOTE: dnf can NOT download SRPM packages at this time. Build step by step (using --short-circuit) package=??? # get sources yum-builddep $package rpm -ihv $package-*.src.rpm # %prep -- extract / apply all patches -- in /usr/src/redhat/BUILD rpmbuild -bp ~/rpmbuild/SPECS/$package.spec # %files -- check all prerequisite files are avaiable rpmbuild -bl ~/rpmbuild/SPECS/$package.spec # %build -- compile the binaries patched (above and manually) sources rpmbuild --short-circuit -bc ~/rpmbuild/SPECS/$package.spec # %install -- install the just built binaries (into a fake root?) rpmbuild --short-circuit -bi ~/rpmbuild/SPECS/$package.spec # build the appropriate RPM's from installed package rpmbuild --short-circuit -bb ~/rpmbuild/SPECS/$package.spec # --- # Rebuild SRPM source package (after changes to patching or sources tar) rpmbuild -bs ~/rpmbuild/SPECS/$package.spec Clean out the whole source area rm -rf ~/rpmbuild Build a RPM that will install into a different prefix??? -- untested rpmbuild --define="_prefix /opt/MyApps/ImageMagick" spec_file To prevent RPM from stripping debug information either Add to "spec" file %define __os_install_post %{nil} or in the install section export this variable export DONT_STRIP=1 or disable the script that calls it On fedora systems that is /usr/lib/rpm/find-debuginfo.sh ------------------------------------------------------------------------------- Unpack RPM without installing... mkdir t cd t rpm2cpio .../RPM.rpm | cpio -idmv ------------------------------------------------------------------------------- RPM from TAR source Found on GQview web site, how this workes is another matter. When complete, the new binary package can be found in /usr/src/redhat/RPMS/i386 rpm -tb xxx-x.x.x.tar.gz ------------------------------------------------------------------------------- Create 'os' dnf repository from DVD echo ' | [fedora-dvd] | name=Fedora DVD (for $releasever) | baseurl=file:///media/Fedora%20$releasever%20i386%20DVD/ | enabled=0 ' | sed -n '/^ *|/!d; s/^ *|//; s/^ //; p' > FILE dnf --disablerepo=\* --enablerepo=fedora-dvd list available Install original kernel from DVD dnf --disablerepo=\* --enablerepo=fedora-dvd install \ kernel kernel-PAE kernel-headers kernel-devel kernel-PAE-devel ------------------------------------------------------------------------------- Errors and Problems Error: rpmdb open failed From... https://unix.stackexchange.com/questions/198703/ rm -rf /var/lib/rpm/__db* db_verify /var/lib/rpm/Packages rpm --rebuilddb yum clean all # Verify echo n | yum update # If you get "unfinished transactions remaining.." yum-complete-transaction --cleanup-only --- Error: "Unable to upload Enabled Repositories Report" yum remove -y katello-host-tools --- Error: "This system is not registered with RHN Classic..." subscription-manager config --rhsm.auto_enable_yum_plugins=0 sed -i 's/enabled *= *1/enabled = 0/g' /etc/yum/pluginconf.d/rhnplugin.conf --- Error: "nothing provides module(perl:5.26)" This is on RHEL8 Generally seen with a command like: yum list installed >/dev/null Caused by minimal "perl" now being called "perl-interpreter" Check using: dnf module list perl the '[d]' flag should be enough bit isn't, so add a '[e]' (enable) flag dnf module enable -y perl --- Error: "/var/lib/rpm/Packages: unexpected file type or format" The /var/lib/rpm/Packages file is completely corrupt, or zero in size Copy a valid version of the file from some other (simular) machine Then run this to rebuild fully... rpm -vv --rebuilddb --- Packages no longer available package-cleanup --orphans --- Duplicate packages... Generally caused by yum interuptions https://access.redhat.com/solutions/3924551 Find repoquery --duplicated # both old and new package-cleanup --dupes # both old and new repoquery --duplicated --latest-limit=-1 -q # just list old version Deleted duplicate yum remove sed-4.5-2.el8 OR just from database rpm -ev --justdb --nodeps sed-4.5-2.el8 BEST WAY, but ALL duplicates (except kernel), and reinstall newest dnf remove --duplicates package-cleanup --cleandupes Check existing RPM # prelink -ua rpm -Va sed-4.5-5.el8 fix a problem yum reinstall sed-4.5-5.el8 -------------------------------------------------------------------------------