Objective: Setup /tmp and swap using a lvg
Additional details: Part of this exercise, we have assigned a disk named 14Oct2022_Centos_79_tmpnswap01.vdi (after increasing the sata ports needed).
Refer to Url:
https://docs.oracle.com/cd/E18476_01/doc.220/e25258/GUID-0C1EF990-1EA7-426D-9208-083D07FF249D.htm
By default centos 7.x creates a pv & lvg for root fs and swap fs.
>>> List disks available:
[root@10 ~]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000b7b30
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM
Disk /dev/sdb: 4294 MB, 4294967296 bytes, 8388608 sectors <<<< new disk we alloacted for tmp and swap
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/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors <<<< new disk we allocated for pg* mountpoints.
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/centos-root: 8585 MB, 8585740288 bytes, 16769024 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/centos-swap: 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
>>> Let us now create a pv and lvgs needed for /tmp and swap fs.
>>> Partition the disk:
[root@10 ~]# 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 0x626472a8.
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-8388607, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607):
Using default value 8388607
Partition 1 of type Linux and of size 4 GiB is set
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): t
Selected partition 1
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): 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.
Syncing disks.
[root@10 ~]#
Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000b7b30
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM
Disk /dev/sdb: 4294 MB, 4294967296 bytes, 8388608 sectors <<<< new disk we alloacted for tmp and swap
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/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors <<<< new disk we allocated for pg* mountpoints.
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/centos-root: 8585 MB, 8585740288 bytes, 16769024 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/centos-swap: 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
>>> Let us now create a pv and lvgs needed for /tmp and swap fs.
>>> Partition the disk:
[root@10 ~]# 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 0x626472a8.
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-8388607, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607):
Using default value 8388607
Partition 1 of type Linux and of size 4 GiB is set
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): t
Selected partition 1
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): 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.
Syncing disks.
[root@10 ~]#
>>> List the partitions:
[root@10 ~]# fdisk -lDisk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000b7b30
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM
Disk /dev/sdb: 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 label type: dos
Disk identifier: 0x626472a8
Device Boot Start End Blocks Id System
/dev/sdb1 2048 8388607 4193280 8e Linux LVM
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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/centos-root: 8585 MB, 8585740288 bytes, 16769024 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/centos-swap: 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
[root@10 ~]#
>>> Report the PV available
[root@10 ~]# pvdisplay--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <9.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 2303
Free PE 0
Allocated PE 2303
PV UUID g4bogw-Jcoc-2zu7-RIqV-r1nQ-3jZ2-gL6sod
>>> Create new PV
[root@10 ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
[root@10 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <9.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 2303
Free PE 0
Allocated PE 2303
PV UUID g4bogw-Jcoc-2zu7-RIqV-r1nQ-3jZ2-gL6sod
"/dev/sdb1" is a new physical volume of "<4.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <4.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID mkrsFQ-FmN6-wWEb-vavK-7y1A-GwNv-rIph7K
[root@10 ~]#
>>> Create volume group for the new physical volume:
vgcreate ostmpswpvg /dev/sdb1[root@10 ~]# vgcreate ostmpswpvg /dev/sdb1
Volume group "ostmpswpvg" successfully created
[root@10 ~]#
>>> Display vgs available:
[root@10 ~]# vgdisplay--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size <9.00 GiB
PE Size 4.00 MiB
Total PE 2303
Alloc PE / Size 2303 / <9.00 GiB
Free PE / Size 0 / 0
VG UUID mjXQXu-MLRw-QpAj-sOcH-Xn8X-w4WX-xLl7a0
--- Volume group ---
VG Name ostmpswpvg
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size <4.00 GiB
PE Size 4.00 MiB
Total PE 1023
Alloc PE / Size 0 / 0
Free PE / Size 1023 / <4.00 GiB
VG UUID KfLEOe-luOc-XQw3-iJFC-zDWs-V8ST-nnZfew
[root@10 ~]#
>>> Activate the new vg:
vgchange -a y ostmpswpvg[root@10 ~]# vgchange -a y ostmpswpvg
0 logical volume(s) in volume group "ostmpswpvg" now active
[root@10 ~]#
>>> Create the new logical volume (lv):
lvcreate -l 4094 ostmpswpvg -n myVolGroup-LogVol00
But we use "L" to indicate the size.
lvcreate -L 2000 ostmpswpvg -n ostmpswpvg-tmp00
[root@10 ~]# lvcreate -L 2000 ostmpswpvg -n ostmpswpvg-tmp00
Logical volume "ostmpswpvg-tmp00" created.
lvcreate -L 2000 ostmpswpvg -n ostmpswpvg-swp00
[root@10 ~]# lvcreate -L 2000 ostmpswpvg -n ostmpswpvg-swp00
Logical volume "ostmpswpvg-swp00" created.
[root@10 ~]#
[root@10 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID R7ItvU-RZST-gGIh-PwJW-jukf-27Nl-c62eDf
LV Write Access read/write
LV Creation host, time localhost, 2022-10-14 11:18:28 +0530
LV Status available
# open 2
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID F7ESm7-w49Z-PhZS-ydAy-otg4-3PzY-hvAurG
LV Write Access read/write
LV Creation host, time localhost, 2022-10-14 11:18:30 +0530
LV Status available
# open 1
LV Size <8.00 GiB
Current LE 2047
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Logical volume ---
LV Path /dev/ostmpswpvg/ostmpswpvg-tmp00 <<< tmp vg
LV Name ostmpswpvg-tmp00
VG Name ostmpswpvg
LV UUID sqdk8r-dxfH-BR4l-5UvA-Nq4m-jv9q-kjKf22
LV Write Access read/write
LV Creation host, time 10.0.2.4, 2022-10-16 18:37:26 +0530
LV Status available
# open 0
LV Size 1.95 GiB <<< 2000m equals to 1.95GB
Current LE 500
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/ostmpswpvg/ostmpswpvg-swp00 <<< swap vg
LV Name ostmpswpvg-swp00
VG Name ostmpswpvg
LV UUID a2eAP1-Ie07-5EmQ-Rfkg-qDl1-SmSc-n6Lq9m
LV Write Access read/write
LV Creation host, time 10.0.2.4, 2022-10-16 18:38:06 +0530
LV Status available
# open 0
LV Size 1.95 GiB <<< 2000m equals to 1.95GB
Current LE 500
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3
[root@10 ~]#
>>> Format the lvgs with ext3 filesystem type:
mkfs.ext3 /dev/ostmpswpvg/ostmpswpvg-tmp00[root@10 ~]# mkfs.ext3 /dev/ostmpswpvg/ostmpswpvg-tmp00
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
128000 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=524288000
16 block groups
32768 blocks per group, 32768 fragments per group
8000 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[root@10 ~]#
mkfs.ext3 /dev/ostmpswpvg/ostmpswpvg-swp00
[root@10 ~]# mkfs.ext3 /dev/ostmpswpvg/ostmpswpvg-swp00
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
128000 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=524288000
16 block groups
32768 blocks per group, 32768 fragments per group
8000 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[root@10 ~]#
>>> Make an entry for /tmp in /etc/fstab...
/dev/ostmpswpvg/ostmpswpvg-tmp00 /tmp ext3 defaults,nodev,nosuid,noexec 1 2mount /tmp
/dev/mapper/ostmpswpvg-ostmpswpvg--tmp00 1.9G 3.0M 1.8G 1% /tmp
>>> Swap setup change from existing default setup to new lv we just created:
Current swap setting:[root@10 ~]# cat /proc/swaps
Filename Type Size Used Priority
/dev/dm-1 partition 1048572 0 -2
[root@10 ~]#
[root@10 ~]# free -k
total used free shared buff/cache available
Mem: 1014720 169104 198408 6900 647208 676316
Swap: 1048572 0 1048572 <<<< 1GB swap coming from root
[root@10 ~]# swapoff /dev/mapper/centos-swap
[root@10 ~]# free -k
total used free shared buff/cache available
Mem: 1014720 133764 774548 6880 106408 752856
Swap: 0 0 0 <<<< swap became 0 bytes
[root@10 ~]#
[root@10 ~]# mkswap /dev/ostmpswpvg/ostmpswpvg-swp00
mkswap: /dev/ostmpswpvg/ostmpswpvg-swp00: warning: wiping old ext3 signature.
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=48028613-bb1a-4445-8bc3-4f4541809fc4
[root@10 ~]#
[root@10 ~]# swapon /dev/ostmpswpvg/ostmpswpvg-swp00
[root@10 ~]# free -k
total used free shared buff/cache available
Mem: 1014720 135336 772864 6880 106520 751228
Swap: 2047996 0 2047996
[root@10 ~]#
/etc/fstab update:
#/dev/mapper/centos-swap swap swap defaults 0 0 <<<< old entry is commented
/dev/ostmpswpvg/ostmpswpvg-swp00 swap swap defaults 0 0 <<<< new entry is added
[root@10 ~]# free -k
total used free shared buff/cache available
Mem: 1014720 135320 772852 6880 106548 751228
Swap: 2047996 0 2047996 <<<< swap became 2GB now
[root@10 ~]#
/tmp and swap updates are done.
No comments:
Post a Comment