Friday, April 25, 2014

fsadm, lvresize, resize2fs command usage Red Hat Linux

Hi Friends,

I never like reducing the File system in Redhat Linux or Linux. As it needs un-mounting of the file system. That most of the time is very tidy and asking downtime for it doesn't look good to me. Where increasing file system size can be done online.

Learned about a "FSADM" utility in HP UNIX 11i V3 that comes with Online JFS. which allows to reduce the file system size in Hp Unix online that is without un-mounting a file system. That removes the headache of downtime. Searching for the same kind in RedHat Linux found fsadm and learned about it, tried the same and thought to share with all.

Below are the steps including creation, extension and reduction of the size of an Logical Volume {LV named as Test in VG named as VolGroup}.

Creating an LV of 500 MB size naming as  test in VG VolGroup.



[root@localhost /]# lvcreate -L 500M -n test VolGroup
  WARNING: Failed to connect to lvmetad: No such file or directory. Falling back to internal scanning.
  Logical volume "test" created


for me lvmetd message was coming due to lvmetd daemon and cfdisk which worked for recovery of  external USB for me. It helped me in saving my data on USB. so for now please ignore above warning, It happened in my case only.

Command "lvs"showing the output of the available LV. it shows to which Volume Group an LV belongs and of what size.




[root@localhost /]# lvs
  WARNING: Failed to connect to lvmetad: No such file or directory. Falling back to internal scanning.
  LV      VG       Attr      LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_home VolGroup -wi-ao--- 100.10g                                             
  lv_root VolGroup -wi-ao---  50.00g                                            
  lv_swap VolGroup -wi-ao---   3.91g                                            
  test    VolGroup -wi-a---- 500.00m                                             
[root@localhost /]#
[root@localhost /]# mkf
mkfifo        mkfontscale   mkfs.cramfs   mkfs.ext3     mkfs.ext4dev  mkfs.msdos   
mkfontdir     mkfs          mkfs.ext2     mkfs.ext4     mkfs.gfs2     mkfs.vfat    
[root@localhost /]# mkfs.ext4
mkfs.ext4     mkfs.ext4dev 
[root@localhost /]# mkfs.ext4 /dev/mapper/VolGroup-
VolGroup-lv_home  VolGroup-lv_root  VolGroup-lv_swap  VolGroup-test    
[root@localhost /]# mkfs.ext4 /dev/mapper/VolGroup-test
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
      8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Writing inode tables: done                           
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost /]# 
above created a EXT4 file system using mkfst.ext4 command. 

