Adding Hard disk to Red Hat Enterprise Linux using LVM

note: the actual installation are performed from VMware Red Hat Enterprise 7.0

Scenario: 

I have created another 100 GB virtual disk and i want to add this to my linux installation.
the 100 GB are to be used used for /images partition. 

The installation are likely the same accross other version Red Hat Enterprise version and likely to differ in some commands which i will try my best to share

Lets us begin…

[root@eSuareznotes01 ~]# 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 0xd5f31fd6.

Command (m for help): m # for HELP information to display
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 # To create a new partition

Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p # To make it a primary partition

Partition number (1-4, default 1): 1 # To make the first partition
First sector (2048-209715199, default 2048): #default
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): #default
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): t # To make it a linux LVM type partition
Selected partition 1
Hex code (type L to list all codes): L # to list the Hex codes

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 ❤ 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): 8e # To select Linux LVM
Changed type of partition ‘Linux’ to ‘Linux LVM’

Command (m for help): w # To write the partition table
The partition table has been altered!

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

[root@eSuareznotes01 ~]# ls -l /dev/sdb1
brw-rw—-. 1 root disk 8, 17 Jul 13 10:20 /dev/sdb1

[root@eSuareznotes01 ~]# pvcreate /dev/sdb1 # Create Physical volume
Physical volume “/dev/sdb1” successfully created
[root@eSuareznotes01 ~]# vgcreate datavg01 /dev/sdb1 # Create Volume group
Volume group “datavg01” successfully created
[root@eSuareznotes01 ~]# pvdisplay # display the physical volume information
— Physical volume —
PV Name /dev/sda2
VG Name rootvg
PV Size 25.01 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 6401
Free PE 1
Allocated PE 6400
PV UUID 150o7e-DP2W-afYR-bAXM-RgBJ-S9UO-Ql91Wd

— Physical volume —
PV Name /dev/sdb1
VG Name datavg01
PV Size 100.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25599
Free PE 25599
Allocated PE 0
PV UUID tKjaH4-3STt-tttO-2Aqe-25Vb-vIfu-VssId8

 
when extending the disk space it is very important that you run this command this give you the "Free PE's"
to get the the available PE that you can use to extend Free PE x PE size (PE size sometime comes with KB or MB output)

[root@eSuareznotes01 ~]# lvcreate -n imagelv -L 50G /dev/datavg01
Logical volume “imagelv” created

To create logical volume then named as imagelv with 50GB size under /dev/datavg volume group
note: I only 50 GB here instead of 100 GB which i can use the other half on different things 

[root@eSuareznotes01 ~]# mkfs.xfs /dev/datavg01/imagelv # here is where you format the logical volume using XFS
meta-data=/dev/datavg01/imagelv isize=256 agcount=4, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

on this mkfs.X where X is the type of partition so on this section it will be likely different based on what partition your Red Hat system use for example if you use ext3 see the example below:

[root@nightops ~]# mkfs.ext3 /dev/datavg01/imageslv
nightops ~ -> mkfs.ext3 /dev/datavg01/imageslv
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1048576 inodes, 2097152 blocks
104857 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

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

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@eSuareznotes01 ~]# fdisk -l # list information

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000a490d

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 309247 153600 83 Linux
/dev/sda2 309248 52754431 26222592 8e Linux LVM

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0xd5f31fd6

Device Boot Start End Blocks Id System
/dev/sdb1 2048 209715199 104856576 8e Linux LVM

Disk /dev/mapper/rootvg-usrlv: 4294 MB, 4294967296 bytes, 8388608 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 /dev/mapper/rootvg-swaplv: 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 /dev/mapper/rootvg-rootlv: 1073 MB, 1073741824 bytes, 2097152 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 /dev/mapper/rootvg-homelv: 4294 MB, 4294967296 bytes, 8388608 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 /dev/mapper/rootvg-loglv: 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 /dev/mapper/rootvg-optlv: 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 /dev/mapper/rootvg-locallv: 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 /dev/mapper/rootvg-varlv: 4294 MB, 4294967296 bytes, 8388608 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 /dev/mapper/rootvg-tmplv: 4294 MB, 4294967296 bytes, 8388608 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 /dev/mapper/datavg01-imagelv: 53.7 GB, 53687091200 bytes, 104857600 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

[root@eSuareznotes01 ~]# vi /etc/fstab # add the entry to your fstab to make the filesystem always available
#
# /etc/fstab
# Created by anaconda on Thu Jul 10 18:13:58 2014
#
# 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/rootvg-rootlv / xfs defaults 1 1
UUID=ce3544c5-a456-4473-af44-a569a8dec4fd /boot xfs defaults 1 2
/dev/mapper/rootvg-homelv /home xfs defaults 1 2
/dev/mapper/rootvg-optlv /opt xfs defaults 1 2
/dev/mapper/rootvg-tmplv /tmp xfs defaults 1 2
/dev/mapper/rootvg-usrlv /usr xfs defaults 1 2
/dev/mapper/rootvg-locallv /usr/local xfs defaults 1 2
/dev/mapper/rootvg-varlv /var xfs defaults 1 2
/dev/mapper/rootvg-loglv /var/log xfs defaults 1 2
/dev/mapper/datavg01-imagelv /images xfs defaults 1 2
/dev/mapper/rootvg-swaplv swap swap defaults 0 0 xfs defaults 1 2

[root@eSuareznotes01 ~]# mkdir /images # Create where the partition will be mounted
[root@eSuareznotes01 ~]# mount -a # refresh mount based on fstab configurations
[root@eSuareznotes01 ~]# df -h # List disk information
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv 1014M 52M 963M 6% /
devtmpfs 236M 0 236M 0% /dev
tmpfs 242M 0 242M 0% /dev/shm
tmpfs 242M 4.6M 237M 2% /run
tmpfs 242M 0 242M 0% /sys/fs/cgroup
/dev/mapper/rootvg-usrlv 4.0G 767M 3.3G 19% /usr
/dev/mapper/rootvg-homelv 4.0G 33M 4.0G 1% /home
/dev/mapper/rootvg-optlv 2.0G 33M 2.0G 2% /opt
/dev/mapper/rootvg-locallv 2.0G 33M 2.0G 2% /usr/local
/dev/mapper/rootvg-tmplv 4.0G 33M 4.0G 1% /tmp
/dev/mapper/rootvg-varlv 4.0G 57M 4.0G 2% /var
/dev/mapper/rootvg-loglv 2.0G 35M 2.0G 2% /var/log
/dev/sda1 147M 68M 80M 46% /boot
/dev/mapper/datavg01-imagelv 50G 33M 50G 1% /images

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s