How to free disk space on /boot partition


I’ve just encountered a problem. I ran

yum upgrade

to upgrade all installed packages on my Centos 5.9. New kernel was in the list of packages to be updated.

In this article I’ll also explain how to remove (install) specific package version with YUM

Kernel package installation thrown an error about lack of space on /boot partition:

Error Summary
Disk Requirements:
At least 4MB needed on the /boot filesystem.

My /boot partition is not big enough. I have 5 kernels installed and I’m trying to install one more. Yum takes care of removing old kernels automatically, but only after new kernel installation. :)

df /boot gives us information about free space on boot partition (add -h option to get human readable output):

# df /boot
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda1 101086 88956 12130 88% /boot

# df -h /boot
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 99M 87M 12 100% /boot

So my /boot partition size is 99MB and 12MB is free. New kernel requires 24MB (from yum upgrade):
kernel x86_64 centosplus 24 M

Indeed, lack of space.

To solve this problem we have to delete unused kernels from /boot partition.

To get a list of currently installed packages I use yum list installed
To get a list of currently installed kernel packages add one more grep: yum list installed | grep kernel.

I have 5 kernals installed:

# yum list installed | grep kernel
kernel.x86_64 installed
kernel.x86_64 installed
kernel.x86_64 installed
kernel.x86_64 installed
kernel.x86_64 installed

And only 2 of them are are available for boot (/boot/grub/grub.conf file contains information abot avaliable kernels and their priority during boot process):

