2

I did a silly thing by renaming the /etc folder. I was asked for the admin password to change the folder's name. But it's not possible to rename it back to /etc. As if my password was wrong.

I assume the association between password and username is stored in this folder. I can still change the admin's password in the system settings. But I can't login to the advanced options that expect admin rights.

Unfortunately I don't have a recent time machine backup to replace the /etc folder.

Now I'm concerned about rebooting my Mac, as I'm not sure if I'll be able to login again.

How do I fix this issue?

Nimesh Neema
  • 51,809
w2m
  • 23
  • Where did you change it? Did you do it from the alias or inside /private/ ? I'd check it hasn't simply made a new folder or alias itself, that you'd need to clear first. – Tetsujin Apr 10 '19 at 11:54
  • Can you still open Terminal and run sudo ls -ld /etc /private/etc? If yes, please add the result to your question. – nohillside Apr 10 '19 at 12:01
  • @Tetsujin I changed the folder's name from the favorites list in the finder by right clicking it and rename. I thought I was just changing the favorite's name and not the folder's name itself. The "private" folder contains only 4 folders now. "hosts etc" which is the old "etc", "tftpboot", "tmp" and "var". – w2m Apr 10 '19 at 12:18
  • 1
    @nohiliside when opening the terminal I can't log in anymore – w2m Apr 10 '19 at 12:21
  • Could this work to create a new admin account and rename the folder? https://apple.stackexchange.com/a/323501 – w2m Apr 10 '19 at 13:27
  • @w2m No. Booting into single-user mode still requires a working /etc directory. –  Apr 10 '19 at 20:31

1 Answers1

7

I would try booting in single user mode (holding the Apple and S keys while rebooting), mount the hard drive (mount -uw /) and then check and rename etc as needed (there should be an alias at the root of the HD named etc pointing to /private/etc).

I would do an ls -al / and a ls -al /etc to see which directory name was changed and then fix the bad directory name with mv. Checking each directory would be important regardless of which fix you used (the one above or below).

If single user boot doesn't work, I would “Target Disk Mode” using another Mac (turn off the bad Mac, connect the two Macs with Firewire or Thunderbolt cable, start the bad Mac while holding down the T key), this will mount the bad Mac's drive as an external drive on the other Mac and you should be able to use the command line to change the name there.

Or, as someone else suggested, booting from the recovery partition.

Last resort is to reinstall the system, it should allow you to do that without wiping the drive.

David Rouse
  • 1,707
  • 1
    @w2m And while in target disk mode, take the opportunity to back up your files... – Solar Mike Apr 10 '19 at 15:52
  • 1
    With /etc missing, booting into single-user mode will fail. There's no hope of that working. –  Apr 10 '19 at 20:32
  • Sounds like the "Target Disk Mode" is my last option without wiping the drive.

    Reinstalling will probably ask for the login. See section 3.2. https://support.apple.com/en-us/HT204904

    Tomorrow I'll buy an external drive and run a time machine backup just in case I'll have to erase the drive. Owly will have to keep my Mac running until then :)

    – w2m Apr 10 '19 at 22:04
  • 1
    You should be able to boot into recovery mode, command + r at boot. Then you into terminal and change the name. Be sure to navigate the the correct drive. – historystamp Apr 10 '19 at 23:38
  • Update: the time machine backup was successful. But as I expected I couldn't reboot the system. I am able to start pressing command r and command s. I tried to rename the folder using the following command : mv '/private/hosts etc' '/private/etc'. But then I receive the terminal notification that the folder doesn't exist: https://i.ibb.co/xMjgjQt/20190412-180421.jpg. Would appreciate if anyone could help me out. – w2m Apr 12 '19 at 16:42
  • What do you get when you 'ls -al /private'? – David Rouse Apr 12 '19 at 17:05
  • https://i.ibb.co/cTgf6Q8/20190412-194217.jpg seems like the 'etc' folder exists. But I can't restart the system though. Could this be a problem with the alias? – w2m Apr 12 '19 at 17:52
  • I've tried to address the questions in my original answer. – David Rouse Apr 12 '19 at 19:43
  • Thank you so much! It works! :) actually I'm not sure when the renaming worked out. But I followed your steps again and it looked good and I couldn't find the bad folder name anymore. https://i.ibb.co/2M5pSmk/20190412-225007.jpg https://i.ibb.co/K9XQ0k4/20190412-225007.jpg the system starts again :) thanks again! – w2m Apr 12 '19 at 21:05
  • @w2m - You said "it works" but without being specific about which solution worked. David Rouse had suggested two options for booting: 1. booting with single user mode, and 2. Target Disk Mode. Which of the two worked for you? Or did you try something else? I have precisely the same problem (I renamed the /etc folder and now sudo will no longer work because it can't find the /etc/sudoers file). But I fear turning off the Mac in case the Mac login will no longer work without a valid /etc folder. – TechnoCat Nov 18 '21 at 08:47
  • @DavidRouse - I attempted to implement your solution this evening after an identical problem arose on a colleague's Mac. However, after successfully logging on using Single User Mode and mounting the disk, it was not possible to change the name of the /etc folder - or even to navigate to that folder (or to any of the alias folders). I have posted a full question at https://apple.stackexchange.com/q/431024/123183, in case you are able to answer that new question. – TechnoCat Nov 18 '21 at 14:43