How to recover your lost root password in CentOS

Here is a handy report on how to reset your root password if you have console access.

How to recover your lost root password

In CentOS, it’s possible to have the scripts that run from the initramfs debug the shell at certain points, provide a root shell, and continue when that shell exists.

First, reboot the system.

linux root password

Interrupt the boot loader countdown by pressing any key.

Move the cursor to the entry that needs to be booted.

linux root password

Press “e” to select that entry. After selecting that entry, the below kernel commands will appear.

linux root password

In the kernel command line, move the cursor to the line that starts with linux16.

linux root password

Press the “End” key to move the cursor to the end of it. Type “rd.break” (This will break just before control is handed from the initramfs to the actual system).

linux root password

Then press “Ctrl+x” to save those changes. The Initramfs debug shell will appear.

linux root password

Next, we have to provide read and write permissions to /sysroot by typing the below command:

mount -o remount,rw /sysroot/
linux root password

Now switch into chroot jail.

chroot /sysroot
linux root password

In here, /sysroot is treated as the root of the file system tree.

Next you’ll set a new root password.

passwd root
linux root password

And relabel the files.

touch /.autorelabel
linux root password

Finally, type “exit” twice.

The first one will exit from the chroot jail.

linux root password

The next one will exit from the initramfs debug shell and reboots the system.

linux root password

How to enable second level quotas on SolusVM with OpenVZ

Fixing already provisioned VMs

What about VMs already provisioned? First, the container must be powered off, then issue the vzctl set “VMID” –quotaugidlimit 1000 –save. Note that “VMID” is a placeholder for the container ID. Then start the container and you will have the second quotas enabled for use.

Fixing cPanel Quotas

Once you have the quotas enabled you will want to manual force cPanel to refresh the quotas. I would suggest running vzctl enter “VMID” to simply gain access to the VM. Again “VMID” is a placeholder for the container ID. Once inside the VM run the cPanel /script command to force the recheck on quotas /scripts/fixquotas You should see it force a recheck and will print out all of the quotas the accounts are getting set to. Once you see this you are finished,and cPanel is now showing disk usage correctly.

How do I get the size of a directory on the command line?

du -sh file_path


du command estimates file_path space usage
The options -sh are (from man du):

-s, –summarize
display only a total for each argument

-h, –human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
To check more than one directory and see the total, use du -sch:
-c, –total
produce a grand total