Thursday, September 28, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  19] [ 0]  / answers: 1 / hits: 37385  / 2 Years ago, tue, march 29, 2022, 8:59:17

Possible Duplicate:

Cannot lock '/etc/group' in recovery mode

I have a laptop with Ubuntu 11.10 that is shared between myself and two other family members. My user id was setup as the only "Administrator" on the laptop. The other users were setup as "Standard" users. In my attempt to try to add myself to the user groups for the other users, I somehow deleted myself from the admin groups. I used the "usermod" command from the terminal. I must have neglected to include the proper switches or syntax for the update.

It looks like I successfully added my userid to the group associated with my wife's account. When I use the "groups" command, I can see only my id and my wife's id in the list. I no longer see the "admin" or "adm" groups, and others that used to be listed. When I go into System Settings > User Accounts it looks like my ID is now listed as a "Standard" user. I would like to change my account back to "Administrator", but now I can't.

I did some searches for solutions and found that I would need to boot into Recovery Mode and execute the usermod command from the root session. I was able to successfully boot into Recovery Mode and get to the root session. I was trying to execute the command "usermod -a -G admin user1" to add my id (user1) back to the admin group.

When I execute the command from the root session, I get the error message "usermod: cannot lock /etc/passwd; try again later". I tried preceding the usermod command with "sudo", but it didn't make a difference, same error. I then tried adding a new user using adduser, thinking I would try to create a new userid and make the new userid part of the admin group. I get the same error using the adduser command.

I saw some posts that recommend looking for and deleting files that end in ".lock" in the etc directory. The only file I found was .pwd.lock which I haven't touched.

I am at a loss as to what to try next. I am relatively inexperienced with Ubuntu and Linux, so alot of this is new to me. Any help you can provide would be much appreciated.

More From » sudo


I finally figured out why I was receiving the "usermod: cannot lock /etc/passwd; try again later" error message. The root cause of the issue had to do with the fact that when I booted into Recovery Mode, by default the filesystem was mounted as read-only. Because the filesystem was mounted as read-only, the adduser and usermod commands were not able to perform their functions and produced the error message.

What got me thinking the issue was not a file corruption or *.lock related issue was that there were no passwd.lock, group.lock, or shadow.lock files in the /etc folder. Also, I got a different error message when I tried to copy, rename or delete the .pwd.lock file that was in the /etc folder when I was booted into the Root Session in Recovery Mode. I got a different error message, something like unable to rename file read-only. I did some web searching on "Recover Mode Read Only" and came across the following post:

The post talks about the Recovery Mode being in read-only mode by default. It suggested remounting as read-write to allow changes to be made to files in the /etc folder. So here's what I did to resolve the issue:

  1. Shutdown the computer

  2. Boot into Recovery Mode
    --After BIOS load, hold down Shift key to access the grub menu
    --Once in grub menu, select the entry ending in "(recovery mode)"

  3. From the next menu selected option to enter Root Session

  4. At the root session, execute the following command to remount the filesystem as read-write :

    mount -o remount,rw /

  5. Execute adduser command to add my userid back to the admin group. Command executed "adduser username admin" where I replaced username with my actual system username. This time I did not receive an error executing the command since the filesystem was mounted as read-write.

  6. Exit Root Session, exit recovery mode, and rebooted.

Once rebooted into Ubuntu, I could see that my userid was now listed as being a member of the admin group, by executing "Groups" command from the normal terminal session. I also verified the same in the GUI by going to "User Accounts" in the Ubuntu System Settings menu. There my userID was also listed as an "Administrator".

I went further to try to replicate my original issue to see if rebooting back to Recovery Mode and skipping Step #4 above (to remount the filesystem as read-write) would reproduce the "unable to lock /etc/passwd" error, and it did. The root cause of the issue had to do with how the filesystem was mounted in Recovery Mode.

It seems odd to me as a new user that booting into Recovery Mode would be read-only by default. Isn't that the idea of recovery, that you would need to make some changes to correct update files, correct issues that would otherwise not be possible as a normal user?

Anyway, I'm just happy to now have at least one user on the computer with Administrator access. Thanks again to all who responded to my issue.

[#42016] Thursday, March 31, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 307
Total Questions: 103
Total Answers: 119

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
2 Years ago
tisglitter questions
Sun, Jan 9, 22, 16:18, 2 Years ago
Tue, Jan 10, 23, 00:08, 9 Months ago
Wed, Jun 1, 22, 18:03, 1 Year ago
Fri, Dec 10, 21, 14:31, 2 Years ago