Tuesday, May 28, 2013

Reset Root Password on CentOS 5 & 6



Below are the steps to Reset the Password for Root:

Boot or Reboot your CentOS and Hold the Arrow button to bring the Grub menu, From the GRUB menu, select the appropriate kernel version and press the 'e' key.


You will now be presented with the option menu for the kernel version

From this menu, select the kernel /vmlinuz-... line and press the 'e' key.You will now be presented with the kernel boot options, add single at the end of line, Press enter to save your changes and Press 'b' to boot from this


                                       
This will boot up in single user mode, Now you will boot up to the root shell and you can use passwd to set your new password.


Issue passwd command to reset the password

Reboot and you have a new root password for your CentOS installation.

Saturday, May 25, 2013

Howto Free up used memory on a Linux operating system



Usually the kernel handles memory utilization pretty well it caches memory for dentry cache, page cache and inodes which improves IO speed and performance generally. But in some cases user applications needs lots of memory and we need to clear what’s called dirty memory which could be inodes already written to the disk, so now the kernel given us the option to manage this manually.
To Free
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
free -m
total used free shared buffers cached
Mem: 3833 2827 1005 0 31 1030
-/+ buffers/cache: 1765 2067
Swap: 10095 0 10095
~ $free -m

                     total       used          free     shared    buffers     cached
Mem:           5754       1551       4202          0        258        980
-/+ buffers/cache:          313       5441
Swap:           5215            0       5215



Here "buffers" and "cached" columns, which tell you about the amount of memory that the kernel is using for filesystem buffers, etc

So in this example, 5441MB is how much memory is technically available for allocation should an application need it. The "buffers" (258MB) and "cached" (980MB) will be released by the kernal if they are needed.

Tuesday, May 7, 2013

Reconfiguring Network Interfaces in CentOS/RHEL Systems Cloned with vCenter


While cloning CentOS VMs in our environment, I ran into a problem where eth0 wouldn’t start up. When trying to start the networking service, the following error popped up:

Bringing up interface eth0: Device eth0 does not seem to be preset, delaying initialization.      [FAILED]


The reason this error occurs is because networking adapters in cloned VMs are assigned unique MAC addresses, so they don’t conflict with the parent VM. During OS installation, the installer detects the network adapter and udev configures the mapping between the device eth0 and the MAC address. When the MAC address changes udev thinks the device is missing.

To fix this, we need to update udev’s mapping rules to point the eth0 definition to the device with the correct MAC address. Open the file /etc/udev/rules.d/70-persistent-net.rules. You should see something similar to what is below:

# PCI device 0x8086:0x100f (e1000) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:9c:00:16", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100f (e1000) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:9c:00:18", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

As you can see there are two PCI ethernet adapters present. The original one from the parent VM (MAC: 9c:00:16) and the new one from the current VM (MAC: 9c:00:18). To fix the issue you need to change the eth0 device definition to have the correct MAC address (9c:00:18) and remove the eth1 device. Your resulting file will look like so:

You have to update the /etc/sysconfig/network-scripts/ifcfg-eth0 file to reflect the correct MAC address. Then, after a quick system restart your eth0 adapter will be back up.

Date and Time in Linux


Set Date

Use the following syntax to set new data and time:
date --set="STRING"

set new data to 23 Jan 2012 2:12:15

date --set="Tue Jan 23 2:12:15 EDT 2012"

You can format as belwo:

date +%Y%m%d -s "20120910"


Set Time

Use the following syntax to set time:

# date +%T -s "11:10:05"

11Hour (hh)

10: Minute (mm)

05: Second (ss)

Use %p locale’s equivalent of either AM or PM, enter:

# date +%T%p -s "2:12:30AM"

# date +%T%p -s "11:12:30PM"