0% found this document useful (0 votes)
21 views48 pages

Partioning 2

The document provides a detailed guide on how to add, partition, format, and manage a new disk in a Linux environment using fdisk and other commands. It includes steps for creating partitions, formatting them with a filesystem, updating the /etc/fstab for persistent mounting, and instructions for removing or decommissioning a disk. Additionally, it covers creating swap partitions and managing disk settings using command-line tools.

Uploaded by

mithun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views48 pages

Partioning 2

The document provides a detailed guide on how to add, partition, format, and manage a new disk in a Linux environment using fdisk and other commands. It includes steps for creating partitions, formatting them with a filesystem, updating the /etc/fstab for persistent mounting, and instructions for removing or decommissioning a disk. Additionally, it covers creating swap partitions and managing disk settings using command-line tools.

Uploaded by

mithun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 48

Linux partitioning disk:

Adding the new desk to vm:-


vmware workstation->righ click on vm->settings->select HD->add-> next-> create a new virtual desk->
scsi(disk type)-> menction the size-> finish

1. Identify the disk/device

[root@classs ~]# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

fd0 2:0 1 4K 0 disk

sda 8:0 0 15G 0 disk

├─sda1 8:1 0 1G 0 part /boot

└─sda2 8:2 0 14G 0 part

├─rhel-root 253:0 0 12.5G 0 lvm /

└─rhel-swap 253:1 0 1.5G 0 lvm [SWAP]

sdb 8:16 0 2G 0 disk

sr0 11:0 1 4.2G 0 rom /run/media/student/RHEL-7.9 Server.x86_64

[root@classs ~]#

2. partition the disk

[root@classs ~]# fdisk /dev/sdb

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.

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0xd968a89a.

Command (m for help): m

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): n

Partition type:

p primary (0 primary, 0 extended, 4 free)

e extended

Select (default p): p

Partition number (1-4, default 1): 1

First sector (2048-4194303, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): +100M

Partition 1 of type Linux and of size 100 MiB is set


Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 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 label type: dos

Disk identifier: 0xd968a89a

Device Boot Start End Blocks Id System

/dev/sdb1 2048 206847 102400 83 Linux

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@classs ~]# kpartx /dev/sdb;partx -a /dev/sdb;partprobe /dev/sdb

sdb1 : 0 204800 /dev/sdb 2048

partx: /dev/sdb: error adding partition 1

