Creation of a partion for an unallocated area

For executing it, have to follow this nice tutorial - https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html-single/storage_administration_guide/#s2-disk-storage-parted-create-part

either fron the beginning of OS_setup it's possible to divide storage to proper parts

by creating logical volumes for cache

lv_cache 12Glv_cache_meta 24M

or later, after running newly deployed server

  • lsblk

NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda                       252:0    0   50G  0 disk
├─vda1                    252:1    0  953M  0 part /boot
└─vda2                    252:2    0 45.7G  0 part
  ├─centos7-root          253:0    0 30.8G  0 lvm  /
  ├─centos7-swap          253:1    0  2.8G  0 lvm  [SWAP]
  ├─centos7-home          253:2    0  956M  0 lvm  /home
  ├─centos7-lv_cache      253:3    0 11.2G  0 lvm  /cache/lv_cache
  └─centos7-lv_cache_meta 253:4    0   24M  0 lvm  /cache/lv_cache_meta

  • lvconvert --type cache-pool --cachemode writethrough --poolmetadata centos7/lv_cache_meta centos7/lv_cache

  WARNING: Converting logical volume centos7/lv_cache and centos7/lv_cache_meta to cache pool's data and metadata volumes with metadata wiping.
  THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)
Do you really want to convert centos7/lv_cache and centos7/lv_cache_meta? [y/n]: y
  Logical volume centos7/lv_cache_meta contains a filesystem in use.
  Aborting. Failed to deactivate centos7/lv_cache_meta.

  • umount /cache/lv_cache_meta
  • umount /cache/lv_cache
  • lvconvert --type cache-pool --cachemode writethrough --poolmetadata centos7/lv_cache_meta centos7/lv_cache
      WARNING: Converting logical volume centos7/lv_cache and centos7/lv_cache_meta to cache pool's data and metadata volumes with metadata wiping.
      THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)
    Do you really want to convert centos7/lv_cache and centos7/lv_cache_meta? [y/n]: y
      Volume group "centos7" has insufficient free space (2 extents): 6 required.
  •  pvs
      PV         VG      Fmt  Attr PSize  PFree
      /dev/vda2  centos7 lvm2 a--  45.67g 8.00m
  • lvreduce -L 11G /dev/centos7/lv_cache
      Size of logical volume centos7/lv_cache changed from 11.18 GiB (2861 extents) to 11.00 GiB (2816 extents).
      Logical volume centos7/lv_cache successfully resized.
  • lvconvert --type cache-pool --cachemode writethrough --poolmetadata centos7/lv_cache_meta centos7/lv_cache
      WARNING: Converting logical volume centos7/lv_cache and centos7/lv_cache_meta to cache pool's data and metadata volumes with metadata wiping.
      THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)
    Do you really want to convert centos7/lv_cache and centos7/lv_cache_meta? [y/n]: y
      Converted centos7/lv_cache to cache pool.
  •  lvs -a -o +devices
      LV               VG      Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert Devices
      home             centos7 -wi-ao---- 956.00m                                                     /dev/vda2(0)
      lv_cache         centos7 Cwi---C---  11.00g                                                     lv_cache_cdata(0)
      [lv_cache_cdata] centos7 Cwi-------  11.00g                                                     /dev/vda2(955)
      [lv_cache_cmeta] centos7 ewi-------  24.00m                                                     /dev/vda2(3816)
      [lvol0_pmspare]  centos7 ewi-------  24.00m                                                     /dev/vda2(3771)
      root             centos7 -wi-ao----  30.73g                                                     /dev/vda2(3822)
      swap             centos7 -wi-ao----   2.80g                                                     /dev/vda2(239)
  •  lvconvert --type cache --cachepool centos7/lv_cache centos7/root
    Do you want wipe existing metadata of cache pool volume centos7/lv_cache? [y/n]: y
      Logical volume centos7/root is now cached.
  • lvs -a -o +devices
      LV               VG      Attr       LSize   Pool       Origin       Data%  Meta%  Move Log Cpy%Sync Convert Devices
      home             centos7 -wi-ao---- 956.00m                                                                 /dev/vda2(0)
      [lv_cache]       centos7 Cwi---C---  11.00g                         0.00   5.91            0.00             lv_cache_cdata(0)
      [lv_cache_cdata] centos7 Cwi-ao----  11.00g                                                                 /dev/vda2(955)
      [lv_cache_cmeta] centos7 ewi-ao----  24.00m                                                                 /dev/vda2(3816)
      [lvol0_pmspare]  centos7 ewi-------  24.00m                                                                 /dev/vda2(3771)
      root             centos7 Cwi-aoC---  30.73g [lv_cache] [root_corig] 0.00   5.91            0.00             root_corig(0)
      [root_corig]     centos7 owi-aoC---  30.73g                                                                 /dev/vda2(3822)
      swap             centos7 -wi-ao----   2.80g                                                                 /dev/vda2(239)
  • lsblk
    NAME                       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    vda                        252:0    0   50G  0 disk
    ├─vda1                     252:1    0  953M  0 part /boot
    └─vda2                     252:2    0 45.7G  0 part
      ├─centos7-swap           253:1    0  2.8G  0 lvm  [SWAP]
      ├─centos7-home           253:2    0  956M  0 lvm  /home
      ├─centos7-lv_cache_cdata 253:3    0   11G  0 lvm
      │ └─centos7-root         253:0    0 30.8G  0 lvm  /
      ├─centos7-lv_cache_cmeta 253:4    0   24M  0 lvm
      │ └─centos7-root         253:0    0 30.8G  0 lvm  /
      └─centos7-root_corig     253:5    0 30.8G  0 lvm
        └─centos7-root         253:0    0 30.8G  0 lvm  /

    Rebuild initramfs

  • nano /etc/fstab
