Saturday, November 29, 2014

Filesystem management

Adding Disk:

##############################     PERL    scan for new disk     ######################
#!/usr/bin/perl -w
use strict;

my $dir = '/sys/class/scsi_host';
opendir(DIR, $dir) or die $!;

while (my $file = readdir(DIR)) {

       # Use a regular expression to ignore files beginning with a period
        next if ($file =~ m/^\./);
        print "$file\n";
        system("echo '- - -' > /sys/class/scsi_host/$file/scan");
    }
system("fdisk -l |grep -i disk |grep -i bytes");
closedir(DIR);
exit 0;
#########################################################################################

Deleting Disk:

########################## Removing disk from system#####################################
root@centOS # pvremove /dev/<disk_name>
  PV /dev/sdc belongs to Volume Group vg_rhel so please use vgreduce first.
  (If you are certain you need pvremove, then confirm by using --force twice.)

root@centOS # vgreduce vg_rhel /dev/sdc
  Removed "/dev/sdc" from volume group "vg_rhel"

root@centOS #  pvremove /dev/sdc
  Labels on physical volume "/dev/sdc" successfully wiped

root@centOS #  pvs
  PV         VG           Fmt  Attr PSize  PFree
  /dev/sda2  vg_rhel lvm2 a--  19.51g      0
  /dev/sdb   vg_rhel lvm2 a--   5.00g 292.00m

root@centOS # blockdev --flushbufs /dev/sdc

root@centOS #  echo 1 > /sys/block/sdc/device/delete

#########################################################################################

vgs

vgextend vg_rhel /dev/sdb

lsdisplay

lvextend -L10G /dev/mapper/rootVG-var   Extend the size of the underlying volume 

resize2fs /dev/mapper/rootVG-var        Resize the filesystem to the new size of the underlying volume 

root@rhel-gpfs # lvcreate -L1G test_vg
  Logical volume "lvol0" created

root@rhel-gpfs # lvcreate -L500M -ntest_lv test_vg
  Logical volume "test_lv" created


root@rhel-gpfs # vgs
  Couldn't find device with uuid peSePJ-x6iW-YQwn-YqQw-7ejV-K85k-Yk1vrI.
  Couldn't find device with uuid r7Uk76-GAX3-2NBV-wckH-hMKD-JAaB-1HgoqN.
  VG           #PV #LV #SN Attr   VSize  VFree
  vg_rhel   4   6   0 wz-pn- 36.50g 17.85g

root@rhel-gpfs # vgreduce --removemissing vg_rhel
  Couldn't find device with uuid peSePJ-x6iW-YQwn-YqQw-7ejV-K85k-Yk1vrI.
  Couldn't find device with uuid r7Uk76-GAX3-2NBV-wckH-hMKD-JAaB-1HgoqN.

  Wrote out consistent volume group vg_rhel

####################################################
Adding disk:

root@rhel-gpfs # fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x468f4a0e.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): quit

root@rhel-gpfs # ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2        /dev/sdb

root@rhel-gpfs # fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x58ecb49b.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): c
DOS Compatibility flag is not set

Command (m for help): u
Changing display/entry units to sectors

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x58ecb49b

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-4194303, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303):
Using default value 4194303

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

Calling ioctl() to re-read partition table.
Syncing disks.
root@rhel-gpfs # ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2        /dev/sdb  /dev/sdb1
root@rhel-gpfs # /sbin/mkfs.ext4 -L /backup /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=/backup
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524032 blocks
26201 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

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

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
root@rhel-gpfs # mkdir /backup
root@rhel-gpfs # mount /dev/sdb1 /backup
root@rhel-gpfs # mount
/dev/mapper/vg_rhel-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)
/dev/mapper/vg_rhel-LogVol02 on /home type ext4 (rw)
/dev/mapper/vg_rhel-LogVol03 on /tmp type ext4 (rw)
/dev/mapper/vg_rhel-LogVol04 on /usr type ext4 (rw)
/dev/mapper/vg_rhel-LogVol05 on /var type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sdb1 on /backup type ext4 (rw)

No comments:

Post a Comment