Friday, November 23, 2012


Converting the File System from ext3 to ext2 without data Loss

 

Release:

RHEL

 

Problem:

This document guide you on how to convert an ext3 file system to ext2 file system without data loss.

 

Solution:

In this document we are having a Red hat box with a partition /dev/sdb1 formatted using ext3 file system and mounted under /test directory.

[root@akhisar test]# mount

/dev/mapper/vg_akhisar-lv_root on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)

/dev/sr0 on /media/RHEL_6.1 x86_64 Disc 1 type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)

/dev/sr0 on /mnt type iso9660 (ro)

/dev/sdb1 on /test type ext3 (rw)

 

We can see that the partition is containing data and the listed output for the /test directory is as below:

[root@akhisar test]# ls

file1   file16  file22  file29  file35  file41  file48  file54  lost+found

file10  file17  file23  file3   file36  file42  file49  file55

file11  file18  file24  file30  file37  file43  file5   file56

file12  file19  file25  file31  file38  file44  file50  file6

file13  file2   file26  file32  file39  file45  file51  file7

file14  file20  file27  file33  file4   file46  file52  file8

file15  file21  file28  file34  file40  file47  file53  file9

 

 

 

Now we are going to convert the file system for the partition /dev/sdb1 from ext3 to ext2.

 

Step 1:

Unmount the partition on which the activity needs to be carried out.

[root@akhisar /]# umount /test

[root@akhisar /]# mount

/dev/mapper/vg_akhisar-lv_root on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)

/dev/sr0 on /media/RHEL_6.1 x86_64 Disc 1 type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)

/dev/sr0 on /mnt type iso9660 (ro)

 

Step 2:

Clear the has_journal using the tune2fs command along with the “^” string.

[root@akhisar /]# tune2fs -O ^has_journal /dev/sdb1

tune2fs 1.41.12 (17-May-2010)

 

Step 3:

Check the partition for errors by typing the following command as root:

[root@akhisar /]# e2fsck -y /dev/sdb1

e2fsck 1.41.12 (17-May-2010)

/dev/sdb1: clean, 67/42168 files, 6877/168648 blocks

 

Step 4:

Then mount the partition again as ext2 file system by typing the below command:

[root@akhisar /]# mount -t ext2 /dev/sdb1 /test/

 

Step 5:

You can check the same by using the mount option.

 

 

[root@akhisar /]# mount

/dev/mapper/vg_akhisar-lv_root on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)

/dev/sr0 on /media/RHEL_6.1 x86_64 Disc 1 type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)

/dev/sr0 on /mnt type iso9660 (ro)

/dev/sdb1 on /test type ext2 (rw)

 

Step 6:

Check the data by browsing to the test folder.

[root@akhisar /]# cd test

[root@akhisar test]# ls

file1   file16  file22  file29  file35  file41  file48  file54  lost+found

file10  file17  file23  file3   file36  file42  file49  file55

file11  file18  file24  file30  file37  file43  file5   file56

file12  file19  file25  file31  file38  file44  file50  file6

file13  file2   file26  file32  file39  file45  file51  file7

file14  file20  file27  file33  file4   file46  file52  file8

file15  file21  file28  file34  file40  file47  file53  file9

 

 

**************************************

Identifying the Linux file system Type

Release:
RHEL

Problem:
This document guides you on how to identify the Linux file system type of a partition.
 

Solution:
Method 1:

Using the df command you can know the type of the file system using the “T” switch.

[root@akhisar /]# df -T

Filesystem    Type   1K-blocks      Used Available Use% Mounted on

/dev/mapper/vg_akhisar-lv_root

              ext4     6362016   3340220   2698624  56% /

tmpfs        tmpfs      345956       260    345696   1% /dev/shm

/dev/sda1     ext4      495844     31884    438360   7% /boot

/dev/sr0   iso9660     3516418   3516418         0 100% /media/RHEL_6.1 x86_64 Disc 1

/dev/sr0   iso9660     3516418   3516418         0 100% /mnt

Limitation: Only mounted partitions will be listed by this command.

 

Method 2:

You can use the mount command as root to know the file system type of your partitions:

[root@akhisar /]# mount | grep "^/dev"

