UNDERSTANDING LINUX PARTITIONING / STORAGE VIRTUALIZATION
------------------------------------------------------------------------------------------------
We will be given raw disks ( SATA HDD's or LUN or Storage volume's in cloud ).
When attached to the server they are called PARTITIONS.
We have to format the Raw disk partition to a Linux LVM Partition using fdisk command.
Then, we create a Physical volume using pvcreate. We will also know how to remove it. pvcreate -v command will also be used below.
We will then create Volume Group. A volume group can accommodate one or more Physical volumes. We will also display what it contains.
Using lvcreate we can create logical volume of the desired size. using lvextend we can also extend the logical volume assigned.
A volume group is like a Bucket. Physical volume is like Water. Logical volume is like a tumbler or bucket.
We will then make a file system (ext3) out of the logical volume created.
Then, mount the file system to a directory that doesnt have any contents.
Add the directory to /etc/fstab to ensure the file system is available permanently.
[root@oeldbapex ~]# clear
[root@oeldbapex ~]# fdisk -l | grep GB
Disk /dev/sda: 64.4 GB, 64424509440 bytes
Disk /dev/sdb: 80.5 GB, 80530636800 bytes
[root@oeldbapex ~]# fdisk -l /dev/sdb/
[root@oeldbapex ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 80.5 GB, 80530636800 bytes
255 heads, 63 sectors/track, 9790 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@oeldbapex ~]# fdisk /dev/sdb/
fdisk: cannot open /dev/sdb/: Not a directory
[root@oeldbapex ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xb6f70bac.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
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
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
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-9790, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-9790, default 9790):
Using default value 9790
Command (m for help): l
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1
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
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): p
Disk /dev/sdb: 80.5 GB, 80530636800 bytes
255 heads, 63 sectors/track, 9790 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb6f70bac
Device Boot Start End Blocks Id System
/dev/sdb1 1 9790 78638143+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@oeldbapex ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 7.8G 0 part [SWAP]
└─sda3 8:3 0 51.2G 0 part /
sdb 8:16 0 75G 0 disk
└─sdb1 8:17 0 75G 0 part
sr0 11:0 1 1024M 0 rom
[root@oeldbapex ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root@oeldbapex ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 ---- 75.00g 75.00g
[root@oeldbapex ~]# pvdisplay
"/dev/sdb1" is a new physical volume of "75.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 75.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID GphTIS-PITl-vNja-acW7-6TZ1-OZlM-LVQzd0
[root@oeldbapex ~]# pvremove /dev/sdb1
Labels on physical volume "/dev/sdb1" successfully wiped
[root@oeldbapex ~]# fdisk -l | grep GB
Disk /dev/sda: 64.4 GB, 64424509440 bytes
Disk /dev/sdb: 80.5 GB, 80530636800 bytes
[root@oeldbapex ~]# fdisk -l /dev/sdb1
Disk /dev/sdb1: 80.5 GB, 80525458944 bytes
255 heads, 63 sectors/track, 9789 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@oeldbapex ~]# pvcreate -v /dev/sdb1
Wiping cache of LVM-capable devices
Set up physical volume for "/dev/sdb1" with 157276287 available sectors
Zeroing start of device /dev/sdb1
Writing physical volume data to disk "/dev/sdb1"
Physical volume "/dev/sdb1" successfully created
[root@oeldbapex ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 ---- 75.00g 75.00g
[root@oeldbapex ~]# pvdisplay
"/dev/sdb1" is a new physical volume of "75.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 75.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID kvtys4-YuN1-lvyZ-KABA-VfHw-E31T-tDehWX
[root@oeldbapex ~]# vgcreate vg0 /dev/sdb1
Volume group "vg0" successfully created
[root@oeldbapex ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 1 0 0 wz--n- 74.99g 74.99g
[root@oeldbapex ~]# vgdisplay
--- Volume group ---
VG Name vg0
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 74.99 GiB
PE Size 4.00 MiB
Total PE 19198
Alloc PE / Size 0 / 0
Free PE / Size 19198 / 74.99 GiB
VG UUID FBcjKM-aGKd-jqQS-W9pS-vZSZ-ZtNi-1rjxI9
[root@oeldbapex ~]# lvcreate -L 50G -n lvoL0 vg0
Logical volume "lvoL0" created.
[root@oeldbapex ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lvoL0 vg0 -wi-a----- 50.00g
[root@oeldbapex ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg0/lvoL0
LV Name lvoL0
VG Name vg0
LV UUID ucQRNm-jeAe-1Id2-mMJa-1w2q-6Som-XfGFhR
LV Write Access read/write
LV Creation host, time oeldbapex.localdomain, 2019-11-23 19:12:05 +0530
LV Status available
# open 0
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 251:0
[root@oeldbapex ~]# mkfs -t ext3 /dev/vg0/lvoL0
mke2fs 1.43-WIP (20-Jun-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3276800 inodes, 13107200 blocks
655360 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done
[root@oeldbapex ~]#
[root@oeldbapex ~]# cd /u
u01/ usr/
[root@oeldbapex ~]# mkdir /u02
[root@oeldbapex ~]# mount -t /dev/vg0/lvoL0 /u02
Usage: mount -V : print version
mount -h : print this help
mount : list mounted filesystems
mount -l : idem, including volume labels
So far the informational part. Next the mounting.
The command is `mount [-t fstype] something somewhere'.
Details found in /etc/fstab may be omitted.
mount -a [-t|-O] ... : mount all stuff from /etc/fstab
mount device : mount device at the known place
mount directory : mount known device here
mount -t type dev dir : ordinary mount command
Note that one does not really mount a device, one mounts
a filesystem (of the given type) found on the device.
One can also mount an already visible directory tree elsewhere:
mount --bind olddir newdir
or move a subtree:
mount --move olddir newdir
One can change the type of mount containing the directory dir:
mount --make-shared dir
mount --make-slave dir
mount --make-private dir
mount --make-unbindable dir
One can change the type of all the mounts in a mount subtree
containing the directory dir:
mount --make-rshared dir
mount --make-rslave dir
mount --make-rprivate dir
mount --make-runbindable dir
A device can be given by name, say /dev/hda1 or /dev/cdrom,
or by label, using -L label or by uuid, using -U uuid .
Other options: [-nfFrsvw] [-o options] [-p passwdfd].
For many more details, say man 8 mount .
[root@oeldbapex ~]# mount /dev/vg0/lvoL0 /u02
[root@oeldbapex ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 51G 44G 4.5G 91% /
tmpfs 1.9G 76K 1.9G 1% /dev/shm
/dev/sda1 976M 83M 827M 10% /boot
/dev/mapper/vg0-lvoL0
50G 52M 47G 1% /u02
[root@oeldbapex ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name vg0
PV Size 75.00 GiB / not usable 3.06 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 19198
Free PE 6398
Allocated PE 12800
PV UUID kvtys4-YuN1-lvyZ-KABA-VfHw-E31T-tDehWX
[root@oeldbapex ~]# vgdisplay
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 74.99 GiB
PE Size 4.00 MiB
Total PE 19198
Alloc PE / Size 12800 / 50.00 GiB
Free PE / Size 6398 / 24.99 GiB
VG UUID FBcjKM-aGKd-jqQS-W9pS-vZSZ-ZtNi-1rjxI9
[root@oeldbapex ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg0/lvoL0
LV Name lvoL0
VG Name vg0
LV UUID ucQRNm-jeAe-1Id2-mMJa-1w2q-6Som-XfGFhR
LV Write Access read/write
LV Creation host, time oeldbapex.localdomain, 2019-11-23 19:12:05 +0530
LV Status available
# open 1
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 251:0
[root@oeldbapex ~]# lvextend -l +100%FREE /dev/vg0/lvoL0
Size of logical volume vg0/lvoL0 changed from 50.00 GiB (12800 extents) to 74.99 GiB (19198 extents).
Logical volume lvoL0 successfully resized.
[root@oeldbapex ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg0/lvoL0
LV Name lvoL0
VG Name vg0
LV UUID ucQRNm-jeAe-1Id2-mMJa-1w2q-6Som-XfGFhR
LV Write Access read/write
LV Creation host, time oeldbapex.localdomain, 2019-11-23 19:12:05 +0530
LV Status available
# open 1
LV Size 74.99 GiB
Current LE 19198
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 251:0
[root@oeldbapex ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 51G 44G 4.5G 91% /
tmpfs 1.9G 76K 1.9G 1% /dev/shm
/dev/sda1 976M 83M 827M 10% /boot
/dev/mapper/vg0-lvoL0
50G 52M 47G 1% /u02
[root@oeldbapex ~]# resize2fs /dev/vg0/lvoL0
resize2fs 1.43-WIP (20-Jun-2013)
Filesystem at /dev/vg0/lvoL0 is mounted on /u02; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 5
Performing an on-line resize of /dev/vg0/lvoL0 to 19658752 (4k) blocks.
The filesystem on /dev/vg0/lvoL0 is now 19658752 blocks long.
[root@oeldbapex ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 51G 44G 4.5G 91% /
tmpfs 1.9G 76K 1.9G 1% /dev/shm
/dev/sda1 976M 83M 827M 10% /boot
/dev/mapper/vg0-lvoL0
74G 52M 70G 1% /u02
[root@oeldbapex ~]# blk
blkdeactivate blkdiscard blkid blkiomon blkparse blkrawverify blktrace
[root@oeldbapex ~]# blk
blkdeactivate blkdiscard blkid blkiomon blkparse blkrawverify blktrace
[root@oeldbapex ~]# blkid
/dev/sda1: UUID="df22e960-84f2-43aa-8fe3-94256c7cde65" TYPE="ext4"
/dev/sda2: UUID="9d39cd25-89d7-4641-b232-430caf4df419" TYPE="swap"
/dev/sda3: UUID="bf40672a-9da6-4783-8064-36a8acb03def" TYPE="ext4"
/dev/sdb1: UUID="kvtys4-YuN1-lvyZ-KABA-VfHw-E31T-tDehWX" TYPE="LVM2_member"
/dev/mapper/vg0-lvoL0: UUID="8629600b-470e-4248-a297-99f71ebd933b" TYPE="ext3"
[root@oeldbapex ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Nov 14 13:13:43 2019
#
# 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
#
UUID=bf40672a-9da6-4783-8064-36a8acb03def / ext4 defaults 1 1
UUID=df22e960-84f2-43aa-8fe3-94256c7cde65 /boot ext4 defaults 1 2
UUID=9d39cd25-89d7-4641-b232-430caf4df419 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@oeldbapex ~]# vi /etc/fstab
[root@oeldbapex ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 51G 44G 4.5G 91% /
tmpfs 1.9G 76K 1.9G 1% /dev/shm
/dev/sda1 976M 83M 827M 10% /boot
/dev/mapper/vg0-lvoL0
74G 52M 70G 1% /u02
[root@oeldbapex ~]# mount -a
mount: /dev/sdb1 already mounted or /u02 busy
mount: according to mtab, /dev/mapper/vg0-lvoL0 is already mounted on /u02
[root@oeldbapex ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 51G 44G 4.5G 91% /
tmpfs 1.9G 76K 1.9G 1% /dev/shm
/dev/sda1 976M 83M 827M 10% /boot
/dev/mapper/vg0-lvoL0
74G 52M 70G 1% /u02
[root@oeldbapex ~]#
You can watch the video in this link https://youtu.be/raWk8kzdmW0