0

I used rsync -aiiP to copy the /etc from my old laptop to the /etc of my new laptop. After locking the screen and trying to log back in, my password no longer works. I rebooted but it gets stuck on the loading screen and my new user account never appears, instead I am entered into emergency mode where I can use root on the command line to navigate the filesystem.

I think the problem could be that I replaced /etc/shadow and /etc/passwd on the new system with the ones from the old system. The user account on my old system and new system are different.

How do I get access to my user account again and what caused this problem?

I'm thinking of freshly installing fedora 37 on a different laptop and then copying /etc to the broken laptop using root in emergency mode, but I don't know if there's a better way.

dr_
  • 28,763
  • 21
  • 89
  • 133
bit
  • 1,076
  • 2
  • 17
  • 36
  • 2
    There's quite a lot of files that you can't transfer between systems from `/etc` "just like that", including network configurations, configured mount points, mail settings, host SSH keys and config files for other packages, and a number of other things. The best option would be to restore from backup. – Kusalananda Jan 30 '23 at 23:47
  • @Kusalananda thanks, I see. What exactly do you mean by restore from backup? – bit Jan 31 '23 at 00:10
  • 1
    You've never should have done that. `/etc` is highly dependent on installed packages and different systems mustn't be synchronized unless you're 100% sure you know what you're doing. This answer could help you: https://unix.stackexchange.com/a/731966/260833 only instead of `/var` you should use `/etc`. Mounting `var` is not necessary of course. – Artem S. Tashkinov Jan 31 '23 at 00:55
  • @ArtemS.Tashkinov thanks. Can you write an answer please? I'm not sure how to use the answer you linked. I'm also not sure how to mount `/etc`, can you explain? – bit Jan 31 '23 at 02:23
  • 1. Boot in recovery 2. chroot into your system 3. `restorecon -rv /etc` 4. `reboot` – Artem S. Tashkinov Jan 31 '23 at 02:53
  • @ArtemS.Tashkinov if I don't have a backup of /etc will ` restorecon -rv /etc` still work? – bit Feb 01 '23 at 18:29
  • @ArtemS.Tashkinov is it necessary to `chroot` after entering rescue/recovery mode since I am already at the root directory of the filesystem? If so what is the exact `chroot` command I need to use? – bit Feb 01 '23 at 19:56
  • Just reinstall. I'm not free tech support and I'm not in a mood to teach you everything about Linux. You'll need to fix your /etc/fstab as well which is far from trivial if you don't know the right commands. Please don't rsync `/etc` from now on. – Artem S. Tashkinov Feb 02 '23 at 09:40

1 Answers1

0

The best way to go is to reinstall your new laptop from scratch, unless you have backed up /etc, in which case you can restore it.

The /etc directory contains machine-specific configuration files for disks, network, services, and all installed packages. One cannot simply copy it from one machine into another and expect the machine to work (or ever to boot into an usable mode).

I think the problem could be that I replaced /etc/shadow and /etc/passwd on the new system with the ones from the old system. The user account on my old system and new system are different.

Correct, this is why you cannot log in. Besides, these files also contain UIDs, so replacing the files also messed up file ownership.

dr_
  • 28,763
  • 21
  • 89
  • 133
  • Thanks. I was under the impression that /etc contained application data files, is this wrong? Also what if I copy the /etc from another laptop from the same manufacturer but a newer model, will it work? – bit Feb 01 '23 at 18:32
  • I don't know what you mean exactly by application data files, but it contains configuration files for all programs and services. And no, copying and pasting `/etc` from one machine to another won't work in 99.9% of cases. You need to find another way to do what you want. – dr_ Feb 02 '23 at 09:21
  • *won't work in 99.9% of cases* modern Linux'es have very few HW specific bits in /etc. The most important is `/etc/fstab` which can be trivially fixed. Almost everything else is configured automatically at runtime. – Artem S. Tashkinov Feb 02 '23 at 09:36