[root@classs ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 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 label type: dos

Disk identifier: 0xd968a89a


Device Boot Start End Blocks Id System

/dev/sdb1 2048 206847 102400 83 Linux

[root@classs ~]#

3. Format the partition

Syn: mkfs.<filesyetemtype> partition name.

[root@classs ~]# mkfs.

mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.vfat

mkfs.cramfs mkfs.ext3 mkfs.fat mkfs.msdos mkfs.xfs

[root@classs ~]# mkfs.xfs /dev/sdb1

meta-data=/dev/sdb1 isize=512 agcount=4, agsize=6400 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0, sparse=0

data = bsize=4096 blocks=25600, imaxpct=25

= sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1

log =internal log bsize=4096 blocks=855, version=2

= sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

[root@classs ~]#

4. make entry in /etc/fstab to mount it permanently

[root@classs ~]# blkid /dev/sdb1

/dev/sdb1: UUID="8a224fbb-fac0-47e0-b18f-92254db49445" TYPE="xfs"

[root@classs ~]# vi /etc/fstab

/dev/mapper/rhel-root / xfs defaults 00

UUID=9345f2a6-7e5d-4702-ad97-a7d6720457e7 /boot xfs defaults 00

/dev/mapper/rhel-swap swap swap defaults 00

UUID=8a224fbb-fac0-47e0-b18f-92254db49445 /backup xfs defaults 0 0


5. mount a partitions.

[root@classs ~]# mkdir /backup


[root@classs ~]# mount /dev/sdb1 /backup
[root@classs ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 901M 0 901M 0% /dev
tmpfs tmpfs 917M 0 917M 0% /dev/shm
tmpfs tmpfs 917M 11M 907M 2% /run
tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup
/dev/mapper/rhel-root xfs 13G 4.1G 8.4G 33% /
/dev/sda1 xfs 1014M 184M 831M 19% /boot
tmpfs tmpfs 184M 24K 184M 1% /run/user/1000
/dev/sr0 iso9660 4.3G 4.3G 0 100% /run/media/student/RHEL-7.9 Server.x86_64
tmpfs tmpfs 184M 0 184M 0% /run/user/0
/dev/sdb1 xfs 97M 5.3M 92M 6% /backup
[root@classs ~]#

Removing/decommissioning
disk:
1. Identify the device or mount point
2.
3. Unmount the partition/device
4. Remove the entry from /etc/fstab
5. Remove the partition from the disk.

[root@classs ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 901M 0 901M 0% /dev


tmpfs tmpfs 917M 0 917M 0% /dev/shm

tmpfs tmpfs 917M 11M 907M 2% /run

tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup

/dev/mapper/rhel-root xfs 13G 4.1G 8.4G 33% /

/dev/sda1 xfs 1014M 184M 831M 19% /boot

tmpfs tmpfs 184M 24K 184M 1% /run/user/1000

/dev/sr0 iso9660 4.3G 4.3G 0 100% /mnt

tmpfs tmpfs 184M 0 184M 0% /run/user/0

/dev/sdb1 xfs 97M 5.3M 92M 6% /backup

[root@classs ~]#

[root@classs ~]# umount /backup

[root@classs ~]# rm -rf /backup

[root@classs ~]#

[root@classs ~]# vi /etc/fstab - remove the /backup line by using dd and write and quit

[root@classs ~]#

[root@classs ~]# fdisk /dev/sdb

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/sdb: 2147 MB, 2147483648 bytes, 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 label type: dos

Disk identifier: 0xd968a89a

Device Boot Start End Blocks Id System

/dev/sdb1 2048 206847 102400 83 Linux

Command (m for help): d

Selected partition 1

Partition 1 is deleted

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@classs ~]

Creating the swap partitions.

[root@classs ~]# lsblk /dev/sdb

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sdb 8:16 0 2G 0 disk

└─sdb1 8:17 0 500M 0 part /mnt/new

[root@classs ~]# fdisk /dev/sdb

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): n

Partition type:

p primary (1 primary, 0 extended, 3 free)

e extended

Select (default p): p

Partition number (2-4, default 2):

First sector (1026048-4194303, default 1026048):

Using default value 1026048

Last sector, +sectors or +size{K,M,G} (1026048-4194303, default 4194303): +500M

Partition 2 of type Linux and of size 500 MiB is set

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 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 label type: dos

Disk identifier: 0xd968a89a

Device Boot Start End Blocks Id System

/dev/sdb1 2048 1026047 512000 83 Linux

/dev/sdb2 1026048 2050047 512000 83 Linux

Command (m for help): t

Partition number (1,2, default 2): 2


Hex code (type L to list all codes): l

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris

1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-

2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-

3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-

4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx

5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data

6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .

7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility

8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt

9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access

a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O

b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor

c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs

e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT

f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/

10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b

11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor

12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor

14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary

16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS

17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE

18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto

1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep

1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT

1e Hidden W95 FAT1 80 Old Minix

Hex code (type L to list all codes): 82

Changed type of partition 'Linux' to 'Linux swap / Solaris'


Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[root@classs ~]# cat /proc/partitions

major minor #blocks name

2 0 4 fd0

8 0 15728640 sda

8 1 1048576 sda1

8 2 14679040 sda2

8 16 2097152 sdb

8 17 512000 sdb1

11 0 4420608 sr0

253 0 13103104 dm-0

253 1 1572864 dm-1

[root@classs ~]# fdisk /dev/sdb -l

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 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 label type: dos


Disk identifier: 0xd968a89a

Device Boot Start End Blocks Id System

/dev/sdb1 2048 1026047 512000 83 Linux

/dev/sdb2 1026048 2050047 512000 82 Linux swap / Solaris

[root@classs ~]# kpartx /dev/sdb

sdb1 : 0 1024000 /dev/sdb 2048

sdb2 : 0 1024000 /dev/sdb 1026048

[root@classs ~]# cat /proc/partitions

major minor #blocks name

2 0 4 fd0

8 0 15728640 sda

8 1 1048576 sda1

8 2 14679040 sda2

8 16 2097152 sdb

8 17 512000 sdb1

11 0 4420608 sr0

253 0 13103104 dm-0

253 1 1572864 dm-1

[root@classs ~]# partx -a /dev/sdb

partx: /dev/sdb: error adding partition 1

[root@classs ~]# cat /proc/partitions

major minor #blocks name

2 0 4 fd0

8 0 15728640 sda

8 1 1048576 sda1

8 2 14679040 sda2
8 16 2097152 sdb

8 17 512000 sdb1

8 18 512000 sdb2

11 0 4420608 sr0

253 0 13103104 dm-0

253 1 1572864 dm-1

[root@classs ~]# mkswap /dev/sdb2

Setting up swapspace version 1, size = 511996 KiB

no label, UUID=34718292-ebda-46b6-a70a-a9ba34b27ec9

[root@classs ~]# blkid /dev/sdb2

/dev/sdb2: UUID="34718292-ebda-46b6-a70a-a9ba34b27ec9" TYPE="swap"

[root@classs ~]# vi /etc/fstab

/dev/sdb2 swap swap defaults 00

[root@classs ~]# swapon /dev/sdb2

[root@classs ~]# swapon -s

Filename Type Size Used Priority

/dev/dm-1 partition 1572860 3592 -2

/dev/sdb2 partition 511996 0 -3

[root@classs ~]#

Creating swap filesystem on


filesystem or use file as swap.

1. Identify the free space on filesystem.


2. Create a file with dd command.
3. Create a swap filesystem by using mkswap.
4. activate swap filesystem. swapon
5. Make entry in /etc/fstab to enable the swap at next reboot/boot up.
[root@classs ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 901M 0 901M 0% /dev

tmpfs tmpfs 917M 0 917M 0% /dev/shm

tmpfs tmpfs 917M 27M 891M 3% /run

tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup

/dev/mapper/rhel-root xfs 13G 4.2G 8.4G 34% /

/dev/sda1 xfs 1014M 184M 831M 19% /boot

tmpfs tmpfs 184M 28K 184M 1% /run/user/1000

/dev/sr0 iso9660 4.3G 4.3G 0 100% /run/media/student/RHEL-7.9 Server.x86_64

tmpfs tmpfs 184M 12K 184M 1% /run/user/42

tmpfs tmpfs 184M 0 184M 0% /run/user/0

/dev/sdb1 xfs 497M 26M 472M 6% /mnt/new

[root@classs ~]# dd if=/dev/zero of=/swap bs=1M count=512

512+0 records in

512+0 records out

536870912 bytes (537 MB) copied, 0.95755 s, 561 MB/s

[root@classs ~]# du -hs /swap

512M /swap

[root@classs ~]# file /swap

/swap: data

[root@classs ~]# mkswap /swap

Setting up swapspace version 1, size = 524284 KiB

no label, UUID=99ed52a9-e033-448e-baee-42e71b1eaaf7

[root@classs ~]# swapon /swap

swapon: /swap: insecure permissions 0644, 0600 suggested.

[root@classs ~]# swapon -s


Filename Type Size Used Priority

/dev/dm-1 partition 1572860 4360 -2

/dev/sdb2 partition 511996 0 -3

/swap file 524284 0 -4

[root@classs ~]# vi /etc/fstab

/swap swap swap defaults 00

[root@classs ~]# free -m

total used free shared buff/cache available

Mem: 1833 984 66 40 782 646

Swap: 2547 4 2543

[root@classs ~]#

Commissioning / removing swap space.


1. Deactivate the swap partition.
2. Remove entry from /etc/fstab
3. Remove the partitions/file from disk or filesystem.
[root@classs ~]# swapon -s

[root@classs ~]# swapoff /swap

[root@classs ~]# swapon -s

Filename Type Size Used Priority

/dev/dm-1 partition 1572860 4176 -2

/dev/sdb2 partition 511996 0 -3

[root@classs ~]# vim /etc/fstab

[root@classs ~]# rm -rf /swap

[root@classs ~]#

======================== partitions======

[root@classs ~]# swapon -s

Filename Type Size Used Priority

/dev/dm-1 partition 1572860 4176 -2


/dev/sdb2 partition 511996 0 -3

[root@classs ~]# swapoff /dev/sdb2

[root@classs ~]# vi /etc/fstab

[root@classs ~]# swapon -s

Filename Type Size Used Priority

/dev/dm-1 partition 1572860 4176 -2

[root@classs ~]# fdisk /dev/sdb

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/sdb: 2147 MB, 2147483648 bytes, 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 label type: dos

Disk identifier: 0xd968a89a

Device Boot Start End Blocks Id System

/dev/sdb1 2048 1026047 512000 83 Linux

/dev/sdb2 1026048 2050047 512000 82 Linux swap / Solaris

Command (m for help): d

Partition number (1,2, default 2): 2


Partition 2 is deleted

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[root@classs ~]# partx /dev/sdb

NR START END SECTORS SIZE NAME UUID

1 2048 1026047 1024000 500M

[root@classs ~]# cat /proc/partitions

major minor #blocks name

2 0 4 fd0

8 0 15728640 sda

8 1 1048576 sda1

8 2 14679040 sda2

8 16 2097152 sdb

8 17 512000 sdb1

8 18 512000 sdb2

11 0 4420608 sr0

253 0 13103104 dm-0

253 1 1572864 dm-1

[root@classs ~]# kpartx /dev/sdb

sdb1 : 0 1024000 /dev/sdb 2048


[root@classs ~]# cat /proc/partitions

major minor #blocks name

2 0 4 fd0

8 0 15728640 sda

8 1 1048576 sda1

8 2 14679040 sda2

8 16 2097152 sdb

8 17 512000 sdb1

8 18 512000 sdb2

11 0 4420608 sr0

253 0 13103104 dm-0

253 1 1572864 dm-1

[root@classs ~]# partprobe /dev/sdb

[root@classs ~]# cat /proc/partitions

major minor #blocks name

2 0 4 fd0

8 0 15728640 sda

8 1 1048576 sda1

8 2 14679040 sda2

8 16 2097152 sdb

8 17 512000 sdb1

11 0 4420608 sr0

253 0 13103104 dm-0

253 1 1572864 dm-1

[root@classs ~]#
.

LVM: Logical volume manager, we can extend the filesystem size in online without interrupting the
services and also it supports snapshot feature.

Logical volume manager (LVM)


o Filesystems may be created on Logical Volumes

[root@classs ~]# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

fd0 2:0 1 4K 0 disk

sda 8:0 0 15G 0 disk

├─sda1 8:1 0 1G 0 part /boot

└─sda2 8:2 0 14G 0 part

├─rhel-root 253:0 0 12.5G 0 lvm /


└─rhel-swap 253:1 0 1.5G 0 lvm [SWAP]

sdb 8:16 0 2G 0 disk

└─sdb1 8:17 0 500M 0 part /mnt/new

sr0 11:0 1 4.2G 0 rom /run/media/student/RHEL-7.9 Server.x86_64

[root@classs ~]# fdisk /dev/sdb

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/sdb: 2147 MB, 2147483648 bytes, 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 label type: dos

Disk identifier: 0xd968a89a

Device Boot Start End Blocks Id System

/dev/sdb1 2048 1026047 512000 83 Linux

Command (m for help): n

Partition type:

p primary (1 primary, 0 extended, 3 free)

e extended

Select (default p): p

Partition number (2-4, default 2):


First sector (1026048-4194303, default 1026048):

Using default value 1026048

Last sector, +sectors or +size{K,M,G} (1026048-4194303, default 4194303): +300M

Partition 2 of type Linux and of size 300 MiB is set

Command (m for help): n

Partition type:

p primary (2 primary, 0 extended, 2 free)

e extended

Select (default p): p

Partition number (3,4, default 3):

First sector (1640448-4194303, default 1640448):

Using default value 1640448

Last sector, +sectors or +size{K,M,G} (1640448-4194303, default 4194303): +100M

Partition 3 of type Linux and of size 100 MiB is set

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 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 label type: dos

Disk identifier: 0xd968a89a

Device Boot Start End Blocks Id System

/dev/sdb1 2048 1026047 512000 83 Linux

/dev/sdb2 1026048 1640447 307200 83 Linux

/dev/sdb3 1640448 1845247 102400 83 Linux


Command (m for help): t

Partition number (1-3, default 3): 3

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): t

Partition number (1-3, default 3): 2

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 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 label type: dos

Disk identifier: 0xd968a89a

Device Boot Start End Blocks Id System

/dev/sdb1 2048 1026047 512000 83 Linux

/dev/sdb2 1026048 1640447 307200 8e Linux LVM

/dev/sdb3 1640448 1845247 102400 8e Linux LVM

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.


WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[root@classs ~]# cat /proc/partitions

major minor #blocks name

2 0 4 fd0

8 0 15728640 sda

8 1 1048576 sda1

8 2 14679040 sda2

8 16 2097152 sdb

8 17 512000 sdb1

11 0 4420608 sr0

253 0 13103104 dm-0

253 1 1572864 dm-1

[root@classs ~]# kpartx /dev/sdb

sdb1 : 0 1024000 /dev/sdb 2048

sdb2 : 0 614400 /dev/sdb 1026048

sdb3 : 0 204800 /dev/sdb 1640448

[root@classs ~]# cat /proc/partitions

major minor #blocks name

2 0 4 fd0

8 0 15728640 sda

8 1 1048576 sda1

8 2 14679040 sda2

8 16 2097152 sdb
8 17 512000 sdb1

11 0 4420608 sr0

253 0 13103104 dm-0

253 1 1572864 dm-1

[root@classs ~]# partprobe /dev/sdb

[root@classs ~]# cat /proc/partitions

major minor #blocks name

2 0 4 fd0

8 0 15728640 sda

8 1 1048576 sda1

8 2 14679040 sda2

8 16 2097152 sdb

8 17 512000 sdb1

8 18 307200 sdb2

8 19 102400 sdb3

11 0 4420608 sr0

253 0 13103104 dm-0

253 1 1572864 dm-1

[root@classs ~]# pvcreate /dev/sdb2 /dev/sdb3

WARNING: swap signature detected on /dev/sdb2 at offset 4086. Wipe it? [y/n]: y

Wiping swap signature on /dev/sdb2.

Physical volume "/dev/sdb2" successfully created.

Physical volume "/dev/sdb3" successfully created.

[root@classs ~]# pvs

PV VG Fmt Attr PSize PFree

/dev/sda2 rhel lvm2 a-- <14.00g 0

/dev/sdb2 lvm2 --- 300.00m 300.00m

/dev/sdb3 lvm2 --- 100.00m 100.00m


[root@classs ~]# pvdisplay

--- Physical volume ---

PV Name /dev/sda2

VG Name rhel

PV Size <14.00 GiB / not usable 3.00 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 3583

Free PE 0

Allocated PE 3583

PV UUID 2keweW-8eIN-xqXq-bz0y-t9f8-Xn2Q-Kc9UjQ

"/dev/sdb2" is a new physical volume of "300.00 MiB"

--- NEW Physical volume ---

PV Name /dev/sdb2

VG Name

PV Size 300.00 MiB

Allocatable NO

PE Size 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID WpZrFV-2t8W-FJT6-11tu-S9RT-8Bae-GQe8TB

"/dev/sdb3" is a new physical volume of "100.00 MiB"

--- NEW Physical volume ---

PV Name /dev/sdb3

VG Name

PV Size 100.00 MiB


Allocatable NO

PE Size 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID 0moIGd-psts-7ef1-KQVc-fY5q-9TRB-Drlmhq

[root@classs ~]# vgcreate vg0 /dev/sdb2 /dev/sdb3

Volume group "vg0" successfully created

[root@classs ~]# vgs

VG #PV #LV #SN Attr VSize VFree

rhel 1 2 0 wz--n- <14.00g 0

vg0 2 0 0 wz--n- 392.00m 392.00m

[root@classs ~]# vgdisplay vg0

--- Volume group ---

VG Name vg0

System ID

Format lvm2

Metadata Areas 2

Metadata Sequence No 1

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 0

Open LV 0

Max PV 0

Cur PV 2

Act PV 2

VG Size 392.00 MiB


PE Size 4.00 MiB

Total PE 98

Alloc PE / Size 0/0

Free PE / Size 98 / 392.00 MiB

VG UUID wKowh2-wgPN-iaeJ-sSQU-KRNT-fd2T-oliU3J

[root@classs ~]#

[root@classs ~]# lvcreate -L 120M -n lv_sapdata1 vg0

Logical volume "lv_sapdata1" created.

[root@classs ~]# lvcreate -l 25 -n lv_sapdata2 vg0

Logical volume "lv_sapdata2" created.

[root@classs ~]# lvs

LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert

root rhel -wi-ao---- <12.50g

swap rhel -wi-ao---- 1.50g

lv_sapdata1 vg0 -wi-a----- 120.00m

lv_sapdata2 vg0 -wi-a----- 100.00m

[root@classs ~]# mkfs.ext4 /dev/vg0/lv_sapdata1

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

30720 inodes, 122880 blocks

6144 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=33685504


15 block groups

8192 blocks per group, 8192 fragments per group

2048 inodes per group

Superblock backups stored on blocks:

8193, 24577, 40961, 57345, 73729

Allocating group tables: done

Writing inode tables: done

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

[root@classs ~]# mkfs.ext4 /dev/vg0/lv_sapdata2

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

25688 inodes, 102400 blocks

5120 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=33685504

13 block groups

8192 blocks per group, 8192 fragments per group

1976 inodes per group

Superblock backups stored on blocks:

8193, 24577, 40961, 57345, 73729

Allocating group tables: done


Writing inode tables: done

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

[root@classs ~]# vi /etc/fstab

/dev/vg0/lv_sapdata1 /sapdata1 ext4 defaults 00

/dev/vg0/lv_sapdata2 /sapdata2 ext4 defaults 00

[root@classs ~]# mount -a

mount: mount point /sapdata1 does not exist

mount: mount point /sapdata2 does not exist

[root@classs ~]# mkfir /sapdata1

bash: mkfir: command not found...

[root@classs ~]# mkdir /sapdata1 /sapdata2

[root@classs ~]# mount /dev/vg0/lv_sapdata1 /sapdata1

[root@classs ~]# mount /dev/vg0/lv_sapdata2 /sapdata2

[root@classs ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 901M 0 901M 0% /dev

tmpfs tmpfs 917M 0 917M 0% /dev/shm

tmpfs tmpfs 917M 51M 866M 6% /run

tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup

/dev/mapper/rhel-root xfs 13G 4.2G 8.4G 34% /

/dev/sda1 xfs 1014M 184M 831M 19% /boot

tmpfs tmpfs 184M 28K 184M 1% /run/user/1000

/dev/sr0 iso9660 4.3G 4.3G 0 100% /run/media/student/RHEL-7.9 Server.x86_64

tmpfs tmpfs 184M 28K 184M 1% /run/user/42

/dev/sdb1 xfs 497M 26M 472M 6% /mnt/new

tmpfs tmpfs 184M 0 184M 0% /run/user/0


/dev/mapper/vg0-lv_sapdata1 ext4 113M 1.6M 103M 2% /sapdata1

/dev/mapper/vg0-lv_sapdata2 ext4 93M 1.6M 85M 2% /sapdata2

[root@classs ~]# cp -rf /etc /sapdata2/

[root@classs ~]# cp -rf /etc /sapdata2/etc.old

[root@classs ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 901M 0 901M 0% /dev

tmpfs tmpfs 917M 0 917M 0% /dev/shm

tmpfs tmpfs 917M 51M 866M 6% /run

tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup

/dev/mapper/rhel-root xfs 13G 4.2G 8.4G 34% /

/dev/sda1 xfs 1014M 184M 831M 19% /boot

tmpfs tmpfs 184M 28K 184M 1% /run/user/1000

/dev/sr0 iso9660 4.3G 4.3G 0 100% /run/media/student/RHEL-7.9 Server.x86_64

tmpfs tmpfs 184M 28K 184M 1% /run/user/42

/dev/sdb1 xfs 497M 26M 472M 6% /mnt/new

tmpfs tmpfs 184M 0 184M 0% /run/user/0

/dev/mapper/vg0-lv_sapdata1 ext4 113M 1.6M 103M 2% /sapdata1

/dev/mapper/vg0-lv_sapdata2 ext4 93M 88M 0 100% /sapdata2

[root@classs ~]# cp -rf /bin /sapdata2

[root@classs ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 901M 0 901M 0% /dev

tmpfs tmpfs 917M 0 917M 0% /dev/shm

tmpfs tmpfs 917M 51M 866M 6% /run

tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup

/dev/mapper/rhel-root xfs 13G 4.2G 8.4G 34% /

/dev/sda1 xfs 1014M 184M 831M 19% /boot

tmpfs tmpfs 184M 28K 184M 1% /run/user/1000


/dev/sr0 iso9660 4.3G 4.3G 0 100% /run/media/student/RHEL-7.9 Server.x86_64

tmpfs tmpfs 184M 28K 184M 1% /run/user/42

/dev/sdb1 xfs 497M 26M 472M 6% /mnt/new

tmpfs tmpfs 184M 0 184M 0% /run/user/0

/dev/mapper/vg0-lv_sapdata1 ext4 113M 1.6M 103M 2% /sapdata1

/dev/mapper/vg0-lv_sapdata2 ext4 93M 88M 0 100% /sapdata2

[root@classs ~]# ls /sapdata2

[root@classs ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 901M 0 901M 0% /dev

tmpfs tmpfs 917M 0 917M 0% /dev/shm

tmpfs tmpfs 917M 51M 866M 6% /run

tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup

/dev/mapper/rhel-root xfs 13G 4.2G 8.4G 34% /

/dev/sda1 xfs 1014M 184M 831M 19% /boot

tmpfs tmpfs 184M 28K 184M 1% /run/user/1000

/dev/sr0 iso9660 4.3G 4.3G 0 100% /run/media/student/RHEL-7.9 Server.x86_64

tmpfs tmpfs 184M 28K 184M 1% /run/user/42

/dev/sdb1 xfs 497M 26M 472M 6% /mnt/new

tmpfs tmpfs 184M 0 184M 0% /run/user/0

/dev/mapper/vg0-lv_sapdata1 ext4 113M 1.6M 103M 2% /sapdata1

/dev/mapper/vg0-lv_sapdata2 ext4 93M 91M 0 100% /sapdata2

Extending the LVM


In order to extend the lvm we need to have sufficient free disk space on volume group (VG)
[root@classs ~]# vgdisplay vg0

--- Volume group ---

VG Name vg0

System ID

Format lvm2

Metadata Areas 2

Metadata Sequence No 3

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 2

Open LV 2

Max PV 0

Cur PV 2

Act PV 2

VG Size 392.00 MiB

PE Size 4.00 MiB

Total PE 98

Alloc PE / Size 55 / 220.00 MiB

Free PE / Size 43 / 172.00 MiB

VG UUID wKowh2-wgPN-iaeJ-sSQU-KRNT-fd2T-oliU3J

[root@classs ~]# lvextend -L +50M /dev/vg0/lv_sapdata2

Rounding size to boundary between physical extents: 52.00 MiB.

Size of logical volume vg0/lv_sapdata2 changed from 100.00 MiB (25 extents) to 152.00 MiB (38
extents).

Logical volume vg0/lv_sapdata2 successfully resized.

[root@classs ~]# lvs

LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- <12.50g

swap rhel -wi-ao---- 1.50g

lv_sapdata1 vg0 -wi-ao---- 120.00m

lv_sapdata2 vg0 -wi-ao---- 152.00m

[root@classs ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 901M 0 901M 0% /dev

tmpfs tmpfs 917M 0 917M 0% /dev/shm

tmpfs tmpfs 917M 51M 866M 6% /run

tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup

/dev/mapper/rhel-root xfs 13G 4.2G 8.4G 34% /

/dev/sda1 xfs 1014M 184M 831M 19% /boot

tmpfs tmpfs 184M 28K 184M 1% /run/user/1000

/dev/sr0 iso9660 4.3G 4.3G 0 100% /run/media/student/RHEL-7.9 Server.x86_64

tmpfs tmpfs 184M 28K 184M 1% /run/user/42

/dev/sdb1 xfs 497M 26M 472M 6% /mnt/new

tmpfs tmpfs 184M 0 184M 0% /run/user/0

/dev/mapper/vg0-lv_sapdata1 ext4 113M 1.6M 103M 2% /sapdata1

/dev/mapper/vg0-lv_sapdata2 ext4 93M 91M 0 100% /sapdata2

[root@classs ~]# resize2fs /dev/vg0/lv_sapdata2

resize2fs 1.42.9 (28-Dec-2013)

Filesystem at /dev/vg0/lv_sapdata2 is mounted on /sapdata2; on-line resizing required

old_desc_blocks = 1, new_desc_blocks = 2

The filesystem on /dev/vg0/lv_sapdata2 is now 155648 blocks long.

[root@classs ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 901M 0 901M 0% /dev

tmpfs tmpfs 917M 0 917M 0% /dev/shm


tmpfs tmpfs 917M 51M 866M 6% /run

tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup

/dev/mapper/rhel-root xfs 13G 4.2G 8.4G 34% /

/dev/sda1 xfs 1014M 184M 831M 19% /boot

tmpfs tmpfs 184M 28K 184M 1% /run/user/1000

/dev/sr0 iso9660 4.3G 4.3G 0 100% /run/media/student/RHEL-7.9 Server.x86_64

tmpfs tmpfs 184M 28K 184M 1% /run/user/42

/dev/sdb1 xfs 497M 26M 472M 6% /mnt/new

tmpfs tmpfs 184M 0 184M 0% /run/user/0

/dev/mapper/vg0-lv_sapdata1 ext4 113M 1.6M 103M 2% /sapdata1

/dev/mapper/vg0-lv_sapdata2 ext4 144M 91M 44M 68% /sapdata2

[root@classs ~]# cp -rf /etc /sapdata2/etc.old1

[root@classs ~]#

Extending Volume Group.


We are extending the VG to create new lv with size of 500Mb for /oracle.

[root@classs ~]# fdisk /dev/sdb

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/sdb: 2147 MB, 2147483648 bytes, 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 label type: dos

Disk identifier: 0xd968a89a

Device Boot Start End Blocks Id System

/dev/sdb1 2048 1026047 512000 83 Linux

/dev/sdb2 1026048 1640447 307200 8e Linux LVM

/dev/sdb3 1640448 1845247 102400 8e Linux LVM

Command (m for help): n

Partition type:

p primary (3 primary, 0 extended, 1 free)

e extended

Select (default e): e

Selected partition 4

First sector (1845248-4194303, default 1845248):

Using default value 1845248

Last sector, +sectors or +size{K,M,G} (1845248-4194303, default 4194303):

Using default value 4194303

Partition 4 of type Extended and of size 1.1 GiB is set

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 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 label type: dos

Disk identifier: 0xd968a89a

Device Boot Start End Blocks Id System

/dev/sdb1 2048 1026047 512000 83 Linux

/dev/sdb2 1026048 1640447 307200 8e Linux LVM

/dev/sdb3 1640448 1845247 102400 8e Linux LVM

/dev/sdb4 1845248 4194303 1174528 5 Extended

Command (m for help): n

All primary partitions are in use

Adding logical partition 5

First sector (1847296-4194303, default 1847296):

Using default value 1847296

Last sector, +sectors or +size{K,M,G} (1847296-4194303, default 4194303): +400M

Partition 5 of type Linux and of size 400 MiB is set

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 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 label type: dos

Disk identifier: 0xd968a89a

Device Boot Start End Blocks Id System

/dev/sdb1 2048 1026047 512000 83 Linux


/dev/sdb2 1026048 1640447 307200 8e Linux LVM

/dev/sdb3 1640448 1845247 102400 8e Linux LVM

/dev/sdb4 1845248 4194303 1174528 5 Extended

/dev/sdb5 1847296 2666495 409600 83 Linux

Command (m for help): t

Partition number (1-5, default 5): 5

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[root@classs ~]# partprobe /dev/sdb

[root@classs ~]# cat /proc/partitions

major minor #blocks name

2 0 4 fd0

8 0 15728640 sda

8 1 1048576 sda1

8 2 14679040 sda2

8 16 2097152 sdb

8 17 512000 sdb1
8 18 307200 sdb2

8 19 102400 sdb3

8 20 0 sdb4

8 21 409600 sdb5

11 0 4420608 sr0

253 0 13103104 dm-0

253 1 1572864 dm-1

253 2 122880 dm-2

253 3 155648 dm-3

[root@classs ~]# pvcreate /dev/sdb5

Physical volume "/dev/sdb5" successfully created.

[root@classs ~]# pvs

PV VG Fmt Attr PSize PFree

/dev/sda2 rhel lvm2 a-- <14.00g 0

/dev/sdb2 vg0 lvm2 a-- 296.00m 24.00m

/dev/sdb3 vg0 lvm2 a-- 96.00m 96.00m

/dev/sdb5 lvm2 --- 400.00m 400.00m

[root@classs ~]# vgs

VG #PV #LV #SN Attr VSize VFree

rhel 1 2 0 wz--n- <14.00g 0

vg0 2 2 0 wz--n- 392.00m 120.00m

[root@classs ~]# vgextend vg0 /dev/sdb5

Volume group "vg0" successfully extended

[root@classs ~]# vgs

VG #PV #LV #SN Attr VSize VFree

rhel 1 2 0 wz--n- <14.00g 0

vg0 3 2 0 wz--n- 788.00m 516.00m

[root@classs ~]# lvcreate -L +400M -n lv_oracle vg0

Logical volume "lv_oracle" created.


[root@classs ~]# mkfs.xfs /dev/vg0/lv_oracle

meta-data=/dev/vg0/lv_oracle isize=512 agcount=4, agsize=25600 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0, sparse=0

data = bsize=4096 blocks=102400, imaxpct=25

= sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1

log =internal log bsize=4096 blocks=855, version=2

= sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

[root@classs ~]# vi /etc/fstab

[root@classs ~]# mount /dev/vg0/lv_oracle /oracle

mount: mount point /oracle does not exist

[root@classs ~]# mkdir /oracle

[root@classs ~]# mount /dev/vg0/lv_oracle /oracle

[root@classs ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 901M 0 901M 0% /dev

tmpfs tmpfs 917M 0 917M 0% /dev/shm

tmpfs tmpfs 917M 52M 866M 6% /run

tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup

/dev/mapper/rhel-root xfs 13G 4.2G 8.4G 34% /

/dev/sda1 xfs 1014M 184M 831M 19% /boot

tmpfs tmpfs 184M 28K 184M 1% /run/user/1000

/dev/sr0 iso9660 4.3G 4.3G 0 100% /run/media/student/RHEL-7.9 Server.x86_64

tmpfs tmpfs 184M 28K 184M 1% /run/user/42

/dev/sdb1 xfs 497M 26M 472M 6% /mnt/new

tmpfs tmpfs 184M 0 184M 0% /run/user/0

/dev/mapper/vg0-lv_sapdata1 ext4 113M 1.6M 103M 2% /sapdata1


/dev/mapper/vg0-lv_sapdata2 ext4 144M 91M 44M 68% /sapdata2

/dev/mapper/vg0-lv_oracle xfs 397M 21M 377M 6% /oracle

[root@classs ~]#

========================Removing /oracle lvm and recovering the deleted lv==============

Recovering/restore removed lvm t

[root@classs ~]# umount /dev/vg0/lv_sapdata2

[root@classs ~]# lvremove /dev/vg0/lv_sapdata2

Do you really want to remove active logical volume vg0/lv_sapdata2? [y/n]: y

Logical volume "lv_sapdata2" successfully removed

[root@classs ~]# lvs

LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert

root rhel -wi-ao---- <12.50g

swap rhel -wi-ao---- 1.50g

lv_oracle vg0 -wi-ao---- 400.00m

lv_sapdata1 vg0 -wi-ao---- 120.00m

[root@classs ~]# cd /etc/lvm/archive/

[root@classs archive]# ls

rhel_00000-1614243862.vg vg0_00002-996361470.vg vg0_00005-760988034.vg

vg0_00000-240737263.vg vg0_00003-134041404.vg vg0_00006-1542080545.vg

vg0_00001-743391900.vg vg0_00004-1130380576.vg

[root@classs archive]# ls -ltr

total 32

-rw-------. 1 root root 1733 Jul 27 05:25 rhel_00000-1614243862.vg

-rw-------. 1 root root 1125 Aug 10 22:29 vg0_00000-240737263.vg

-rw-------. 1 root root 1128 Aug 10 22:31 vg0_00001-743391900.vg

-rw-------. 1 root root 1562 Aug 10 22:31 vg0_00002-996361470.vg


-rw-------. 1 root root 1981 Aug 10 22:37 vg0_00003-134041404.vg

-rw-------. 1 root root 1966 Aug 10 23:00 vg0_00004-1130380576.vg

-rw-------. 1 root root 2208 Aug 10 23:01 vg0_00005-760988034.vg

-rw-------. 1 root root 2781 Aug 10 23:05 vg0_00006-1542080545.vg

[root@classs archive]# date

Tue Aug 10 23:07:17 EDT 2021

[root@classs archive]# vgcfgrestore vg0 --test -f /etc/lvm/archive/vg0_00006-1542080545.vg

TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.

Volume group vg0 has active volume: lv_sapdata1.

Volume group vg0 has active volume: lv_oracle.

WARNING: Found 2 active volume(s) in volume group "vg0".

Restoring VG with active LVs, may cause mismatch with its metadata.

Do you really want to proceed with restore of volume group "vg0", while 2 volume(s) are active? [y/n]: y

Restored volume group vg0

[root@classs archive]# lvs

[root@classs archive]# lvs

[root@classs archive]# vgcfgrestore vg0 -f /etc/lvm/archive/vg0_00006-1542080545.vg

Volume group vg0 has active volume: lv_sapdata1.

Volume group vg0 has active volume: lv_oracle.

WARNING: Found 2 active volume(s) in volume group "vg0".

Restoring VG with active LVs, may cause mismatch with its metadata.

Do you really want to proceed with restore of volume group "vg0", while 2 volume(s) are active? [y/n]: y

Restored volume group vg0

Scan of VG vg0 from /dev/sdb2 found mda_checksum f4f38aa6 mda_size 2084 vs previous 77e382bf
1779

Scan of VG vg0 from /dev/sdb3 found mda_checksum f4f38aa6 mda_size 2084 vs previous 77e382bf
1779

Scan of VG vg0 from /dev/sdb5 found mda_checksum f4f38aa6 mda_size 2084 vs previous 77e382bf
1779

[root@classs archive]# lvscan


ACTIVE '/dev/rhel/swap' [1.50 GiB] inherit

ACTIVE '/dev/rhel/root' [<12.50 GiB] inherit

ACTIVE '/dev/vg0/lv_sapdata1' [120.00 MiB] inherit

inactive '/dev/vg0/lv_sapdata2' [152.00 MiB] inherit

ACTIVE '/dev/vg0/lv_oracle' [400.00 MiB] inherit

[root@classs archive]# lvchange -a y /dev/vg0/lv_sapdata2

[root@classs archive]# lvs

LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert

root rhel -wi-ao---- <12.50g

swap rhel -wi-ao---- 1.50g

lv_oracle vg0 -wi-ao---- 400.00m

lv_sapdata1 vg0 -wi-ao---- 120.00m

lv_sapdata2 vg0 -wi-a----- 152.00m

[root@classs archive]# mount -a

[root@classs archive]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 901M 0 901M 0% /dev

tmpfs tmpfs 917M 0 917M 0% /dev/shm

tmpfs tmpfs 917M 52M 866M 6% /run

tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup

/dev/mapper/rhel-root xfs 13G 4.2G 8.4G 34% /

/dev/sda1 xfs 1014M 184M 831M 19% /boot

tmpfs tmpfs 184M 28K 184M 1% /run/user/1000

/dev/sr0 iso9660 4.3G 4.3G 0 100% /run/media/student/RHEL-7.9 Server.x86_64

tmpfs tmpfs 184M 28K 184M 1% /run/user/42

/dev/sdb1 xfs 497M 26M 472M 6% /mnt/new

tmpfs tmpfs 184M 0 184M 0% /run/user/0

/dev/mapper/vg0-lv_sapdata1 ext4 113M 1.6M 103M 2% /sapdata1

/dev/mapper/vg0-lv_oracle xfs 397M 21M 377M 6% /oracle


/dev/mapper/vg0-lv_sapdata2 ext4 144M 91M 43M 69% /sapdata2

[root@classs archive]# ls /sapdata2

bin etc etc.old etc.old1 lost+found

[root@classs archive]#

====================Reducing the LVM of ext4============

In order to reduce LV we need to umount lv .

1. Umount the lv
2. Run e2fsck –f <lvname>
3. Run resize2fs lvname <original size after reducing the lvm>
4. Mount the lv

[root@station1 ~]# df -hT


Filesystem Type Size Used Avail Use% Mounted on

/dev/mapper/vgopt-lvopt ext4 186M 88M 86M 51% /opt


[root@station1 ~]#
[root@station1 ~]# du -hs /opt
93M /opt
[root@station1 ~]#

[root@station1 ~]# umount /opt


[root@station1 ~]# e2fsck -f /dev/vgopt/lvopt
e2fsck 1.42.9 (28-Dec-2013)
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/vgopt/lvopt: 7484/51200 files (0.4% non-contiguous), 99692/200704 blocks
[root@station1 ~]# resize2fs /dev/vgopt/lvopt 130M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vgopt/lvopt to 133120 (1k) blocks.
The filesystem on /dev/vgopt/lvopt is now 133120 blocks long.

[root@station1 ~]# lvreduce -L -50M /dev/vgopt/lvopt


Rounding size to boundary between physical extents: 48.00 MiB.
WARNING: Reducing active logical volume to 148.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vgopt/lvopt? [y/n]: y
Size of logical volume vgopt/lvopt changed from 196.00 MiB (49 extents) to 148.00 MiB (37
extents).
Logical volume vgopt/lvopt successfully resized.
[root@station1 ~]# lvdisplay /dev/vgopt/lvopt
--- Logical volume ---
LV Path /dev/vgopt/lvopt
LV Name lvopt
VG Name vgopt
LV UUID an7dp1-0svU-KmxW-zXhj-LfZa-5KjH-dA4z1T
LV Write Access read/write
LV Creation host, time station1.facebook.com, 2021-09-18 09:31:51 -0400
LV Status available
# open 0
LV Size 148.00 MiB
Current LE 37
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3

[root@station1 ~]# mount /opt


[root@station1 ~]# ls /opt
123.txt etc etc.old file1.txt lost+found rh
[root@station1 ~]# du -hs /opt
93M /opt
[root@station1 ~]#

LAB:

1. identify the device

lsblk

2. partion the device fdisk <device name>

change the partition id from 83 to 82

partprobe or karpartx or partx -a--> to update the partions information into kernel
memory.
3. enable the swap singinature on created swap partition. mkswap <partion name>

4 activate the swap partion

swapon -a <partion name>

swapon -s

5 . make entry in /etc/fstab to mount it paramanent mount.

Reducing the LVM i.e formated with XFS.

Step 0. Lab Preparation:

– Create a primary lvm partition using fdisk with 2 Gib size:

# fdisk /dev/sdb

# partprobe

– Create a physical volume:

# pvcreate /dev/sdb1 # create a physical volume

– Create a volume group with an extent size of 16M:

# vgcreate -s 16M vg00 /dev/sdb1

– Create logical volume with size of 800M (50 extents)

# lvcreate -L 800M -n lv00 vg00

– Convert the logical volume to xfs file system

# mkfs.xfs /dev/vg00/lv00

– Mount the partition to a directory

# mkdir /test

# mount /dev/vg00/pv00 /test

– Create some file in the directory

# dd if=/dev/zero of=/test/file01 bs=1024k count=10


# dd if=/dev/zero of=/test/file02 bs=1024k count=10

# dd if=/dev/zero of=/test/file03 bs=1024k count=10

– Install the xfsdump package

# yum install xfsdump -y

Step 1. Backup The Data

# xfsdump -f /tmp/test.dump /test

Step 2. Unmount The Partition

# umount /test

Step 3. Reduce The Partition Size

# lvreduce -L 400M /dev/vg00/lv00

Step 4. Format The Partition With XFS Filesystem

# mkfs.xfs -f /dev/vg00/lv00

Step 5. Remount the Parition

# mount /dev/vg00/lv00 /test

Step 6. Restore The Data

# xfsrestore -f /tmp/test.dump /test

– check the content of partition

# ls -l /test

Removing LV.
1. Umount the lv # umount <lv> or lvmount point
2. Remove the # lvremove lvname
3. Remove entry from /etc/fstab
4. Remove the vg # vgremove <vgname>
5. Remove the pv # pvremove pvnames…
6. Delete the partitions from the disk. # fdisk </dev/sdx>
[root@classs ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 901M 0 901M 0% /dev

tmpfs tmpfs 917M 0 917M 0% /dev/shm

tmpfs tmpfs 917M 18M 899M 2% /run

tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup

/dev/mapper/rhel-root xfs 13G 4.3G 8.3G 34% /

/dev/mapper/vg0-lv_sapdata2 ext4 144M 91M 43M 69% /sapdata2

/dev/sda1 xfs 1014M 184M 831M 19% /boot

tmpfs tmpfs 184M 12K 184M 1% /run/user/42

tmpfs tmpfs 184M 0 184M 0% /run/user/0

/dev/mapper/vg0-lv_sapdata1 ext4 81M 45M 30M 61% /sapdata1

/dev/sr0 iso9660 4.3G 4.3G 0 100% /mnt

/dev/mapper/vg0-lv_oracle xfs 349M 80M 270M 23% /oracle

[root@classs ~]# pvs

PV VG Fmt Attr PSize PFree

/dev/sda2 rhel lvm2 a-- <14.00g 0

/dev/sdb2 vg0 lvm2 a-- 296.00m 44.00m

/dev/sdb3 vg0 lvm2 a-- 96.00m 96.00m

/dev/sdb5 vg0 lvm2 a-- 396.00m 44.00m

[root@classs ~]# umount /oracle

[root@classs ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 901M 0 901M 0% /dev

tmpfs tmpfs 917M 0 917M 0% /dev/shm

tmpfs tmpfs 917M 18M 899M 2% /run

tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup

/dev/mapper/rhel-root xfs 13G 4.3G 8.3G 34% /


/dev/mapper/vg0-lv_sapdata2 ext4 144M 91M 43M 69% /sapdata2

/dev/sda1 xfs 1014M 184M 831M 19% /boot

tmpfs tmpfs 184M 12K 184M 1% /run/user/42

tmpfs tmpfs 184M 0 184M 0% /run/user/0

/dev/mapper/vg0-lv_sapdata1 ext4 81M 45M 30M 61% /sapdata1

/dev/sr0 iso9660 4.3G 4.3G 0 100% /mnt

[root@classs ~]# lvs

LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert

root rhel -wi-ao---- <12.50g

swap rhel -wi-ao---- 1.50g

lv_oracle vg0 -wi-a----- 352.00m

lv_sapdata1 vg0 -wi-ao---- 100.00m

lv_sapdata2 vg0 -wi-ao---- 152.00m

[root@classs ~]# lvremove /dev/vg0/lv_oracle

Do you really want to remove active logical volume vg0/lv_oracle? [y/n]: y

Logical volume "lv_oracle" successfully removed

[root@classs ~]# lvs

LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert

root rhel -wi-ao---- <12.50g

swap rhel -wi-ao---- 1.50g

lv_sapdata1 vg0 -wi-ao---- 100.00m

lv_sapdata2 vg0 -wi-ao---- 152.00m

[root@classs ~]#

You might also like