/dev/mapper/vg_akhisar-lv_root on / type ext4 (rw)

/dev/sda1 on /boot type ext4 (rw)

/dev/sr0 on /media/RHEL_6.1 x86_64 Disc 1 type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)

/dev/sr0 on /mnt type iso9660 (ro)

Limitation: Only mounted partitions will be listed by this command.

 

Method 3:

You can use the file command as root by inputting the individual device name. Illustration of the same is given below. You may get the device name for the partitions from the “fdisk –l” command output.

[root@akhisar /]# file -sL /dev/sdb2

/dev/sdb2: Linux rev 1.0 ext3 filesystem data

Method 4:

You can check for the entry in /etc/fstab file. The third field refers to the file system.

[root@akhisar /]# cat /etc/fstab

#

# /etc/fstab

# Created by anaconda on Mon Aug 13 17:02:54 2012

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

/dev/mapper/vg_akhisar-lv_root /                       ext4    defaults        1 1

UUID=eb572a9e-49dc-451a-94e1-6d1de54af5d6 /boot                   ext4    defaults        1 2

/dev/mapper/vg_akhisar-lv_swap swap                    swap    defaults        0 0

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

 
Limitations: It may contain only the default entries created during the installation or the one provided by the administrator. It can only be used as a quick reference on the partitions.

 
Method 5:

You can execute the fsck command with the “-N” switch followed by the individual partitions to know the partition file system type.

[root@akhisar /]# fsck -N /dev/sdb2

fsck from util-linux-ng 2.17.2

[/sbin/fsck.ext3 (1) -- /dev/sdb2] fsck.ext3 /dev/sdb2

[root@akhisar /]# fsck -N /dev/sdb1

fsck from util-linux-ng 2.17.2

[/sbin/fsck.ext2 (1) -- /dev/sdb1] fsck.ext2 /dev/sdb1

 

******************************

Using UUIDs as label to identify your filesystems


Release:
Red Hat Enterprise Linux

Problem:
Using UUIDs as label to identify your filesystems.

Solution:

What is an UUID?
A universally unique identifier (UUID) is an identifier standard used in software construction, standardized by the Open Software Foundation (OSF) as part of the Distributed Computing Environment (DCE). A UUID is a 16-octet (128-bit) number. In its canonical form, a UUID is represented by 32 hexadecimal digits, displayed in five groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters (32 digits and four hyphens). For example:
550e8400-e29b-41d4-a716-446655440000

There are 340,282,366,920,938,463,463,374,607,431,768,211,456 possible UUIDs (16 to the 32nd power or 2 to the 128th power), or ~3.4 × 1038.

UUID in Linux
In Linux, the ext2/ext3/ext4 filesystem also uses UUID to identify partitions. You are not at the safer side if you are using device node names like /dev/sda1 to refer your file system in your /etc/fstab. This is due to the fact that these device node names can change due to switching of cable or upgrading certain packages. So instead of the device node names you may consider using the UUID or LABELs in non-LVM systems.

Determine what is your current entry of the /etc/fstab by using the below command.
# grep /dev/[hsv]d /etc/fstab
/dev/sda1               /boot                   ext4    defaults        1 2
/dev/sda3               /data                   ext4    defaults        0 2

Replace the device entries which point to the device node names like /dev/sda with the UUID or the Label. In this session we will be considering the UUID. You may use the blkid command for getting the UUID of the concerned devices.


# blkid | grep sd
/dev/sda1: LABEL="/boot" UUID="c9fdb384-19ed-4b94-b29e-23f0f566e970"  TYPE="ext4"
/dev/sda3: UUID="80a27dc2-c309-4cc8-9ceb-3bb1a055cf3d" TYPE="ext4"

Following this example, the above lines from /etc/fstab will look like this after being fixed:
LABEL="/boot"                                 /boot   ext4    defaults        1 2
UUID="80a27dc2-c309-4cc8-9ceb-3bb1a055cf3d"   /data   ext4    defaults        0 2

Check the /etc/grub.conf for the use of device node names for non-LVM device nodes to identify the root file system. If present, change the entry by putting in either the label or the UUID.