[root@localhost /]# mount /dev/mapper/VolGroup-test /test1/
[root@localhost /]#
[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      477M  2.3M  445M   1% /test1
[root@localhost /]#
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# pwd
/
[root@localhost /]# man fsadm
[root@localhost /]#
[root@localhost /]# fsadm -e -y /dev/mapper/VolGroup-test 1000M
fsadm: Wrong argument "/dev/mapper/VolGroup-test". (see: fsadm --help)
[root@localhost /]# man fsadm
[root@localhost /]# 
Here I tried with increasing the test file system size online using fsadm to 1000MB size. It failed. 
[root@localhost /]# fsadm -e -y resize /dev/mapper/VolGroup-test 1000M
Do you want to unmount "/test1"? [Y|n] y
fsck from util-linux-ng 2.17.2
/dev/mapper/VolGroup-test: 11/128016 files (0.0% non-contiguous), 26666/512000 blocks
resize2fs 1.41.12 (17-May-2010)
The containing partition (or device) is only 512000 (1k) blocks.
You requested a new size of 1024000 blocks.

fsadm: Resize ext4 failed

[root@localhost /]# fsadm -e -y resize /dev/mapper/VolGroup-test 400M
Do you want to unmount "/test1"? [Y|n] y
fsck from util-linux-ng 2.17.2
/dev/mapper/VolGroup-test: 11/128016 files (0.0% non-contiguous), 26666/512000 blocks
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-test to 409600 (1k) blocks.
The filesystem on /dev/mapper/VolGroup-test is now 409600 blocks long.

[root@localhost /]# 
It allowed reduction within the size given to it at the time of creation. Lets see can we increase the size back to 500MB with this command or not.
[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      380M  2.3M  354M   1% /test1

[root@localhost /]#
[root@localhost /]#
[root@localhost /]# fsadm -e -y resize /dev/mapper/VolGroup-test 500M
Do you want to unmount "/test1"? [Y|n] y
fsck from util-linux-ng 2.17.2
/dev/mapper/VolGroup-test: 11/101600 files (0.0% non-contiguous), 23338/409600 blocks
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-test to 512000 (1k) blocks.
The filesystem on /dev/mapper/VolGroup-test is now 512000 blocks long.

[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      477M  2.3M  445M   1% /test1
[root@localhost /]#

[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      477M  2.3M  445M   1% /test1
[root@localhost /]#
[root@localhost /]# 
As seen above the file system size increase without using lvextend command and resize2fs command, but it did it to the limits of 500MB only, which we have given to it at the time of creation. 
Now Back to old method of extending the Logical Volume using lvextend command. 

[root@localhost /]# lvextend -L +500M /dev/mapper/VolGroup-test
  WARNING: Failed to connect to lvmetad: No such file or directory. Falling back to internal scanning.
  Extending logical volume test to 1000.00 MiB
  Logical volume test successfully resized
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      477M  2.3M  445M   1% /test1
[root@localhost /]#
The size after extending through LVEXTEND command will not be visible until we resize the file system, where this was not in the case of fsadm command shown above.
[root@localhost /]# resize
resize2fs   resizecons 
[root@localhost /]# man resizecons
[root@localhost /]#
[root@localhost /]# resize2fs /dev/mapper/VolGroup-test
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-test is mounted on /test1; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 4
Performing an on-line resize of /dev/mapper/VolGroup-test to 1024000 (1k) blocks.
The filesystem on /dev/mapper/VolGroup-test is now 1024000 blocks long.

[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      961M  2.5M  910M   1% /test1

[root@localhost /]# 
Size Increased.
[root@localhost /]# fsadm -y resize /dev/mapper/VolGroup-test 800M
Do you want to unmount "/test1"? [Y|n] y
fsck from util-linux-ng 2.17.2
/dev/mapper/VolGroup-test: 11/254000 files (0.0% non-contiguous), 42797/1024000 blocks
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-test to 819200 (1k) blocks.
The filesystem on /dev/mapper/VolGroup-test is now 819200 blocks long.

[root@localhost /]# 
Now we have reduced the size of 1000MB extended above using lvextend and resize2fs with fsadm command to size 800MB. 

[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      767M  2.5M  725M   1% /test1
[root@localhost /]# man fsadm
[root@localhost /]#
[root@localhost /]# e2fsck /dev/mapper/VolGroup-test
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/VolGroup-test is mounted.
e2fsck: Cannot continue, aborting.



[root@localhost /]# resize2fs /dev/mapper/VolGroup-test 700M
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-test is mounted on /test1; on-line resizing required
On-line shrinking from 819200 to 716800 not supported.

[root@localhost /]#
[root@localhost /]# lvre
lvreduce  lvremove  lvrename  lvresize 
[root@localhost /]# lvresize -L +2G /dev/mapper/VolGroup-test
  WARNING: Failed to connect to lvmetad: No such file or directory. Falling back to internal scanning.
  Extending logical volume test to 2.98 GiB
  Logical volume test successfully resized

[root@localhost /]#
[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      767M  2.5M  725M   1% /test1
[root@localhost /]# resize2fs /dev/mapper/VolGroup-test
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-test is mounted on /test1; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 12
Performing an on-line resize of /dev/mapper/VolGroup-test to 3121152 (1k) blocks.
The filesystem on /dev/mapper/VolGroup-test is now 3121152 blocks long.

[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   12G   36G  24% /
tmpfs                 926M  224K  926M   1% /dev/shm
/dev/sda1             477M   56M  393M  13% /boot
/dev/mapper/VolGroup-lv_home
                       99G   38G   56G  41% /home
/dev/mapper/VolGroup-test
                      2.9G  3.2M  2.8G   1% /test1
[root@localhost /]# 
... lvresize command with resize2fs command increased the size similarly as lvextend and resize2fs command. So it showed both of these worked similarly. Now we can come to a conclusion below.


Command "fsadm" allows you to reduce the file system without manually un-mounting a file system and also running e2fsck or file system check and then resizing or lvreduce command and then mounting back, but within the file system size given at the creation time of Logical Volume. It skipped 
a. UMOUNT
b. FSCK
c. resize2fs {LV} SIZE
d. lvreduce
e. Mount the File system. 


Will be adding in other post about how we can use the space of the LV reduced using this method. 


 


Tuesday, April 15, 2014

Using while to run a command number of times + UNIX

Hi Friends,

We can use while to run a command multiple times with a time difference of n seconds.

[root@abc /]# while true
> do sleep 10
> df -h
> done
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   19G   28G  41% /
tmpfs                 935M  408K  935M   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/mapper/VolGroup-lv_home
                       50G  5.5G   42G  12% /home
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   19G   28G  41% /
tmpfs                 935M  408K  935M   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/mapper/VolGroup-lv_home
                       50G  5.5G   42G  12% /home
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   19G   28G  41% /
tmpfs                 935M  408K  935M   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/mapper/VolGroup-lv_home
                       50G  5.5G   42G  12% /home

===========


the output of df command is coming after every ten seconds. these can be used when monitoring the size of file system while reducing it using find or rm.

Love Sharing
Amit Chopra

Thursday, April 3, 2014

How to read wtmp, btmp and utmp files + Linux

Hi Friends,

Learning Linux is now more exciting to me, I stay very happy when i learn any new thing about UNIX systems.sharing the same with you my friends, please add more in this if find me correct or incorrect so that we all can share better with everyone and understand more about UNIX system and working on it.

Reading files with cat, vi and more depends only upon the type of file which we want to check or read or see. So it is best to check the type of file with "file --name of the file-- ".

#file /var/log/wtmp
wtmp: data
#

so to read it we can try with Command "STRINGS" i.e.

#strings wtmp

but this output doesn't show the output in human readable form. so we can use "last -f" command. like below :- last -f /var/log/wtmp

we can also redirect this output to /tmp or desired location. and can then read this file properly.
-----
-----

wtmp file carries login details, reboot or system boot details with timings, terminals detail, with format of Day, Date, Time, System Crash/ Went Down/Made reboot.

utmp , wtmp carries login records and it also depends on type of programs using utmp logging as not all programs uses utmp logging.

utmp can be found in

/var/log/utmp
/var/run/utmp

btmp file carries login details, attaching the output in text file so that it can be read.

again

last -f "/var/log/btmp" ---- will give output in detail and can be redirected to any desired path.

attaching the o/p below :-

[root@localhost log]# last -f btmp
(unknown tty1         :0               Fri Mar 28 13:29    gone - no logout
ROOTEST1 tty7         :0               Wed Mar 26 20:28    gone - no logout
ROOTTEST tty7         :0               Wed Mar 26 20:25 - 20:28  (00:03)   
test123  tty7         :0               Wed Mar 26 20:15 - 20:25  (00:10)   
harish   tty1         :0               Tue Mar 11 06:48 - 13:29 (17+06:41) 
root     ssh:notty    175.125.29.35    Sun Mar  2 05:29    gone - no logout
root     ssh:notty    175.125.29.35    Sun Mar  2 05:29 - 05:29  (00:00)   
root     ssh:notty    175.125.29.35    Sun Mar  2 05:29 - 05:29  (00:00)   
root     ssh:notty    175.125.29.35    Sun Mar  2 05:29 - 05:29  (00:00)   
root     ssh:notty    175.125.29.35    Sun Mar  2 05:29 - 05:29  (00:00)   
root     ssh:notty    175.125.29.35    Sun Mar  2 05:29 - 05:29  (00:00)   

-============================================

btmp begins Sun Mar  2 02:09:17 2014
[root@localhost log]# last -f wtmp
root     pts/1        :0.0             Tue Apr  1 07:42   still logged in  
root     pts/0        :0.0             Tue Apr  1 07:38   still logged in  
root     tty1         :0               Tue Apr  1 07:34   still logged in  
reboot   system boot  2.6.32-358.el6.x Tue Apr  1 07:33 - 07:43  (00:09)   
root     pts/0        :0.0             Mon Mar 31 23:49 - down   (00:30)   
root     tty1         :0               Mon Mar 31 23:48 - down   (00:30)   
reboot   system boot  2.6.32-358.el6.x Mon Mar 31 23:48 - 00:19  (00:31)   
root     pts/2        :0.0             Sun Mar 30 11:38 - 11:38  (00:00)   

==================================

[root@localhost Desktop]# last -f /var/log/wtmp > /tmp/wtmpMarch.txt
[root@localhost Desktop]# ls -ld /tmp/wtmpMarch.txt
-rw-r--r-- 1 root root 12435 Apr  3 08:36 /tmp/wtmpMarch.txt
[root@localhost Desktop]#
[root@localhost Desktop]# less /tmp/wtmpMarch.txt
[root@localhost Desktop]# tail -4 /tmp/wtmpMarch.txt
reboot   system boot  2.6.32-358.el6.x Sat Feb  8 23:42 - 23:49  (00:07)   
reboot   system boot  2.6.32-358.el6.x Sat Feb  8 23:40 - 23:41  (00:01)   

wtmp begins Sat Feb  8 23:40:05 2014
[root@localhost Desktop]#




Love Sharing
Amit Chopra



How to check ntp version + redhat linux

Hi Friends,

Same as HP UNIX, ntp version can be checked from ntpq prompt. Please go to ntpq prompt, write version there, it will give the output which you are using.

attaching screen shot.






Love Sharing
Amit Chopra



Wednesday, April 2, 2014

How to check version of NTP + Hp UX

Hello Friends,

We were looking for NTP version installed on the hp ux server. but couldn't get the information using swinstall, swlist -l product, swlist -l fileset, swlist -l patch, swagent.log. After trying so many things we checked in

#ntpq
ntpq"prompt'
ntpq"prompt" version
"it will show the installed version of NTP"

NTP prompt is ntp"greater than arrow sign", {I dont know how can i enable the arrow signs here, as greater than or smaller than sign changes into some code after clicking on publish of post}
. Sorry for the inconvenience.

1. Somewhere i read on google, that "ntpd -v" will show the version of NTP. Or /usr/sbin/ntpd -v or /usr/sbin/xntpd -v will show the version but this was not available on  V3 and V2.

2. Also the /etc/rc.config.d/netdaemon files and /etc/ntp.conf  do not carry exact information about the version of NTP.

3. yes also Read on HP forum that the by default version of NTP which comes with 11.31 V3 is NTP verison 3.5.

4. The latest release from HP is version 4.2.6, not yet recommended by HP to upgrade the version.

5. Now to automate and check the version on large number of server, we can use a script or command. like below :-

If you are using any tool to get all information from all server from one server then it is very fine. you can use below command and extract information from the same.

 #"hostname; echo 'version' |ntpq; echo 'ntpversion' |ntpq"

or

#echo 'version' |ntpq

it will show the output, you not need to  give an input manually to ntpq prompt. after this you can redirect the output to some file also.

6. echo 'version' is giving its output to ntpq prompt and using this we can get the version of NTP.


Love Sharing
Amit Chopra


Tuesday, April 1, 2014

wtmpx data file Huge size + solaris

Hi Friends,

/var/adm/wtmpx  is a file, which keeps login details of the users and also carries shutdown, reboot of the server details. We faced File system full issue due to it. Our File system was total of size 15 GB, and the wtmpx file was occupying 12 GB of space and there were some other files which were occupying few spaces in MBs.

 and we were also not having space on other LVs, so that we could move the wtmp file and then compress the same. We could not stop the wtmp file logging.

a. We copied the same in text format using below command on /temp.

#/usr/lib/acct/fwtmp "<" /var/adm/wtmpx ">" /temp/wtmp.txt (the first sign used is "less than" and the second sign used is "greater than". First one is used to read the content and second one is used to to fwd the content of wtmpx file to text file )

We can also use the last -f command to read the files utmp, wtmp, btmp. As these file types are data type so should not be read with vi, more, cat.
#
#last -f /var/adm/wtmp or
#last -f /var/log/wtmp


this copied the content of wtmp file in /temp/wtmp.txt. You can name this file as per your wish.

this wtmp.txt file size was around 4.8G as it copied all the content of wtmp file of 12 GB.

b. We can monitor the /temp File system and we can also tail -f /temp/wtmp.txt file to check whether the files is proper or not. Now we can read the file as well.

c. tar/ compress/gzip the file, I gzipped the file

#gzip /temp/wtmp.txt

the size of above file became 250MB approx.

d. Now truncate the /var/adm/wtmp file or pass null value to the same like

#> /var/adm/wtmp :- this doesnt kill the process, but it empties the file.

e. File system size reduced.

f. Now moved the wtmp.txt file back to /var/adm/


It was a good learning. the FS size reduced and /var was available for use.




Love Sharing
Amit Chopra




#