#/dev/mapper/centos7-lv_cache /cache/lv_cache         ext4    defaults        1 2
#/dev/mapper/centos7-lv_cache_meta /cache/lv_cache_meta    ext4    defaults        1 2

 
# dracut -v -f

This will rebuild the initramfs to include the cache LV.

use the dracut -f command to rebuild the initial ramdisk ( initrd ), and reboot the system for the changes to take effect.

https://wiki.centos.org/TipsAndTricks/CreateNewInitrd

dracut --regenerate-all -f && grub2-mkconfig -o /boot/grub2/grub.cfg

 

Creating a New Initial RAM Disk

If you have changed a motherboard or moved a disk to a different system it may fail to boot due to the lack of appropriate drivers in the initial RAM disk image (initramfs for CentOS 6).

Boot in Rescue Mode

  1. Boot from a CentOS installation disc (for example, CD #1 or DVD).
  2. Type "linux rescue" at the "boot:" prompt.

  3. Mount all filesystems in read-write mode.

 

Create the New Initramfs or Initrd

Change root to real root ('/') on your hard disk and make the new initramfs or initrd.

mount --bind /proc /mnt/sysimage/proc
mount --bind /dev /mnt/sysimage/dev
mount --bind /sys /mnt/sysimage/sys
chroot /mnt/sysimage

For CentOS 7 and multipathed root ('/') issue the following before chroot-ing to '/mnt/sysimage':

mount --bind /run /mnt/sysimage/run
systemctl start multipathd.service

For CentOS 6:

  • Create a backup copy of the current initramfs:

    cp -p /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
    
  • Now create the initramfs for the current kernel:

    dracut -f 
    
  • If you need to build it for a specific kernel version (replace the version appropriately):

    dracut -f /boot/initramfs-2.6.32-358.el6.x86_64.img 2.6.32-358.el6.x86_64
    
  • One useful option you might want to add is -H (--hostonly). With this option dracut installs only what is needed for booting your system. Otherwise dracut by default adds many drivers to the initramfs making its size larger than necessary. Many other options may be exercised. Please see man dracut, man dracut.conf and the upstream Deployment Guide.

  • Reboot

    cd /
    sync
    telinit 6

umount /cache

 pvcreate /dev/vda3
   vgextend centos7 /dev/vda3
    lvcreate -L 12G -n lv_cache centos7 /dev/vda3

lvcreate -L 12M -n lv_cache_meta centos7 /dev/vda3

lvextend -L 24M /dev/centos7/lv_cache_meta

lvconvert --type cache-pool --cachemode writethrough --poolmetadata centos7/lv_cache_meta centos7/lv_cache

 lvs -a -o +devices

lvconvert --type cache --cachepool centos7/lv_cache centos7/root

lvs -a -o +devices


 

 

pvs
    2  lsblk
    3  blkid
    4  fdisk /dev/vda
 
    6  partprobe
    7  blkid
    8  lsblk
    9  cat /proc/partitions
   10  mkfs.ext4 /dev/vda3
   11  e2label /dev/vda3 "LVM Cache"
   13  mkdir /storage/cache
   14  mount  /dev/vda3 /storage/cache
   15  blkid -o list
   16  cat /etc/fstab

   18  yum install nano
   19  nano /etc/fstab
   20  systemctl daemon-reload
   21  mount /storage/cache
   22  reboot
  


Creation -> Logical Volume inside of Partition

fdisk /dev/vdb

pvcreate /dev/vdb2 /dev/vdb1

vgcreate storage /dev/vdb1 /dev/vdb2

lvcreate -n website -L 12G storage /dev/vdb1

 mkfs.ext4 /dev/storage/website

e2label /dev/storage/website "Web Storage"

mkdir /storage_data

mount /dev/storage/website /storage_data

 

 

  1. fdisk /dev/vdb

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/vdb: 27.9 GB, 27917287424 bytes, 54525952 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 label type: dos
Disk identifier: 0x07abb460
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-54525951, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-54525951, default 54525951):
Using default value 54525951
Partition 1 of type Linux and of size 26 GiB is set

Command (m for help): 8e
8: unknown command
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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): w
The partition table has been altered!

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

  1. pvcreate /dev/vdb1
      Physical volume "/dev/vdb1" successfully created.
  2. vgcreate storage /dev/vdb1
      Volume group "storage" successfully created
  3.  lvcreate -n rescue -L 25.9G  storage /dev/vdb1
      Rounding up size to full physical extent 25.90 GiB
      Logical volume "rescue" created.
  4. lvdisplay
     --- Logical volume ---
      LV Path                /dev/storage/rescue
      LV Name                rescue
      VG Name                storage
      LV UUID                Dup9lR-m3Iu-rGs4-utWs-Lsmn-3Aii-fks4qe
      LV Write Access        read/write
      LV Creation host, time website.development.hk, 2019-04-12 12:17:09 +0100
      LV Status              available
      # open                 0
      LV Size                25.90 GiB
      Current LE             6631
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:6
  5.  mkfs.xfs /dev/storage/rescue
    meta-data=/dev/storage/rescue    isize=512    agcount=4, agsize=1697536 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=6790144, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=3315, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
  6. lsblk
  7. mkdir /rescue
  8. mount /dev/storage/rescue /rescue
  9. blkid
  10. man fstab
  11. nano /etc/fstab
  12. systemctl daemon-reload