rhel 67 – shrink expand lvm partition

the default rhel 6.7 partition, “/” partition only have 50GB and the “/home” get the rest

if you only have 90GB for rhel, it would split  / to 50GB and /home 40GB. but if you have TeraByte space / get 50GB and /home get TeraByte

problem when you use / for default database storage, which store the data in / partition, 50GB so small for database.

the advantage using lvm partition, you can shrink the partition, and give the free space for other partition

i will try reduce /home space and add it to

# test
[root@rhel67 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_rhel67-lv_root
 50G 1.9G 45G 4% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 477M 41M 411M 10% /boot
/dev/mapper/vg_rhel67-lv_home
 45G 52M 43G 1% /home

[root@rhel67 ~]# pvs
  PV         VG        Fmt  Attr PSize  PFree
  /dev/sda2  vg_rhel67 lvm2 a--  99.51g    0 

[root@rhel67 ~]# vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  vg_rhel67   1   3   0 wz--n- 99.51g    0 

[root@rhel67 ~]# lvs
  LV      VG        Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_home vg_rhel67 -wi-ao---- 45.63g                                                    
  lv_root vg_rhel67 -wi-ao---- 50.00g                                                    
  lv_swap vg_rhel67 -wi-ao----  3.88g
  
# step to reduce
[root@rhel67 ~]# umount /home

# check system error
[root@rhel67 ~]# e2fsck -ff /dev/mapper/vg_rhel67-lv_home
e2fsck 1.41.12 (17-May-2010)
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/mapper/vg_rhel67-lv_home: 11/2992416 files (0.0% non-contiguous), 233857/11962368 blocks

# now cut the space
[root@rhel67 ~]# resize2fs /dev/mapper/vg_rhel67-lv_home 20G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_rhel67-lv_home to 5242880 (4k) blocks.
The filesystem on /dev/mapper/vg_rhel67-lv_home is now 5242880 blocks long.

# resize authority
[root@rhel67 ~]# lvreduce -L -19G /dev/mapper/vg_rhel67-lv_home  
  WARNING: Reducing active logical volume to 26.63 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
  Size of logical volume vg_rhel67/lv_home changed from 45.63 GiB (11682 extents) to 26.63 GiB (6818 extents).
  Logical volume lv_home successfully resized

[root@rhel67 ~]# lvdisplay /dev/vg_rhel67/lv_home
  --- Logical volume ---
  LV Path                /dev/vg_rhel67/lv_home
  LV Name                lv_home
  VG Name                vg_rhel67
  LV UUID                TG9ipf-EeEA-jKN6-BrG2-J3Gx-mXz2-tylb4X
  LV Write Access        read/write
  LV Creation host, time rhel67, 2017-07-04 04:05:41 +0700
  LV Status              available
  # open                 0
  LV Size                26.63 GiB
  Current LE             6818
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

[root@rhel67 ~]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
1024*20
20480
2048/4
512

[root@rhel67 ~]# lvreduce -l -512 /dev/vg_rhel67/lv_home
  WARNING: Reducing active logical volume to 24.63 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
  Size of logical volume vg_rhel67/lv_home changed from 26.63 GiB (6818 extents) to 24.63 GiB (6306 extents).
  Logical volume lv_home successfully resized

[root@rhel67 ~]# resize2fs /dev/vg_rhel67/lv_home
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg_rhel67/lv_home to 6457344 (4k) blocks.
The filesystem on /dev/vg_rhel67/lv_home is now 6457344 blocks long.

[root@rhel67 ~]# mount /dev/vg_rhel67/lv_home /home

[root@rhel67 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_rhel67-lv_root
                       50G  1.9G   45G   4% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/sda1             477M   41M  411M  10% /boot
/dev/mapper/vg_rhel67-lv_home
                       25G   44M   23G   1% /home

# now check
[root@rhel67 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_rhel67
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               99.51 GiB
  PE Size               4.00 MiB
  Total PE              25474
  Alloc PE / Size       20098 / 78.51 GiB
  Free  PE / Size       5376 / 21.00 GiB
  VG UUID               DYk8Up-pACU-XZco-ZuEw-iXLL-G98b-gDUSyP
   
[root@rhel67 ~]# pvs
  PV         VG        Fmt  Attr PSize  PFree 
  /dev/sda2  vg_rhel67 lvm2 a--  99.51g 21.00g

[root@rhel67 ~]# lvs
  LV      VG        Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_home vg_rhel67 -wi-ao---- 24.63g                                                    
  lv_root vg_rhel67 -wi-ao---- 50.00g                                                    
  lv_swap vg_rhel67 -wi-ao----  3.88g

# check how much freespace 
[root@rhel67 ~]# pvscan
  PV /dev/sda2   VG vg_rhel67   lvm2 [99.51 GiB / 21.00 GiB free]
  Total: 1 [99.51 GiB] / in use: 1 [99.51 GiB] / in no VG: 0 [0   ]

[root@rhel67 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_rhel67
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               99.51 GiB
  PE Size               4.00 MiB
  Total PE              25474
  Alloc PE / Size       20098 / 78.51 GiB
  Free  PE / Size       5376 / 21.00 GiB
  VG UUID               DYk8Up-pACU-XZco-ZuEw-iXLL-G98b-gDUSyP

# check size partition
[root@rhel67 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_rhel67-lv_root
                       50G  1.9G   45G   4% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/sda1             477M   41M  411M  10% /boot
/dev/mapper/vg_rhel67-lv_home
                       25G   44M   23G   1% /home

# now expand the freespace
[root@rhel67 ~]# resize2fs /dev/vg_rhel67/lv_root 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_rhel67/lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 5
Performing an on-line resize of /dev/vg_rhel67/lv_root to 18612224 (4k) blocks.
The filesystem on /dev/vg_rhel67/lv_root is now 18612224 blocks long.

# check again the size
[root@rhel67 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_rhel67-lv_root
                       70G  1.9G   65G   3% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/sda1             477M   41M  411M  10% /boot
/dev/mapper/vg_rhel67-lv_home
                       25G   44M   23G   1% /home
Advertisements

redhat – local dvd repo

# mounting iso to redhat

mount -o loop rhel7.iso /mnt/rhel7

# or locate where the dvd mount, ex /mnt/rhel7

ln -s /mnt/rhel7 /tmp/rhel7

# create new repo to dvd

nano  /etc/yum.repos.d/rhel7.repo

# input this code

[RepoLocal]
name=baseurl
baseurl=file:///tmp/rhel7/
enable=1
gpgcheck=0

# clean repo and makecache

yum clean all && yum makecache

# test to install

yum install perl

set sftp in redhat

# create user ftprhel
useradd ftprhel
passwd ftprhel

# create new group
groupadd sftpusers

# modify an existing user and make him an sftp user only and put him in the chroot sftp jail, do the following
usermod -g sftpusers -d /incoming -s /sbin/nologin ftprhel

#Setup sftp-server Subsystem in sshd_config
nano /etc/ssh/sshd_config

# comment sftp, add commet to sftp
#Subsystem      sftp    /usr/libexec/openssh/sftp-server

# add new value Subsystem sftp
Subsystem       sftp    internal-sftp

# show what sftp value
grep sftp /etc/ssh/sshd_config

# Specify Chroot Directory for a Group
# add this three line to /etc/ssh/sshd_config
    Match Group sftpusers
        ChrootDirectory /sftp/%u
        ForceCommand internal-sftp

# Create sftp Home Directory
mkdir -p /sftp/ftprhel/incoming

# give appropriate permission
chown ftprhel:sftpusers /sftp/ftprhel/incoming

#restart sshd
service sshd restart

# test with sftp client, filezilla or winscp, or linux sftp
#if you have error
#Error listing directory ‘incoming’
#Permission denied.
#Error code: 3
#Error message from server: Permission denied
#Request code: 11

# enforce SELinux 
setenforce 0

source http://www.thegeekstuff.com/2012/03/chroot-sftp-setup/