Non-recommended Entry:
# grep kernel /etc/grub.conf
    kernel /vmlinuz-2.6.18-308.el5 ro root=/dev/sda2

Recommended Entry:
kernel /vmlinuz-2.6.18-308.el5 ro root=LABEL=/
OR
kernel /vmlinuz-2.6.18-308.el5 ro root=UUID=f52529cb-a959-4a11-8d43-0e4fd8fdecd2


******************

Protection of critical files from unauthorized or unknown delete

Release:

Linux Flavors with ext2 based file system

 

Problem:

Protecting critical files from unauthorized or unknown delete

 

Solution:

You can use the Chattr command for protecting your critical files from unauthorized or unknown deletion. Chattr is the acronym for Change file attributes. It is similar to the chmod command in Linux but having a different invocation and syntax. It only works with ext2/ext3/ext4 filesystems.

 

Once you have given the chattr +i <filename>, the particular file is made as immutable. Then file cannot be modified, linked or deleted even by the root user. One cannot see the overridden rule by using the normal permission check commands. Once set the attribute, it can be removed only by the root user. Demo on it is shown below.

 

At first we will create a file with the filename as mysafefile which is to be made safe from modification or deletion.

 

[root@testing Desktop]# touch mysafefile

 

Now let us view the default permission for the file using the below command.

 

[root@testing Desktop]# ll mysafefile

-rw-r--r-- 1 root root 0 Aug 27 12:37 mysafefile

So the root is having read write permission, the group root and others are having the read-only permission.

 

Now let us protect our file from unknown modification or deletion by adding the immutable option using the string “+i”.

[root@testing Desktop]# chattr +i mysafefile

 

So we will now check whether there was any change in the permission for the created file.

[root@testing Desktop]# ll mysafefile

-rw-r--r-- 1 root root 0 Aug 27 12:37 mysafefile

 

The permission has no visible change using normal permission check. It remains the same. We will now try editing the file which we have protected using the chattr command.

 

#vi mysafefile


 

Once you have opened the file you can see at the bottom left of the file that the file is read-only. Hence you will be unable to edit the file. We will now try now what if we try to delete this file.

 [root@testing Desktop]# rm -f mysafefile

