Increase Linux Disk Space

August 7, 2009 by linuxgurus

Most of the users with heavy storage on Linux encounter Disk full ( 100% used ) problem.

Let me explain…

Problem:

[root@findevdb ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
7.8G  3.1G  4.6G  41% /
/dev/sda1              99M   13M   85M  14% /boot
none                  2.9G     0  2.9G   0% /dev/shm
/dev/sdb1             148G  146G  1.1G 100% /u01
/dev/sdc1              74G   71G  2.2G  98% /u02
/dev/sdd1              74G   71G  1.6G  98% /u03

The above disk status shows that /dev/sdb1 is 100% used but still there is 1.1G free space available.

Reserved Block count

File system Reserved Block Count is supposed to reduce Linux file system defragmentation, to allow root user login for maintenance or to allow Linux system logging facility to function properly in case file system running low of free disk space.

Resolution:

when you check the ext2/ext3 file system parameters, you will find Reserved block count, Block size.

# tune2fs -l /dev/sdb1

Reserved block count:     393210
.
.
.
Block size:               4096

The block size is measured in byte unit. In this case, it’s 4,096 byte or 4KB. So, the Reserved Block Count: 393210 is equal to 1,610,588,160 byte or roughly equivalent to 1.3GB.

So to reduce the reserve bolck to 0%, follow the steps.

# tune2fs -m 0 /dev/sdb1

will set the percentage of file system reserved block count to 0% for /dev/sdb1  file system.

[root@findevdb ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
7.8G  3.1G  4.6G  41% /
/dev/sda1              99M   13M   85M  14% /boot
none                  2.9G     0  2.9G   0% /dev/shm
/dev/sdb1             148G  146G  2.6G  99% /u01
/dev/sdc1              74G   71G  2.2G  98% /u02
/dev/sdd1              74G   71G  1.6G  98% /u03

Disabling of total file system reserved block amount is not an Issue. It can be done.

Note

File system dedicated to host database table files, Samba shares, movie or music files, etc, are safe to disable file system reserved block count.

Increase the Linux Ext3 partition without lossing Data in VMware

July 8, 2009 by linuxgurus

One of  partition on my database server got 100% occupied with data and no free space available on the disk.  Now i am unable to start the database server. its on vmware server.

Here i am taking a sample partition to expand the disk from 5GB to 7GB with out lossing Data.

Before increasing the disk, i have taken the following details from linux vm

# df -h

 Filesystem            Size  Used Avail Use% Mounted on
 /dev/sda3             6.8G  2.1G  4.5G  32% /
 /dev/sda1              99M   12M   83M  13% /boot
 none                  252M     0  252M   0% /dev/shm
 /dev/sdb1             5.0G   39M  4.7G   1% /mnt/test

# fdisk -s /dev/sdb

Disk /dev/sdb: 5368 MB, 5368709120 bytes
 255 heads, 63 sectors/track, 652 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot      Start         End      Blocks   Id  System
 /dev/sdb1               1         652     5237158+  83  Linux

Shutdown the vm now

Now i am going to increase the existing virtual disk ( /dev/sdb ) from vmware command prompt

go to the location of virtual disk location

Note:  this task should be performed only when vm is powered off

# vmware-vdiskmanager -x  7Gb RedHatEnterprise_Linux_4-0.vmdk

Now it will grow the virtual disk to 7Gb

Now you need to power on the VM.

Log into vm using putty or console as root user

# df -h

Filesystem            Size  Used Avail Use% Mounted on
 /dev/sda3             6.8G  2.1G  4.5G  32% /
 /dev/sda1              99M   12M   83M  13% /boot
 none                  252M     0  252M   0% /dev/shm
 /dev/sdb1             5.0G   39M  4.7G   1% /mnt/test

Still it shows the old size.

unmount the partition which you are going to increase.

#umount /dev/sdb1

Run the file system repair on the disk

#fsck -n /dev/sdb1

Now were are goig to remove the journel from the disk to make it into ext2 filesystem

#tune2fs -O ^has_journal /dev/sdb1

Now start partitioning the /dev/sdb to use the increased space to the /dev/sdb1

Note: Don’t Panic, You will not loss data here

I am removing the existing /dev/sdb1 and recreating along with available free space.

# fdisk /dev/sdb

Command (m for help): m
Command action
a   toggle a bootable flag
b   edit bsd disklabel
c   toggle the dos compatibility flag
d   delete a partition
l   list known partition types
m   print this menu
n   add a new partition
o   create a new empty DOS partition table
p   print the partition table
q   quit without saving changes
s   create a new empty Sun disklabel
t   change a partition’s system id
u   change display/entry units
v   verify the partition table
w   write table to disk and exit
x   extra functionality (experts only)

Command (m for help): p

Disk /dev/sdb: 7516 MB, 7516192768 bytes
255 heads, 63 sectors/track, 913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         652     5237158+  83  Linux

Command (m for help): d
Selected partition 1

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-913, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-913, default 913):
Using default value 913

Command (m for help): p

Disk /dev/sdb: 7516 MB, 7516192768 bytes
255 heads, 63 sectors/track, 913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         913     7333641   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Now restart the linux machine to take effect of the partition ( we can also use partprobe, its strictly recommended to restart the machine

# shoutdown now -r

Now once again check the extended file system, if you skip this step, resize2fs command will recommends to run
# e2fsck -f /dev/sdb1

 e2fsck 1.35 (28-Feb-2004)
 Pass 1: Checking inodes, blocks, and sizes
 Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
 /dev/sdb1: 13/655360 files (7.7% non-contiguous), 22121/1309289 blocks

Now resize the file system.

# resize2fs /dev/sdb1

 resize2fs 1.35 (28-Feb-2004)
 Resizing the filesystem on /dev/sdb1 to 1833410 (4k) blocks.
 The filesystem on /dev/sdb1 is now 1833410 blocks long.

Now check the file system

#fsck -n /dev/sdb1

 fsck 1.35 (28-Feb-2004)
 e2fsck 1.35 (28-Feb-2004)
 /dev/sdb1: clean, 13/917504 files, 30538/1833410 blocks

Now recreate the partition with ext3 format

# tune2fs -j /dev/sdb1

 tune2fs 1.35 (28-Feb-2004)
 Creating journal inode: done
 This filesystem will be automatically checked every 32 mounts or
 180 days, whichever comes first.  Use tune2fs -c or -i to override.

Restart the Linux machine once to get effected with ext3 file system.

#shutdown -r now

Once again you login to Linux box using root previleges.

Now you can find the partition increased to 7 Gb

# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             6.8G  2.1G  4.5G  32% /
/dev/sda1              99M   12M   83M  13% /boot
none                  252M     0  252M   0% /dev/shm
/dev/sdb1             6.9G   39M  6.7G   1% /mnt/test




My Experience with Vmware ESXi 4.0

June 28, 2009 by linuxgurus

I have tried the VMware ESXi 4.0 on my machine with AMD Quadracore processor, 500 GB HDD and 4 GB RAM.  The motherboard is compatible with virtualization (VT).  I have installed VMware ESXi 4 on VMware workstation 6.5 .

  1. How to enable SSH on VMware ESXi 4
  • press alt+F1
  • type unsupported
  • enter the root password
  • edit the /etc/inetd.conf and remove the “#”  before ssh …. ( vi /etc/inetd.conf and press ‘x’ at “#” before ssh
  • Restart the ssh service  (“/sbin/services.sh restart” )

more  to come …

Automate SSH Authorization

June 19, 2009 by linuxgurus

I usually work on Linux machines.  every time its a time taking task to generate ssh key generation between server and copy the authorization key.

i have a small script which will generate and copy the files to your desired destinations and makes your task easy

Login to server A

#ssh-keygen -t rsa -b 2048

follow the instructions and complete the key generation.  dont provide any pass phrase.

#cd /tmp
vi sshkeycopy.sh
#-------- end of the script -----------
#! /bin/bash
 PATH="/bin:/usr/bin"

 if [ ! -e ~/.ssh/id_rsa.pub ]; then
 echo "RSA public key file ~/.ssh/id_rsa.pub not found!"
 exit 1
 fi

 for desthost in $@; do
 ssh -q "${USER}@${desthost}" \
 "if [ ! -d ~/.ssh ]; then mkdir -m 0700 ~/.ssh; fi; \
 echo $(cat ~/.ssh/id_rsa.pub) >> ~/.ssh/authorized_keys; \
 chmod 0600 ~/.ssh/authorized_keys" || echo "Unable to connect to $desthost"
 done
#-------- start of the script -----------

Save the test using :wq and quit.

# chmod 700 sshkeycopy.sh

Now you are ready to copy the generated keys to the destination servers
# cd /tmp
#./sshkeycopy.sh dev.linuxgurus.com dev2.linuxgurus.com

Now you can scp or ssh into destination servers from the current servers without any passwords.
- Shankar