how to reset centos 8 without losing data?

Resetting CentOS 8 without losing data isn’t the same as a full reinstall. You can achieve a clean system state while preserving user files and partitions. Here’s how you can do it safely and effectively.

Backup Critical Configuration Files

Before doing anything, back up key configuration files. Resetting may overwrite these, even if user data is preserved.

mkdir /root/config-backup
cp -r /etc/ssh /etc/httpd /etc/nginx /etc/php* /etc/my.cnf* /etc/fstab /root/config-backup

This ensures you don’t lose SSH settings, web server configs, or your fstab entries.

Identify and Preserve Data Partitions

If your /home directory or data is on a separate partition, you’re already halfway safe. Use lsblk or df -h to identify your partitions:

lsblk

Check if /home is a separate mount point. If it’s not, you should move important files to a different partition, mounted drive, or external storage.

To mount an external disk:

mkdir /mnt/usb
mount /dev/sdb1 /mnt/usb
cp -r /home/youruser/* /mnt/usb

Resetting via DNF Group Reinstall

You can reinstall the base system packages using DNF groups. This keeps your data untouched but resets all system packages.

dnf group reinstall "Minimal Install"

Or for a full reset of most packages:

dnf reinstall \*

This might take a while but will restore system packages without formatting the disk.

Remove Unwanted Packages and User-Created Files

Clean out third-party or user-installed packages:

dnf list installed | grep @ | cut -d' ' -f1 | xargs dnf remove -y

You can also manually remove leftover service files in /etc/systemd/system/ or old logs:

rm -rf /etc/systemd/system/old-service.service
rm -rf /var/log/*

Reset SELinux Contexts and Permissions

If files have weird permissions or broken SELinux labels, restore them:

restorecon -R -v /

Reset file permissions:

chmod -R 755 /home
chown -R youruser:youruser /home/youruser

Clean System and Reboot

Clear caches and logs to reclaim space and finish the reset:

dnf clean all
rm -rf /tmp/*

Reboot your system:

reboot

This method avoids full reinstallation while getting you a cleaner system. It’s perfect for when things go wrong but you don’t want to risk wiping out your personal or project files.

Share:

More Posts

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments