Experience LINUX LVM (Logical Volume Manager) with real time examples
1.) What LVM is?
2.) Terminology
3.) Creation of Physical Vol, Volume Group, Logical Volume, Filesystem creation, Mount and making the FS entry in /etc/fstab
4.) Add new disk under existing Volume Group
5.) Filesystem extension in Linux
6.) Filesystem shrinking in Linux
7.) Removing disk from existing Volume Group
8.) Special Note
1.) What LVM is?
LVM stands for Logical Volume Manger, Its a way of presenting Harddrivers/Storage to Operating System in a well defined, user understandale, logical way.
OR
LVM is a method of allocating hard drive space into logical volumes that can be easily resized instead of partitions.
OR
With LVM, the hard drive or set of hard drives is allocated to one or more physical volumes.
2.) Terminology:
a.) Harddrive/Storage Luns —> The physical media where are read and writes occured.
b.) Physical Volume —> The actual harddrive or a partition of harddrive can be assigned to Physical Volume. Its the smallest building unit in Linux LVM.
c.) Volume group —> The combination of Physical Volume is used to make a Volumegroup. You can think Volumegroup as a Pool of harddrives/partiotions.
d.) Logical Volume —> We can create Logical Volume on any Volumegroup which indeed are created on Physical Volume which indeed are on Physical disks.
e.) Mountpoint —> The Filesystem is created on Logical Volume and is mounted on mountpoint which is only a simple directory to make the Filesystem open to world for read write operations.
In simple:
PHYSICAL MEDIA ——->
PHYSICALVOLUME——>
VOLUMEGROUP ———>
LOGICALVOLUME ——>
MOUNTPOINT—>
ALL READY FOR YOU.:-)
Hard-disk, LUN Harddisk or partition Logical-storage-pool Base for Filesystem creation
3.) Creation of Physical Vol, Volume Group, Logical Volume, Filesystem creation, Mount and making the FS entry in /etc/fstab
In our previous post “Basis Filesystem Management in Linux” we have already covered the base of Linux FS so here we will concentrate more on LVM part. Before
proceeding I would like to make all Linux Beginners familiar with Partition Types, In Linux after making partition we have to choose the Partition Type according to the Filesystem we are going to create and use.
Linux-specific partitions would normally be one of the following types:
• 5 (or f) — Extended
• 82 — Linux swap
• 83 — Linux
• 8e — Linux LVM
• fd — Linux RAID auto
Commands used:
pvcreate
pvdisplay
vgcreate
vgdisplay
lvcreate -L or -l (by default is 4MB in Linux) -n
lvdisplay /dev/vgname/logicalvol-name
In example I am using 2 harddrive /dev/sdb & /dev/sdc for presenting LVM in Linux. I will use /dev/sdb to create PV, VG & LV and latter point of time I will add /dev/sdc in the existing VG and then we will perform online Filesystem resizing (extension and shrinking).
You can use complete disk or a portion of disk, I am taking complete disk in the example under primary partition 1.
yogesh-Linux#fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1305 10377990 8e Linux LVM
Disk /dev/sdb: 2147 MB, 2147483648 bytes ————————–> First Drive
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn’t contain a valid partition table
Disk /dev/sdc: 2147 MB, 2147483648 bytes ————————–> second Drive
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdc doesn’t contain a valid partition table
yogesh-Linux#
yogesh-Linux#cat /proc/partitions
major minor #blocks name
8 0 10485760 sda
8 1 104391 sda1
8 2 10377990 sda2
8 16 2097152 sdb
8 32 2097152 sdc
253 0 9306112 dm-0
253 1 1048576 dm-1
yogesh-Linux#
yogesh-Linux#fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. 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 0×0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261):
Using default value 261
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 ————————> To change partition 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: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 83 Linux ————> Here the ID is 83 for simple Linux FS.
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): L
0 Empty 1e Hidden W95 FAT1 80 Old Minix bf Solaris
1 FAT12 24 NEC DOS 81 Minix / old Lin c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 82 Linux swap / So c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 83 Linux c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c7 Syrinx
5 Extended 41 PPC PReP Boot 85 Linux extended da Non-FS data
6 FAT16 42 SFS 86 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set de Dell Utility
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext df BootIt
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT
f W95 Ext’d (LBA) 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f4 SpeedStor
14 Hidden FAT16 we have changed it to 8e as per Linux Kernel Architecture
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 8e Linux LVM ———–> 8e for Linux LVM
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): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
yogesh-Linux#
yogesh-Linux#
yogesh-Linux#cat /proc/partitions
major minor #blocks name
8 0 10485760 sda
8 1 104391 sda1
8 2 10377990 sda2
8 16 2097152 sdb
8 17 2096451 sdb1
8 32 2097152 sdc
253 0 9306112 dm-0
253 1 1048576 dm-1
yogesh-Linux#partprobe /dev/sdb1
yogesh-Linux#
yogesh-Linux#fdisk /dev/sdc ——————————> Similar process for 2nd disk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel.
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 0×0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261):
Using default value 261
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): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdc: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 261 2096451 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
yogesh-Linux#
yogesh-Linux#cat /proc/partitions
major minor #blocks name
8 0 10485760 sda
8 1 104391 sda1
8 2 10377990 sda2
8 16 2097152 sdb
8 17 2096451 sdb1
8 32 2097152 sdc
8 33 2096451 sdc1
253 0 9306112 dm-0
253 1 1048576 dm-1
yogesh-Linux#partprobe /dev/sdc1
yogesh-Linux#
yogesh-Linux#pvcreate /dev/sdb1 —————————–> Physical Volume Creation
Physical volume “/dev/sdb1? successfully created
yogesh-Linux#
yogesh-Linux#vgcreate gurkulgroup /dev/sdb1 ——————–> Volume group creation
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
Attempt to close device ‘/dev/cdrom’ which is not open.
Volume group “gurkulgroup” successfully created
yogesh-Linux#
yogesh-Linux#
yogesh-Linux#pvdisplay /dev/sdb1
— Physical volume —
PV Name /dev/sdb1
VG Name gurkulgroup
PV Size 2.00 GB / not usable 3.32 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 511
Free PE 511
Allocated PE 0
PV UUID 90ikep-gxVd-oLkf-1YGO-s0dl-JkqQ-zTqY7a
yogesh-Linux#vgdisplay gurkulgroup
— Volume group —
VG Name gurkulgroup
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 2.00 GB
PE Size 4.00 MB ——————-> This PE is the physical extents (Physical Volumes are defined with Phyisical Extents of a fixed size)
Total PE 511
Alloc PE / Size 0 / 0
Free PE / Size 511 / 2.00 GB
VG UUID OBnNzV-RWvO-Gvy0-L1rb-Brh1-IiIH-33Mpnc
yogesh-Linux#lvcreate -L 1.5g -n gurkulvolume gurkulgroup —————-> Logical Volume Creation
Logical volume “gurkulvolume” created
yogesh-Linux#
yogesh-Linux#lvdisplay /dev/gurkulgroup/gurkulvolume
— Logical volume —
LV Name /dev/gurkulgroup/gurkulvolume
VG Name gurkulgroup
LV UUID BAS7wh-VZDt-l9rg-mdcf-srQr-yEY2-q9dTsK
LV Write Access read/write
LV Status available
# open 0
LV Size 1.50 GB
Current LE 384
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:2
yogesh-Linux#mkfs -t ext3 /dev/gurkulgroup/gurkulvolume ——————–> Filesystem creation
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
196608 inodes, 393216 blocks
19660 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=402653184
12 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
yogesh-Linux#
yogesh-Linux#mkdir /gurkultest —————————————> Mountpoint
yogesh-Linux#
yogesh-Linux#mount /dev/gurkulgroup/gurkulvolume /gurkultest ———–> FS mounted
yogesh-Linux#
yogesh-Linux#df -h /gurkultest
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
1.5G 35M 1.4G 3% /gurkultest
yogesh-Linux# vi /etc/fstab
yogesh-Linux#more /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
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
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
LINUX1:/yogesh /nfstest nfs defaults 0 0
#/dev/sdc1 /yogesh-primary-test ext3 defaults 0 0
#/dev/sdc5 /yogesh-extended-test ext3 defaults 0 0
#/dev/raidgroup/raidvol /test-raid ext3 defaults 0 0
/dev/gurkulgroup/gurkulvolume /gurkultest ext3 defaults 0 0 ————-> entry in fstab, to make FS persistent across reboots
yogesh-Linux#
Test on the Permanent existence of Mountpoint created:
yogesh-Linux#umount /gurkultest
yogesh-Linux#
yogesh-Linux#mount -a
mount: mount to NFS server ‘LINUX1' failed: System Error: No route to host.
yogesh-Linux#
yogesh-Linux#df -h /gurkultest
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
1.5G 35M 1.4G 3% /gurkultest
yogesh-Linux#
4.) Add new disk under existing Volume Group:
Here in this section we will add one new disk under our existing volumegroup. This is the practical situation where some SA’s needs to extend and shrink Filesystems on regular basis, before proceeding with the Online resizing SA needs to take the disk under OS control and then assign it to existing VG. The process is same as we mentioned above but some commands will be changed as now we are expanding already existed VG.
yogesh-Linux#df -h /gurkultest
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
1.5G 35M 1.4G 3% /gurkultest
yogesh-Linux#vgdisplay gurkulgroup
— Volume group —
VG Name gurkulgroup
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 2.00 GB ——————————> VG size is 2GB i.e the size of /dev/sdb disk
PE Size 4.00 MB
Total PE 511
Alloc PE / Size 384 / 1.50 GB
Free PE / Size 127 / 508.00 MB
VG UUID OBnNzV-RWvO-Gvy0-L1rb-Brh1-IiIH-33Mpnc
yogesh-Linux#fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1305 10377990 8e Linux LVM
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 8e Linux LVM
Disk /dev/sdc: 2147 MB, 2147483648 bytes ————————————————> extra disk to add under VG
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 261 2096451 8e Linux LVM
yogesh-Linux#
yogesh-Linux#pvcreate /dev/sdc1 ———————————–> Physical volume create for /dev/sdc
Physical volume “/dev/sdc1? successfully created
yogesh-Linux#
yogesh-Linux#pvdisplay ——————-> I have my rootdisk under LVM so dont get confused with /dev/sda (its my rootdisk), just concentarte on /dev/sd{b,c}
— Physical volume —
PV Name /dev/sdb1
VG Name gurkulgroup
PV Size 2.00 GB / not usable 3.32 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 511
Free PE 127
Allocated PE 384
PV UUID 90ikep-gxVd-oLkf-1YGO-s0dl-JkqQ-zTqY7a
— Physical volume —
PV Name /dev/sda2
VG Name VolGroup00
PV Size 9.90 GB / not usable 22.76 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 316
Free PE 0
Allocated PE 316
PV UUID md04K8-UyPp-X8G8-KZ7F-Vvm0-jbev-x0SClg
“/dev/sdc1? is a new physical volume of “2.00 GB” ———————-> its not yet assigned to any VG
— NEW Physical volume —
PV Name /dev/sdc1
VG Name
PV Size 2.00 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID JN8wPA-8mAt-9P2E-DYM0-QLYR-uubc-HeeOqb
yogesh-Linux#
yogesh-Linux#vgextend gurkulgroup /dev/sdc1 ———————> Volumegroup has been added with one new PV.
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
Attempt to close device ‘/dev/cdrom’ which is not open.
Volume group “gurkulgroup” successfully extended
yogesh-Linux#
yogesh-Linux#vgdisplay gurkulgroup
— Volume group —
VG Name gurkulgroup
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 3.99 GB
PE Size 4.00 MB ——————————-> The size has been increasedto 4Gb as our disk are 2GB each.
Total PE 1022
Alloc PE / Size 384 / 1.50 GB
Free PE / Size 638 / 2.49 GB
VG UUID OBnNzV-RWvO-Gvy0-L1rb-Brh1-IiIH-33Mpnc
yogesh-Linux#
yogesh-Linux#df -h /gurkultest/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
1.5G 35M 1.4G 3% /gurkultest
yogesh-Linux#
5.) Filesystem extension in Linux (How to grow Filesystem Online in Linux i.e Online resizing)
The online resizing in Linux is very simple but needs to be perform with full caution.
At this point of time we have VG of 4GB with two PV’s and our Filesystem is of 1.5GB, we will increase it to 3GB and will check what the results will be. Kindly refer above outputs before proceeding.
Add new storage —-> Partition it —-> Create PV —-> Take PV under existing VG i.e extend VG —-> Extend Logical Volume —-> resize Filesystem —-> Allready with No Downtime.
yogesh-Linux#lvextend -L +1.5g /dev/gurkulgroup/gurkulvolume
Extending logical volume gurkulvolume to 3.00 GB
Logical volume gurkulvolume successfully resized
yogesh-Linux#
yogesh-Linux#df -h /gurkultest —————-> At this point of tme only Volume has been extended, we also need to resize the FS to reflect the results
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
1.5G 35M 1.4G 3% /gurkultest
yogesh-Linux#resize2fs /dev/gurkulgroup/gurkulvolume
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/gurkulgroup/gurkulvolume is mounted on /gurkultest; on-line resizing required
Performing an on-line resize of /dev/gurkulgroup/gurkulvolume to 786432 (4k) blocks.
The filesystem on /dev/gurkulgroup/gurkulvolume is now 786432 blocks long.
yogesh-Linux#df -h /gurkultest ———————————–> Our filesystem is increased to 3GB now
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
3.0G 35M 2.8G 2% /gurkultest
yogesh-Linux#
6.) Filesystem shrinking in Linux: (How to reduce Filesystem):
In any OS the Shrinking should be peformed with extracare. It you will try to reduce the Filesystem more than space which is free in the FS, dataloss will occur.
Suppose your FS is of 3GB and out of which 2.5GB is used, here if you will try to reduce the FS to 2GB the dataloss will occur.
So best plan before proceeding with any FS shrinking operations, recommended would be to take the Backup before going ahead.
Below I am taking some backups in /gurkultest FS to show that no dataloss will occur if will reduce the FS if space is not used. I will reduce the Filesystem to 1GB.
Unmount the FS —-> Run Fsck —-> resize FS —-> resize existing volume —-> MountFS —-> All Done (Filesystem wont be available during the operation) i.e downtime for the FS is required.
yogesh-Linux#cp -p /var/log/messages /gurkultest
yogesh-Linux#df -h /gurkultest/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
3.0G 35M 2.8G 2% /gurkultest
yogesh-Linux#
yogesh-Linux#resize2fs /dev/gurkulgroup/gurkulvolume 1g —————-> Reduction wont allowed unless and until you will umount the FS
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/gurkulgroup/gurkulvolume is mounted on /gurkultest; on-line resizing required
On-line shrinking from 786432 to 262144 not supported.
yogesh-Linux#
yogesh-Linux#umount /gurkultest
yogesh-Linux#
yogesh-Linux#resize2fs /dev/gurkulgroup/gurkulvolume 1g ————> We have to proceed with fsck to check any dada inconsistency for the FS
resize2fs 1.39 (29-May-2006)
Please run ‘e2fsck -f /dev/gurkulgroup/gurkulvolume’ first.
yogesh-Linux#
yogesh-Linux#e2fsck -f /dev/gurkulgroup/gurkulvolume
e2fsck 1.39 (29-May-2006)
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/gurkulgroup/gurkulvolume: 13/393216 files (7.7% non-contiguous), 21147/786432 blocks
yogesh-Linux#
yogesh-Linux#resize2fs /dev/gurkulgroup/gurkulvolume 1g
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/gurkulgroup/gurkulvolume to 262144 (4k) blocks.
The filesystem on /dev/gurkulgroup/gurkulvolume is now 262144 blocks long.
yogesh-Linux#
yogesh-Linux#lvreduce /dev/gurkulgroup/gurkulvolume -L 1g ——————> I am reducing Logical Vol to 1GB
WARNING: Reducing active logical volume to 1.00 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce gurkulvolume? [y/n]: y
Reducing logical volume gurkulvolume to 1.00 GB
Logical volume gurkulvolume successfully resized
yogesh-Linux#
yogesh-Linux#mount /dev/gurkulgroup/gurkulvolume /gurkultest/
yogesh-Linux#
yogesh-Linux#df -h /gurkultest/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
1008M 34M 933M 4% /gurkultest
yogesh-Linux#cd /gurkultest/
yogesh-Linux#ls
lost+found messages test
yogesh-Linux#ls -lrt —————————————-> No dataloss occured, messages file is preserved
total 104
drwx—— 2 root root 16384 Aug 17 19:22 lost+found
-rw——- 1 root root 74125 Aug 17 19:24 messages
-rw-r–r– 1 root root 0 Aug 17 19:37 test
yogesh-Linux#
7.) Removing disk from existing Volume Group:
Lets check the complete outputs before proceeding with the Disk removal from VG.
yogesh-Linux#pvdisplay
— Physical volume —
PV Name /dev/sdb1
VG Name gurkulgroup
PV Size 2.00 GB / not usable 3.32 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 511
Free PE 255
Allocated PE 256
PV UUID 90ikep-gxVd-oLkf-1YGO-s0dl-JkqQ-zTqY7a
— Physical volume —
PV Name /dev/sdc1
VG Name gurkulgroup
PV Size 2.00 GB / not usable 3.32 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 511
Free PE 511
Allocated PE 0
PV UUID JN8wPA-8mAt-9P2E-DYM0-QLYR-uubc-HeeOqb
— Physical volume —
PV Name /dev/sda2
VG Name VolGroup00
PV Size 9.90 GB / not usable 22.76 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 316
Free PE 0
Allocated PE 316
PV UUID md04K8-UyPp-X8G8-KZ7F-Vvm0-jbev-x0SClg
yogesh-Linux#vgdisplay
— Volume group —
VG Name gurkulgroup
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 3.99 GB
PE Size 4.00 MB
Total PE 1022
Alloc PE / Size 256 / 1.00 GB
Free PE / Size 766 / 2.99 GB
VG UUID OBnNzV-RWvO-Gvy0-L1rb-Brh1-IiIH-33Mpnc
— Volume group —
VG Name VolGroup00
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.88 GB
PE Size 32.00 MB
Total PE 316
Alloc PE / Size 316 / 9.88 GB
Free PE / Size 0 / 0
VG UUID 53YyKs-D2uQ-0gVY-My3w-6QOi-KDQ8-9dFUjF
yogesh-Linux#lvdisplay
— Logical volume —
LV Name /dev/gurkulgroup/gurkulvolume
VG Name gurkulgroup
LV UUID BAS7wh-VZDt-l9rg-mdcf-srQr-yEY2-q9dTsK
LV Write Access read/write
LV Status available
# open 1
LV Size 1.00 GB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:2
— Logical volume —
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID XE3qZL-Ke6Z-3zN7-z1aD-3eee-BY6E-qdVmLz
LV Write Access read/write
LV Status available
# open 1
LV Size 8.88 GB
Current LE 284
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:0
— Logical volume —
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID LT743f-Oy1u-Zq1Z-lKxM-czRy-hG9x-2H7RI3
LV Write Access read/write
LV Status available
# open 1
LV Size 1.00 GB
Current LE 32
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:1
yogesh-Linux#
yogesh-Linux#vgreduce gurkulgroup /dev/sdb1 ————> I tried to remove the disk having data, the LVM is so intelligent that it throw errors as
Physical volume “/dev/sdb1? still in use
yogesh-Linux#vgreduce gurkulgroup /dev/sdc1 —————–> disk removed from VG Removed “/dev/sdc1? from volume group “gurkulgroup”
yogesh-Linux#
yogesh-Linux#pvremove /dev/sdc1 ————————> disk removed from PV i.e complete LVM
/dev/cdrom: open failed: Read-only file system
Attempt to close device ‘/dev/cdrom’ which is not open.
Labels on physical volume “/dev/sdc1? successfully wiped
yogesh-Linux#
yogesh-Linux#pvdisplay /dev/sdc1
No physical volume label read from /dev/sdc1
Failed to read physical volume “/dev/sdc1?
yogesh-Linux#
yogesh-Linux#vgdisplay
— Volume group —
VG Name gurkulgroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
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 2.00 GB
PE Size 4.00 MB
Total PE 511
Alloc PE / Size 256 / 1.00 GB
Free PE / Size 255 / 1020.00 MB
VG UUID OBnNzV-RWvO-Gvy0-L1rb-Brh1-IiIH-33Mpnc
— Volume group —
VG Name VolGroup00
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.88 GB
PE Size 32.00 MB
Total PE 316
Alloc PE / Size 316 / 9.88 GB
Free PE / Size 0 / 0
VG UUID 53YyKs-D2uQ-0gVY-My3w-6QOi-KDQ8-9dFUjF
yogesh-Linux#pvdisplay
— Physical volume —
PV Name /dev/sdb1
VG Name gurkulgroup
PV Size 2.00 GB / not usable 3.32 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 511
Free PE 255
Allocated PE 256
PV UUID 90ikep-gxVd-oLkf-1YGO-s0dl-JkqQ-zTqY7a
— Physical volume —
PV Name /dev/sda2
VG Name VolGroup00
PV Size 9.90 GB / not usable 22.76 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 316
Free PE 0
Allocated PE 316
PV UUID md04K8-UyPp-X8G8-KZ7F-Vvm0-jbev-x0SClg
yogesh-Linux#lvdisplay
— Logical volume —
LV Name /dev/gurkulgroup/gurkulvolume
VG Name gurkulgroup
LV UUID BAS7wh-VZDt-l9rg-mdcf-srQr-yEY2-q9dTsK
LV Write Access read/write
LV Status available
# open 1
LV Size 1.00 GB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:2
— Logical volume —
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID XE3qZL-Ke6Z-3zN7-z1aD-3eee-BY6E-qdVmLz
LV Write Access read/write
LV Status available
# open 1
LV Size 8.88 GB
Current LE 284
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:0
— Logical volume —
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID LT743f-Oy1u-Zq1Z-lKxM-czRy-hG9x-2H7RI3
LV Write Access read/write
LV Status available
# open 1
LV Size 1.00 GB
Current LE 32
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:1
yogesh-Linux#
8.) Special Note:
a.) You can use -l with lvcreate if you wish to use extend instead of size.
b.) Extents size can be changed as per desire.
c.) The physical volumes are combined into logical volume groups, with the exception of the /boot/ partition. The /boot/ partition can not be on a logical volume group
because the boot loader can not read it. If the root / partition is on a logical volume, create a separate /boot/ partition which is not a part of a volume group.
d.) Untill here only LVM is covered so no data redundancy is there as any disk failure will case the dataloss if data is present in the failed disk. So better take backups.
We will come up with the Software RAID in Linux soon in our next post so that we can show you the data redundancy via mirroring in Linux.
No comments:
Post a Comment