rm: cannot remove `mysafefile': Operation not permitted

So the root user is also not able to delete the file. Now let us check on how we can view the overridden permission. You can use the lsattr <filename> command for viewing the attributes currently set for the file.

 [root@testing Desktop]# lsattr mysafefile

----i-------- mysafefile


You can now see the “i” attribute set for the file which prevented it from the deletion. Inorder to clear the attribute you can give the below command.

[root@testing Desktop]# chattr -i mysafefile

Confirm the clear using the lsattr command.

[root@testing Desktop]# lsattr mysafefile

------------- mysafefile

 

Running a physical Inventory in a VERITAS Netbackup



Release:
Symantec VERITAS Netbackup 6.5 for Windows

Problem:
This document guides you through the scenarios where you can use a physical Inventory and how it can accomplish your requirement.

Solution:
Let us considering the following situations:
Ø  For the robots without bar code readers
Ø  For the robots that contain media without bar codes
Generally the Netbackup administrative console will report the presence of the media in the above cases whereas more detailed information is required to perform automated media management. In this scenario we need to go for vmphyinv or what we call as a physical inventory utility.

Features of Vmphyinv
Ø  Can be run from any master server, media server, or SAN media server.
Ø  Can be used with bar coded tape libraries because it verifies the contents of the media.
Ø  Recognizes the NetBackup and the Backup Exec tape formats.
Ø  Supports the remote administration. You do not need to run vmphyinv from the host to which the drives are attached.
Ø  Tries to use multiple drives in a robot even if the drives are attached to different hosts.
Ø  Works with shared drives (NetBackup Shared Storage Option).
Ø  Supports all supported SCSI-based robot types.
Ø  Can be used to inventory a single media in a standalone drive. Use the -u option or the -n option to specify the drive; the drive must contain media and it must be ready.

Applications Of vmphyinv
ü  You may use the vmphyinv to update the EMM server in the following cases:
ü  If you want to run an inventory on a robot that does not have a bar code reader or that contains nonbar coded media.
ü  If you have inserted a new media into a robotic library and no NetBackup volume records correspond to the media. Use the slot range or list option of vmphyinv to perform the inventory operation. You do not need to add volume records to the EMM database.
ü  You insert some media that have unknown media IDs or globally unique identifiers (GUIDs) into a robot. For example, you insert 10 media from a different tape library in slots 11 to 20. You do not know the IDs on the tapes. Use the slot range or list option of vmphyinv to perform the inventory operation. The vmphyinv utility mounts the media, reads the tape header, determines the media ID, and adds media records to the EMM database.
ü  In cases where some of the media are misplaced and the EMM database does not reflect the correct physical location of these media. Inventory the robot or inventory a subset of media in the robot by using options in vmphyinv.

In all the above scenarios vmphyinv will be executing the below operations:
ü  Mounts each tape
ü  Reads the tape header
ü  Identifies the tape in each slot
ü  Updates the NetBackup volume configuration

For initiating a physical inventory you need use the below command syntax in command prompt:
C:\> C:\Program Files\Veritas\Volmgr\bin\vmphyinv -rn <robot_number> -slot_range <from to> -d <density>

Please find an example below. Here we are having 23 slots starting from 1 to 23, there is a single robot with robot number “0” and the density for the tape is hcart in the media server iffco_bkp:
C:\> C:\Program Files\Veritas\Volmgr\bin\vmphyinv -rn 0 -slot_range 1 23 –hcart
----------------------Sample Output----Media Server:iffco_bkp---------------------
Waiting for mount of media ID A00139 on host iffco_bkp
Mounted media ID A00139 on host iffco_bkp
Waiting for mount of media ID A00140 on host iffco_bkp
Mounted media ID A00140 on host iffco_bkp
Waiting for mount of media ID A00141 on host iffco_bkp
Mounted media ID A00141 on host iffco_bkp
Waiting for mount of media ID A00142 on host iffco_bkp
Mounted media ID A00142 on host iffco_bkp
Waiting for mount of media ID A00143 on host iffco_bkp
Mounted media ID A00143 on host iffco_bkp
Waiting for mount of media ID A00144 on host iffco_bkp
Mounted media ID A00144 on host iffco_bkp
Waiting for mount of media ID A00145 on host iffco_bkp
Mounted media ID A00145 on host iffco_bkp
Waiting for mount of media ID A00146 on host iffco_bkp
Mounted media ID A00146 on host iffco_bkp
Waiting for mount of media ID A00147 on host iffco_bkp
Mounted media ID A00147 on host iffco_bkp
Waiting for mount of media ID A00148 on host iffco_bkp
Mounted media ID A00148 on host iffco_bkp


----------------------Sample Output----Media Server:iffco_bkp---------------------
Waiting for mount of media ID A00161 on host iffco_bkp
Mounted media ID A00161 on host iffco_bkp
Waiting for mount of media ID A00150 on host iffco_bkp
Mounted media ID A00150 on host iffco_bkp
Waiting for mount of media ID A00151 on host iffco_bkp
Mounted media ID A00151 on host iffco_bkp
Waiting for mount of media ID A00152 on host iffco_bkp
Mounted media ID A00152 on host iffco_bkp
Waiting for mount of media ID A00153 on host iffco_bkp
Mounted media ID A00153 on host iffco_bkp
Waiting for mount of media ID A00154 on host iffco_bkp
Mounted media ID A00154 on host iffco_bkp
Waiting for mount of media ID A00155 on host iffco_bkp
Mounted media ID A00155 on host iffco_bkp
Waiting for mount of media ID A00156 on host iffco_bkp
Mounted media ID A00156 on host iffco_bkp
Waiting for mount of media ID A00157 on host iffco_bkp
Mounted media ID A00157 on host iffco_bkp
Waiting for mount of media ID A00158 on host iffco_bkp
Mounted media ID A00158 on host iffco_bkp
Waiting for mount of media ID A00159 on host iffco_bkp
Mounted media ID A00159 on host iffco_bkp
Waiting for mount of media ID A00160 on host iffco_bkp
Mounted media ID A00160 on host iffco_bkp
Waiting for mount of media ID A00162 on host iffco_bkp
Mounted media ID A00162 on host iffco_bkp

Proposed Change(s) to Update the Volume Configuration
=====================================================
Logically move media ID A00141 from slot 3 to standalone
Logically add new media A00040 to robot slot 3.
Logically move media ID A00144 from slot 6 to standalone
Logically add new media A00068 to robot slot 6.
Logically move media ID A00146 from slot 8 to standalone
Logically add new media A00041 to robot slot 8.
Logically move media ID A00147 from slot 9 to standalone
Logically add new media A00062 to robot slot 9.
Logically move media ID A00148 from slot 10 to standalone
Logically move media ID A00063 to slot 10.
Logically move media ID A00161 from slot 11 to standalone
Logically add new media A00048 to robot slot 11.
Logically move media ID A00150 from slot 12 to standalone
Logically move media ID A00057 to slot 12.
Logically move media ID A00151 from slot 13 to standalone
Logically move media ID A00050 to slot 13.
Logically move media ID A00152 from slot 14 to standalone
Logically add new media A00064 to robot slot 14.
Logically move media ID A00153 from slot 15 to standalone
Logically move media ID A00060 to slot 15.
Logically move media ID A00154 from slot 16 to standalone
Logically move media ID A00053 to slot 16.
Logically move media ID A00155 from slot 17 to standalone
Logically move media ID A00054 to slot 17.
Logically move media ID A00156 from slot 18 to standalone
Logically move media ID A00055 to slot 18.
Logically move media ID A00157 from slot 19 to standalone
Logically add new media A00056 to robot slot 19.
----------------------Sample Output----Media Server:iffco_bkp---------------------
Logically move media ID A00158 from slot 20 to standalone
Logically add new media A00043 to robot slot 20.
Logically move media ID A00159 from slot 21 to standalone
Logically add new media A00058 to robot slot 21.
Logically move media ID A00160 from slot 22 to standalone
Logically move media ID A00059 to slot 22.
Logically move media ID A00162 from slot 23 to standalone
Logically move media ID A00052 to slot 23.

        Update volume configuration? (y/n) n: y

Moved media ID A00141 from slot 3 to standalone residence
Added new media A00040 to slot 3 on host iffco_bkp.
Moved media ID A00144 from slot 6 to standalone residence
Added new media A00068 to slot 6 on host iffco_bkp.
Moved media ID A00146 from slot 8 to standalone residence
Added new media A00041 to slot 8 on host iffco_bkp.
Moved media ID A00147 from slot 9 to standalone residence
Added new media A00062 to slot 9 on host iffco_bkp.
Moved media ID A00148 from slot 10 to standalone residence
Moved media ID A00063 to slot 10.
Moved media ID A00161 from slot 11 to standalone residence
Added new media A00048 to slot 11 on host iffco_bkp.
Moved media ID A00150 from slot 12 to standalone residence
Moved media ID A00057 to slot 12.
Moved media ID A00151 from slot 13 to standalone residence
Moved media ID A00050 to slot 13.
Moved media ID A00152 from slot 14 to standalone residence
Added new media A00064 to slot 14 on host iffco_bkp.
Moved media ID A00153 from slot 15 to standalone residence
Moved media ID A00060 to slot 15.
Moved media ID A00154 from slot 16 to standalone residence
Moved media ID A00053 to slot 16.
Moved media ID A00155 from slot 17 to standalone residence
Moved media ID A00054 to slot 17.
Moved media ID A00156 from slot 18 to standalone residence
Moved media ID A00055 to slot 18.
Moved media ID A00157 from slot 19 to standalone residence
Added new media A00056 to slot 19 on host iffco_bkp.
Moved media ID A00158 from slot 20 to standalone residence
Added new media A00043 to slot 20 on host iffco_bkp.
Moved media ID A00159 from slot 21 to standalone residence
Added new media A00058 to slot 21 on host iffco_bkp.
Moved media ID A00160 from slot 22 to standalone residence
Moved media ID A00059 to slot 22.
Moved media ID A00162 from slot 23 to standalone residence
Moved media ID A00052 to slot 23.


For further customization and running the vmphyinv to suit your scenario and further examples on the same you may use the below link:


****************