# cat /boot/grub/grub.conf
title CentOS (
    root (hd0,0)
    kernel / ro root=/dev/VolGroup00/LogVol00 selinux=0
    initrd /
title CentOS (
    root (hd0,0)
    kernel / ro root=/dev/VolGroup00/LogVol00 selinux=0
    initrd /

Version 2.6.18-371.6.1 is currently running – it’s on first place in /boot/grub/grub.conf kernels priority list. Also you can get currently running kernel using uname -a::

# uname -a
Linux #1 SMP Fri Dec 13 15:01:51 MSK 2013 x86_64 x86_64 x86_64 GNU/Linux

So kernel versions 2.6.18-348.16.1, 2.6.18-348.18.1 and 2.6.18-371.1.2 are needless and I can remove them.

Using yum remove kernel would remove all kernels so we have to specify which version we’d like to remove.

Yum package version syntax is –.

To remove specific kernel versions we use:

# yum remove

After removal we have enough free space to install new kernels:

# df -h /boot
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 99M 58M 25M 54% /boot

That’s all, folks :)

How to mount NTFS device (i.e. USB stick) on Centos

I’ve just plugged NTFS-formatted USB stick to my Centos 5.9 server and failed to access its data for the first time.
Some additional steps were required:

  1. Create a folder to where you gona mount USB stick partition.
    ([]# mkdir /media/usb)
  2. Find USB stick partition device name.
    • []# ls /dev/disk – – – let’s take a look at the list of files and subfolders in /dev/disk folder – we have 4 subfolders there: by-id by-label by-path by-uuid
    • so all our disks, usb-sticks, usb-hdds etc. are here grouped by 4 different properties. by-id and by-label are the easiest to understand:
      []# ls -la /dev/disk/by-id – – – Shows table of files and subfolders in folder /dev/disk/by-id (partitions are in bold):
      total 0
      drwxr-xr-x 2 root root 140 Jan 1 04:34 .
      drwxr-xr-x 6 root root 120 Jan 1 04:34 ..
      lrwxrwxrwx 1 root root 9 Jan 1 04:34 ata-IC35L040AVVA07-0_VNC202A2GX4NMA -> ../../hda
      lrwxrwxrwx 1 root root 10 Jan 1 04:34 ata-IC35L040AVVA07-0_VNC202A2GX4NMA-part1 -> ../../hda1
      lrwxrwxrwx 1 root root 10 Jan 1 04:34 ata-IC35L040AVVA07-0_VNC202A2GX4NMA-part2 -> ../../hda2
      lrwxrwxrwx 1 root root 9 Jan 1 04:34 usb-JetFlash_Transcend_8GB -> ../../sda
      lrwxrwxrwx 1 root root 10 Jan 1 04:34 usb-JetFlash_Transcend_8GB-part1 -> ../../sda1
    • as you can see we have a collection of Symbolic Links. Each of them points us to specific block device in /dev folder
    • in my case required USB stick partition is ../../sda1 (/dev/sda1)
    • let’s mount it!
  3. []# mount /dev/sda1 /mount/usb – – – trying to mount /dev/sda1 partition to /mount/usb folder gives an error:
    mount: unknown filesystem type 'ntfs' – – – our CentOS don’t know how to work with NTFS
  4. Teaching CentOS working with NTFS is achieved by installing ntfs-3g package. But default CentOS YUM repos lacks of it.
  5. Here goes EPEL – “a Fedora Special Interest Group that creates, maintains, and manages a high quality set of additional packages for Enterprise Linux, including, but not limited to, Red Hat Enterprise Linux (RHEL), CentOS and Scientific Linux (SL)” so their packages  suit our needs.
  6. How can I use these extra packages? section there is 1 RPM’s for 5’th and 1 for 6’th Enterprice Linux. You can install them by:
    []# rpm -uVh (5’th EL).
  7. RPM installation would add 2 extra YUM repositories: EPEL base and EPEL test (disabled by default)
  8. Finally to install ntfs-3g package run:
    []# yum install ntfs-3g For the first time installing packages from EPEL you need to add GPG signature public key for EPEL repository.
  9. After installing ntfs-3g package []# mount /dev/sda1 /mount/usb works well with no errors and USB NTFS data is in /mount/usb folder.
  10. To unmount USB-stick execute []# umount /dev/sda1

That’s all, folks!

How to reset forgotten MySQL root password

Sometimes we need to change root user password on MySQL server.

It’s rather easy if you know current one.

But what if you don’t know current MySQL root password?

Here is the solution:

  1. Stop mysql daemon ( “service mysqld stop” );
  2. Safely start mysql daemon with both –skip-grant-tables and –skip-networking options set ( “mysqld_safe –skip-grant-tables –skip-networking &” );
  3. Log in to MySQL server console as root and select `mysql` database to work with ( “mysql –user=root mysql” );
  4. Set new root user password within console:
    update user set Password=PASSWORD(‘new-password’) where user=’root';
    flush privileges;
  5. Stop MySQL server running in safe mode ( “service mysqld stop” );
  6. Start MySQL normaly ( “service mysqld start” ).

That’s all, folks!

Using PEAR libraries with open_basedir

By default PHP can open files anywhere on filesystem. We can even put file to /file.php and include it with <?php include(‘/file.php’); ?>

It’s very insecure to allow such PHP behavior.

To solve this issue we have very useful  php.ini directive called open_basedir. It  tells PHP to open files ONLY within to the specified directory (and its subdirectories).  If the file is outside the specified directory tree, PHP will refuse to open it. This restriction can’t be  avoided with symbolic links. PHP resolves  symbolic link and check whether resolved path is within  allowed directory.

If you have open_basedir directive set to some folder (for example /www/) PHP can only open files within /www/directory, including the directory  itself:

open_basedir = /var/www/


But what if we need to include() some PHP library from the other place on the filesystem?

Or we want to use any PEAR libraries which is installed on our server?

PEAR   libraries are usual PHP files located in PEAR directory (by default – /usr/share/pear/). PEAR  libraries path added to include_path php.ini directive with PEAR installation. If you haven’t provided absolute path to a file while incude() or require() PHP searches for file based on the include_path.

PEAR classes should be included in our PHP files like <?php include(‘System.php’); ?> (System.php is core PEAR file/directory manipulation library).

So PHP checks is file “/usr/share/pear/System.php” exist and if tries to include it.

Due to  open_basedir directive  PHP can only open files within “/www/” directory but we are trying to open file from “/usr/share/pear/” directory and obviously get PHP “Fatal error: require_once(): Failed opening required ‘System.php’ (include_path=’.:/usr/share/pear:/usr/share/php’) in …”.

To avoid this all we have to do is to add “/usr/share/pear/” directory to  open_basedir directive like:

open_basedir = /var/www/:/usr/share/pear/

You can add as many directories as you want separating them with “:”.



That’s all, folks!



Fixing `ploop-lib conflicts with ovzkernel` yum issue

Few weeks ago there was `ploop` and `ploop-lib` update released for OpenVZ.

When executing `yum update` on OpenVZ Hardware Node machine new `ploop` and  `ploop-lib`packages, which are about to be installed gave a dependancy errors like:

# yum update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base:
* centosplus:
* extras:
* openvz-kernel-rhel5:
* openvz-utils:
* updates:
Setting up Update Process
Resolving Dependencies
--> Running transaction check
---> Package ploop.x86_64 0:1.5-1 set to be updated
---> Package ploop-lib.x86_64 0:1.5-1 set to be updated
---> Package vzctl.x86_64 0:4.0-1 set to be updated
--> Processing Dependency: for package: vzctl
---> Package vzctl-core.x86_64 0:4.0-1 set to be updated
--> Processing Conflict: ploop-lib conflicts vzkernel < 2.6.32-042stab061.1
--> Finished Dependency Resolution
ploop-lib-1.5-1.x86_64 from openvz-utils has depsolving problems
--> ploop-lib conflicts with ovzkernel
Error: ploop-lib conflicts with ovzkernel
You could try using --skip-broken to work around the problem
You could try running: package-cleanup --problems
package-cleanup --dupes
rpm -Va --nofiles --nodigest

Next fix assumes that YOU DON’T USE `ploop` AS A FILESYSTEM LAYOUT FOR NEW CT’s!

To fix this do next steps:

  1. remove the old unused ovzkernels
    • type `yum list | grep ovzkernel | grep installed` to see which OpenVZ kernels do you have installed;
    • you can see your current kernel version and release by typing `uname -r`;
    • to erase old OpenVZ kernels use `yum erase` and add all the old kernels with space before;

    If you have 3 kernels installed:

    #yum list | grep ovzkernel | grep installed
    ovzkernel.x86_64                     2.6.18-308.8.2.el5.028stab101.1    installed
    ovzkernel.x86_64                     2.6.18-308.el5.028stab099.3           installed
    ovzkernel.x86_64                     2.6.18-274.7.1.el5.028stab095.1    installed

    And your current kernel release is:

    #uname -r

    You’ll have to delete 2 oldest kernels with `yum erase ovzkernel-2.6.18-274.7.1.el5.028stab095.1 ovzkernel-2.6.18-308.el5.028stab099.3`.

    (Note that you shouldn’t provide Arch for kernels to delete, only version through “-” after package name);

  2. remove `ploop` and `ploop-lib` packages with `yum erase ploop ploop-lib`.  (Note, that this removal would also remove `vzctl` and `vzctl-lib` (if present) packages);
  3. install `vzctl-core` and `vzctl` packages with `yum install vzctl.x86_64` (for x64 system);
  4. now you can launch `yum update` to update everything.
That’s all, floks!


How to set MySQL root password for the first time in Centos

Yep, you’ve successfully installed mysql server on Centos. What’s next?

Before setting password we have to  start MySQL server first – use `service mysqld start` for it.

After server successfully starts use `mysqladmin password ‘<your-very-strong-root-password>’` to set MySQL root user password FOR THE FIRST TIME.

If your password doesn’t contain any special characters you can drop out quotes like `mysqladmin password <your-very-strong-root-password>`.

Note that this command could be invoked ONLY ONCE –  for the first time we don’t enter any password for such privileged task like setting root password.

New time when you try to set new root password with this command you’ll have to enter privileged user (i.e. root) password like `mysqladmin -p -u root password ‘<your-very-strong-root-password>’`.

That’s all, folks!


How to hard reset OpenWRT on TP-LINK 1043ND

I have TP-LINK 1043 ND router and have OpenWRT firmware on it.

After some configuration actions I’ve broken IPv4 configuration on it and my Router stopped giving IPv4 addresses by DHCP to the network clients.

To make OpenWRT hard reset (nor factory reset) you have to pass 4 easy steps:

  1. Power the router up;
  2. After powering up track the SYS light when it starts to blink, when it does press and hold the QSS button till SYS lights starts to blink faster – router goes to recovery mode;
  3. Telnet to the router on – no password needed (if your computer doesn’t gets IP address from DHCP assign it manually for i.e. with netmask of;
  4. In telnet terminal type `mtd -r erase rootfs_data` to reset OpenWRT to it’s defaults.

That’s all, folks!

  1. mtd -r erase rootfs_data

How to reset root password on Centos 5

Hi there.

Few days ago I’ve found that I’ve lost password from my Centos based server.

Here is what I’ve done to reset my root password.

All we need is to boot in  Single User mode ().

To do it:

  1. Reboot your server
  2. Tap any key right after bios and hardware-related stuff (memory check, RAID controller initialization) to interrupt GRUB loading. Here you should see a list of all avaliable linux kernels to boot.
  3. Move to desired linux kernel and press `a` to enter APPEND mode. Here we are gona append some extra parameters to kernel loading command. If you have GRUB password installed you have to enter it first pressing `p`.
  4. Assume we have entered parameter APPEND mode and see `ro root=LABEL=/`. Here we have to add `single` word to the end of line (with SPACE before) to get  `ro root=LABEL=/ single`.
  5. Press Enter to load Centos with our new parameters string.
  6. After system boots we are logged in system as root and can change password typing `passwd` to change root password or `passwd anyuser` to change anyuser password.

That’s all, folks! ;)

How to change timezone in CentOS 5

To change timezone in CentOS 5 you only have to create one symbolic link.

You need superuser (root) privileges to do it.

First you have to know your timezone and then find it in /usr/share/zoneinfo/ folder.

File, which tells the system its timezone is `/etc/localtime`.

Assume your timezone is Canada/Newfoundland.

Your timezone file would be /usr/share/zoneinfo/Canada/Newfoundland.


To  change timezone call:

ln -s /usr/share/zoneinfo/Canada/Newfoundland /etc/localtime


That’s all folks!