Steps involved in LVM creation.
Following are the steps involved in LVM creation from scratch.
LVM
Steps.
1. Create partition.
2. Format Partition
3. Create physical volume.
4. Create volume group.
5. Create logical volume.
6. Increase/ decrease partition size using lvextend/lvreduce.
7. Command 'resize2fs' to extend or reduce without losing data.
Help URL:
http://www.thegeekstuff.com/2010/08/how-to-create-lvm/
http://www.tldp.org/HOWTO/LVM-HOWTO/removevgs.html
http://www.tutorialspoint.com/unix_commands/resize2fs.htm
http://linux.die.net/man/8/resize2fs
http://www.aboutlinux.info/2005/04/resizing-logical-volumes.html
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/lv_overview.html
Steps in detail:-
1. Create partition.
2. Format Partition
Three Disks are available as listed below:
root@Microknoppix:~# fdisk -l | grep -w 'sdb1\|sdc1\|sdd1'
/dev/sdb1 2048 1194303 596128 83 Linux
/dev/sdc1 2048 1194303 596128 83 Linux
/dev/sdd1 2048 1194303 596128 83 Linux
root@Microknoppix:~#
To create partition and format, do the below steps.
# fdisk /dev/sdb
Command (m for help): d
Partition number (1-5):
Value out of range.
Partition number (1-5): 1
Command (m for help): p --> To list available partitions.
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
Partition number (1-4, default 1):
Using default value 1
First sector (2048-4194303, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): 1194303
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
88 heads, 13 sectors/track, 3666 cylinders, total 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 identifier: 0x4dbf12c7
Device Boot Start End Blocks Id System
/dev/sdb1 2048 1194303 596128 83 Linux
Command (m for help): w --> To save this to disk.
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
root@Microknoppix:~# partprobe --> By default, server will not detect added partitions until reboot. Execute this command for system to detect added partitions without reboot.
root@Microknoppix:~# mkfs -t ext4 /dev/sdb1 --> Mount filesystem to ext4
mke2fs 1.42.5 (29-Jul-2012)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
37280 inodes, 149032 blocks
7451 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=155189248
5 block groups
32768 blocks per group, 32768 fragments per group
7456 inodes per group
Superblock backups stored on blocks:
32768, 98304
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
root@Microknoppix:~#
3. Create physical volume.
Execute the following command to create this.
root@Microknoppix:~# pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1
Writing physical volume data to disk "/dev/sdb1"
Physical volume "/dev/sdb1" successfully created
Writing physical volume data to disk "/dev/sdc1"
Physical volume "/dev/sdc1" successfully created
Writing physical volume data to disk "/dev/sdd1"
Physical volume "/dev/sdd1" successfully created
root@Microknoppix:~#
4. Create volume group.
Execute the following to create a volume group.
root@Microknoppix:~# vgcreate vol_grp1 /dev/sdb1 /dev/sdc1 /dev/sdd1
Volume group "vol_grp1" successfully created
root@Microknoppix:~#
5. Create logical volume.
Execute the following to create a logical volume.
root@Microknoppix:~# lvcreate -l 125 -n logical_vol500_2 vol_grp1
Logical volume "logical_vol500_2" created
root@Microknoppix:~#
Created 3 logical volumes as below:-
root@Microknoppix:~# lvcreate -l 175 -n logical_vol700 vol_grp1
Logical volume "logical_vol700" created
root@Microknoppix:~#
root@Microknoppix:~# lvcreate -l 125 -n logical_vol500 vol_grp1
Logical volume "logical_vol500" created
root@Microknoppix:~#
root@Microknoppix:~# lvcreate -l 125 -n logical_vol500_2 vol_grp1
Logical volume "logical_vol500_2" created
root@Microknoppix:~#
Format created logical volumes using the command:-
#mkfs -t ext4 /dev/vol_grp1/logical_vol700
# mkfs -t ext4 /dev/vol_grp1/logical_vol500
# mkfs -t ext4 /dev/vol_grp1/logical_vol500_2
Now logical volumes are created.
Now, mount these to newly created domains using the following command:
root@Microknoppix:~# mount -t ext4 /dev/vol_grp1/logical_vol700 /lvm_700
root@Microknoppix:~# mount -t ext4 /dev/vol_grp1/logical_vol500 /lvm_500
root@Microknoppix:~# mount -t ext4 /dev/vol_grp1/logical_vol500_2 /lvm_500
Once done, 'df-h' shows as below:-
/dev/mapper/vol_grp1-logical_vol700 673M 712K 638M 1% /lvm_700
/dev/mapper/vol_grp1-logical_vol500 477M 2.3M 449M 1% /lvm_500
/dev/mapper/vol_grp1-logical_vol500_2 477M 2.3M 449M 1% /lvm_500_2
These mapper file are symlinks of original file as displayed below:-
brw-rw---T 1 root disk 252, 0 Aug 19 16:58 /dev/dm-0
brw-rw---T 1 root disk 252, 1 Aug 19 16:59 /dev/dm-1
brw-rw---T 1 root disk 252, 2 Aug 19 16:59 /dev/dm-2
6. Increase/ decrease partition size using lvextend/lvreduce.
a. Lvreduce.
root@Microknoppix:~# lvreduce --size 20M /dev/vol_grp1/logical_vol500
WARNING: Reducing active and open logical volume to 20.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce logical_vol500? [y/n]: y
Reducing logical volume logical_vol500 to 20.00 MiB
Logical volume logical_vol500 successfully resized
root@Microknoppix:~# lvscan
ACTIVE '/dev/vol_grp1/logical_vol500' [20.00 MiB] inherit
root@Microknoppix:~#
b. lvextend.
root@Microknoppix:~# lvextend --size +40M /dev/vol_grp1/logical_vol500
Extending logical volume logical_vol500 to 60.00 MiB
Logical volume logical_vol500 successfully resized
root@Microknoppix:~#
root@Microknoppix:~# lvscan
ACTIVE '/dev/vol_grp1/logical_vol500' [60.00 MiB] inherit
root@Microknoppix:~# df -h | grep logical
/dev/mapper/vol_grp1-logical_vol700 331M 320K 313M 1% /lvm_700
/dev/mapper/vol_grp1-logical_vol500_2 234M 2.1M 220M 1% /lvm_500_2
/dev/mapper/vol_grp1-logical_vol500 380M 264M 96M 74% /lvm_500
root@Microknoppix:~#
These changes will not reflect in mount point. To achive, umount the partition, format and remount. This is shown in below steps.
root@Microknoppix:~# umount /lvm_500
root@Microknoppix:~#
root@Microknoppix:~# mkfs -t ext4 /dev/vol_grp1/logical_vol500
mke2fs 1.42.5 (29-Jul-2012)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
15360 inodes, 61440 blocks
3072 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=62914560
8 block groups
8192 blocks per group, 8192 fragments per group
1920 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
root@Microknoppix:~# mount -t ext4 /dev/vol_grp1/logical_vol500 /lvm_500
root@Microknoppix:~# df -h | grep logical
/dev/mapper/vol_grp1-logical_vol700 331M 320K 313M 1% /lvm_700
/dev/mapper/vol_grp1-logical_vol500_2 234M 2.1M 220M 1% /lvm_500_2
/dev/mapper/vol_grp1-logical_vol500 55M 1.2M 50M 3% /lvm_500
root@Microknoppix:~#
7. Command 'resize2fs' to extend or reduce without losing data.
root@Microknoppix:/# umount /lvm_500_2
root@Microknoppix:/# resize2fs /dev/mapper/vol_grp1-logical_vol500_2 250M
resize2fs 1.42.5 (29-Jul-2012)
Please run 'e2fsck -f /dev/mapper/vol_grp1-logical_vol500_2' first.
root@Microknoppix:~# cd /lvm_500_2
root@Microknoppix:/lvm_500_2# ls
asd.txt lost+found
root@Microknoppix:/lvm_500_2# cat asd.txt
This is a test lvm file
root@Microknoppix:/lvm_500_2# cd
root@Microknoppix:~# umount /lvm_500_2
root@Microknoppix:~# e2fsck -f /dev/vol_grp1/logical_vol500_2
e2fsck 1.42.5 (29-Jul-2012)
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/vol_grp1/logical_vol500_2: 12/65024 files (0.0% non-contiguous), 18464/256000 blocks
root@Microknoppix:~# resize2fs /dev/vol_grp1/logical_vol500_2 310M
resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/vol_grp1/logical_vol500_2 to 317440 (1k) blocks.
The filesystem on /dev/vol_grp1/logical_vol500_2 is now 317440 blocks long.
root@Microknoppix:~# mount /dev/vol_grp1/logical_vol500_2 /lvm_500_2
root@Microknoppix:~# df -h | grep logical
/dev/mapper/vol_grp1-logical_vol700 331M 320K 313M 1% /lvm_700
/dev/mapper/vol_grp1-logical_vol500 55M 1.2M 50M 3% /lvm_500
/dev/mapper/vol_grp1-logical_vol500_2 293M 2.1M 275M 1% /lvm_500_2
root@Microknoppix:~# df -h | grep vol_grp1-logical_vol500_2
/dev/mapper/vol_grp1-logical_vol500_2 293M 2.1M 275M 1% /lvm_500_2
root@Microknoppix:~# cat /lvm_500_2/asd.txt
This is a test lvm file
root@Microknoppix:~#
root@Microknoppix:~# umount /lvm_500_2
root@Microknoppix:~# e2fsck -f /dev/vol_grp1/logical_vol500_2
e2fsck 1.42.5 (29-Jul-2012)
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/vol_grp1/logical_vol500_2: 12/79248 files (0.0% non-contiguous), 20256/317440 blocks
root@Microknoppix:~# resize2fs /dev/vol_grp1/logical_vol500_2 100M
resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/vol_grp1/logical_vol500_2 to 102400 (1k) blocks.
The filesystem on /dev/vol_grp1/logical_vol500_2 is now 102400 blocks long.
root@Microknoppix:~# mount /dev/vol_grp1/logical_vol500_2 /lvm_500_2
root@Microknoppix:~# df -h | grep vol_grp1-logical_vol500_2
/dev/mapper/vol_grp1-logical_vol500_2 89M 1.6M 83M 2% /lvm_500_2
root@Microknoppix:~# cat /lvm_500_2/asd.txt
This is a test lvm file
root@Microknoppix:~#
From the above command, you can verify that the file is not affected on resizing the file-system.
Note:-
To view the available physical volume list, execute the following command:
root@Microknoppix:~# pvscan
PV /dev/sdb1 VG vol_grp1 lvm2 [580.00 MiB / 80.00 MiB free]
PV /dev/sdc1 VG vol_grp1 lvm2 [580.00 MiB / 60.00 MiB free]
PV /dev/sdd1 VG vol_grp1 lvm2 [580.00 MiB / 0 free]
Total: 3 [1.70 GiB] / in use: 3 [1.70 GiB] / in no VG: 0 [0 ]
root@Microknoppix:~#
root@Microknoppix:~# pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name vol_grp1
PV Size 582.16 MiB / not usable 2.16 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 145
Free PE 20
Allocated PE 125
PV UUID if9z2Y-vpoR-7PyH-ReAL-0Hpz-hCky-o8IT2d
--- Physical volume ---
PV Name /dev/sdc1
VG Name vol_grp1
PV Size 582.16 MiB / not usable 2.16 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 145
Free PE 15
Allocated PE 130
PV UUID cX7Sc6-Xhy8-WE72-ET6e-RmhN-VFjG-ZHv24Q
--- Physical volume ---
PV Name /dev/sdd1
VG Name vol_grp1
PV Size 582.16 MiB / not usable 2.16 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 145
Free PE 0
Allocated PE 145
PV UUID EnRms2-s7ka-a9c0-CjVL-Shyz-QeJ0-UatOpY
root@Microknoppix:~#
2. Excute following command to get details of volume group created.
root@Microknoppix:~# vgdisplay
--- Volume group ---
VG Name vol_grp1
System ID
Format lvm2
Metadata Areas 3
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 3
Act PV 3
VG Size 1.70 GiB
PE Size 4.00 MiB
Total PE 435
Alloc PE / Size 0 / 0
Free PE / Size 435 / 1.70 GiB
VG UUID QSba44-K2uv-Hwws-iN73-0Ndq-IxW8-aFbcY0
root@Microknoppix:~#
3. Excute following command to get details of logical volume created.
root@Microknoppix:~# lvdisplay
--- Logical volume ---
LV Path /dev/vol_grp1/logical_vol700
LV Name logical_vol700
VG Name vol_grp1
LV UUID gJP2gk-a1Cm-XEN1-ZMM5-8lmr-QJQ6-tIXfwn
LV Write Access read/write
LV Creation host, time Microknoppix, 2015-08-19 16:55:16 +0000
LV Status available
# open 1
LV Size 500.00 MiB
Current LE 125
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
--- Logical volume ---
LV Path /dev/vol_grp1/logical_vol500
LV Name logical_vol500
VG Name vol_grp1
LV UUID xoOjH0-3HMN-nEo0-nDzH-R14h-k4cV-0Qs56O
LV Write Access read/write
LV Creation host, time Microknoppix, 2015-08-19 16:57:05 +0000
LV Status available
# open 1
LV Size 500.00 MiB
Current LE 125
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:1
--- Logical volume ---
LV Path /dev/vol_grp1/logical_vol500_2
LV Name logical_vol500_2
VG Name vol_grp1
LV UUID GqBroa-e2d2-SoWy-ZlU3-2doF-73EY-UWkyqZ
LV Write Access read/write
LV Creation host, time Microknoppix, 2015-08-19 16:58:12 +0000
LV Status available
# open 1
LV Size 600.00 MiB
Current LE 150
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:2
root@Microknoppix:~#
Help Url:
The physical volumes are divided into 4MB units, since that is the extent size. So a content of 100 extebd will have a size of 400M(4*100).
Following are the steps involved in LVM creation from scratch.
LVM
Steps.
1. Create partition.
2. Format Partition
3. Create physical volume.
4. Create volume group.
5. Create logical volume.
6. Increase/ decrease partition size using lvextend/lvreduce.
7. Command 'resize2fs' to extend or reduce without losing data.
Help URL:
http://www.thegeekstuff.com/2010/08/how-to-create-lvm/
http://www.tldp.org/HOWTO/LVM-HOWTO/removevgs.html
http://www.tutorialspoint.com/unix_commands/resize2fs.htm
http://linux.die.net/man/8/resize2fs
http://www.aboutlinux.info/2005/04/resizing-logical-volumes.html
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/lv_overview.html
Steps in detail:-
1. Create partition.
2. Format Partition
Three Disks are available as listed below:
root@Microknoppix:~# fdisk -l | grep -w 'sdb1\|sdc1\|sdd1'
/dev/sdb1 2048 1194303 596128 83 Linux
/dev/sdc1 2048 1194303 596128 83 Linux
/dev/sdd1 2048 1194303 596128 83 Linux
root@Microknoppix:~#
To create partition and format, do the below steps.
# fdisk /dev/sdb
Command (m for help): d
Partition number (1-5):
Value out of range.
Partition number (1-5): 1
Command (m for help): p --> To list available partitions.
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
Partition number (1-4, default 1):
Using default value 1
First sector (2048-4194303, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): 1194303
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
88 heads, 13 sectors/track, 3666 cylinders, total 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 identifier: 0x4dbf12c7
Device Boot Start End Blocks Id System
/dev/sdb1 2048 1194303 596128 83 Linux
Command (m for help): w --> To save this to disk.
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
root@Microknoppix:~# partprobe --> By default, server will not detect added partitions until reboot. Execute this command for system to detect added partitions without reboot.
root@Microknoppix:~# mkfs -t ext4 /dev/sdb1 --> Mount filesystem to ext4
mke2fs 1.42.5 (29-Jul-2012)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
37280 inodes, 149032 blocks
7451 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=155189248
5 block groups
32768 blocks per group, 32768 fragments per group
7456 inodes per group
Superblock backups stored on blocks:
32768, 98304
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
root@Microknoppix:~#
3. Create physical volume.
Execute the following command to create this.
root@Microknoppix:~# pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1
Writing physical volume data to disk "/dev/sdb1"
Physical volume "/dev/sdb1" successfully created
Writing physical volume data to disk "/dev/sdc1"
Physical volume "/dev/sdc1" successfully created
Writing physical volume data to disk "/dev/sdd1"
Physical volume "/dev/sdd1" successfully created
root@Microknoppix:~#
4. Create volume group.
Execute the following to create a volume group.
root@Microknoppix:~# vgcreate vol_grp1 /dev/sdb1 /dev/sdc1 /dev/sdd1
Volume group "vol_grp1" successfully created
root@Microknoppix:~#
5. Create logical volume.
Execute the following to create a logical volume.
root@Microknoppix:~# lvcreate -l 125 -n logical_vol500_2 vol_grp1
Logical volume "logical_vol500_2" created
root@Microknoppix:~#
Created 3 logical volumes as below:-
root@Microknoppix:~# lvcreate -l 175 -n logical_vol700 vol_grp1
Logical volume "logical_vol700" created
root@Microknoppix:~#
root@Microknoppix:~# lvcreate -l 125 -n logical_vol500 vol_grp1
Logical volume "logical_vol500" created
root@Microknoppix:~#
root@Microknoppix:~# lvcreate -l 125 -n logical_vol500_2 vol_grp1
Logical volume "logical_vol500_2" created
root@Microknoppix:~#
Format created logical volumes using the command:-
#mkfs -t ext4 /dev/vol_grp1/logical_vol700
# mkfs -t ext4 /dev/vol_grp1/logical_vol500
# mkfs -t ext4 /dev/vol_grp1/logical_vol500_2
Now logical volumes are created.
Now, mount these to newly created domains using the following command:
root@Microknoppix:~# mount -t ext4 /dev/vol_grp1/logical_vol700 /lvm_700
root@Microknoppix:~# mount -t ext4 /dev/vol_grp1/logical_vol500 /lvm_500
root@Microknoppix:~# mount -t ext4 /dev/vol_grp1/logical_vol500_2 /lvm_500
Once done, 'df-h' shows as below:-
/dev/mapper/vol_grp1-logical_vol700 673M 712K 638M 1% /lvm_700
/dev/mapper/vol_grp1-logical_vol500 477M 2.3M 449M 1% /lvm_500
/dev/mapper/vol_grp1-logical_vol500_2 477M 2.3M 449M 1% /lvm_500_2
These mapper file are symlinks of original file as displayed below:-
brw-rw---T 1 root disk 252, 0 Aug 19 16:58 /dev/dm-0
brw-rw---T 1 root disk 252, 1 Aug 19 16:59 /dev/dm-1
brw-rw---T 1 root disk 252, 2 Aug 19 16:59 /dev/dm-2
6. Increase/ decrease partition size using lvextend/lvreduce.
a. Lvreduce.
root@Microknoppix:~# lvreduce --size 20M /dev/vol_grp1/logical_vol500
WARNING: Reducing active and open logical volume to 20.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce logical_vol500? [y/n]: y
Reducing logical volume logical_vol500 to 20.00 MiB
Logical volume logical_vol500 successfully resized
root@Microknoppix:~# lvscan
ACTIVE '/dev/vol_grp1/logical_vol500' [20.00 MiB] inherit
root@Microknoppix:~#
b. lvextend.
root@Microknoppix:~# lvextend --size +40M /dev/vol_grp1/logical_vol500
Extending logical volume logical_vol500 to 60.00 MiB
Logical volume logical_vol500 successfully resized
root@Microknoppix:~#
root@Microknoppix:~# lvscan
ACTIVE '/dev/vol_grp1/logical_vol500' [60.00 MiB] inherit
root@Microknoppix:~# df -h | grep logical
/dev/mapper/vol_grp1-logical_vol700 331M 320K 313M 1% /lvm_700
/dev/mapper/vol_grp1-logical_vol500_2 234M 2.1M 220M 1% /lvm_500_2
/dev/mapper/vol_grp1-logical_vol500 380M 264M 96M 74% /lvm_500
root@Microknoppix:~#
These changes will not reflect in mount point. To achive, umount the partition, format and remount. This is shown in below steps.
root@Microknoppix:~# umount /lvm_500
root@Microknoppix:~#
root@Microknoppix:~# mkfs -t ext4 /dev/vol_grp1/logical_vol500
mke2fs 1.42.5 (29-Jul-2012)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
15360 inodes, 61440 blocks
3072 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=62914560
8 block groups
8192 blocks per group, 8192 fragments per group
1920 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
root@Microknoppix:~# mount -t ext4 /dev/vol_grp1/logical_vol500 /lvm_500
root@Microknoppix:~# df -h | grep logical
/dev/mapper/vol_grp1-logical_vol700 331M 320K 313M 1% /lvm_700
/dev/mapper/vol_grp1-logical_vol500_2 234M 2.1M 220M 1% /lvm_500_2
/dev/mapper/vol_grp1-logical_vol500 55M 1.2M 50M 3% /lvm_500
root@Microknoppix:~#
7. Command 'resize2fs' to extend or reduce without losing data.
root@Microknoppix:/# umount /lvm_500_2
root@Microknoppix:/# resize2fs /dev/mapper/vol_grp1-logical_vol500_2 250M
resize2fs 1.42.5 (29-Jul-2012)
Please run 'e2fsck -f /dev/mapper/vol_grp1-logical_vol500_2' first.
root@Microknoppix:~# cd /lvm_500_2
root@Microknoppix:/lvm_500_2# ls
asd.txt lost+found
root@Microknoppix:/lvm_500_2# cat asd.txt
This is a test lvm file
root@Microknoppix:/lvm_500_2# cd
root@Microknoppix:~# umount /lvm_500_2
root@Microknoppix:~# e2fsck -f /dev/vol_grp1/logical_vol500_2
e2fsck 1.42.5 (29-Jul-2012)
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/vol_grp1/logical_vol500_2: 12/65024 files (0.0% non-contiguous), 18464/256000 blocks
root@Microknoppix:~# resize2fs /dev/vol_grp1/logical_vol500_2 310M
resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/vol_grp1/logical_vol500_2 to 317440 (1k) blocks.
The filesystem on /dev/vol_grp1/logical_vol500_2 is now 317440 blocks long.
root@Microknoppix:~# mount /dev/vol_grp1/logical_vol500_2 /lvm_500_2
root@Microknoppix:~# df -h | grep logical
/dev/mapper/vol_grp1-logical_vol700 331M 320K 313M 1% /lvm_700
/dev/mapper/vol_grp1-logical_vol500 55M 1.2M 50M 3% /lvm_500
/dev/mapper/vol_grp1-logical_vol500_2 293M 2.1M 275M 1% /lvm_500_2
root@Microknoppix:~# df -h | grep vol_grp1-logical_vol500_2
/dev/mapper/vol_grp1-logical_vol500_2 293M 2.1M 275M 1% /lvm_500_2
root@Microknoppix:~# cat /lvm_500_2/asd.txt
This is a test lvm file
root@Microknoppix:~#
root@Microknoppix:~# umount /lvm_500_2
root@Microknoppix:~# e2fsck -f /dev/vol_grp1/logical_vol500_2
e2fsck 1.42.5 (29-Jul-2012)
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/vol_grp1/logical_vol500_2: 12/79248 files (0.0% non-contiguous), 20256/317440 blocks
root@Microknoppix:~# resize2fs /dev/vol_grp1/logical_vol500_2 100M
resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/vol_grp1/logical_vol500_2 to 102400 (1k) blocks.
The filesystem on /dev/vol_grp1/logical_vol500_2 is now 102400 blocks long.
root@Microknoppix:~# mount /dev/vol_grp1/logical_vol500_2 /lvm_500_2
root@Microknoppix:~# df -h | grep vol_grp1-logical_vol500_2
/dev/mapper/vol_grp1-logical_vol500_2 89M 1.6M 83M 2% /lvm_500_2
root@Microknoppix:~# cat /lvm_500_2/asd.txt
This is a test lvm file
root@Microknoppix:~#
From the above command, you can verify that the file is not affected on resizing the file-system.
Note:-
To view the available physical volume list, execute the following command:
root@Microknoppix:~# pvscan
PV /dev/sdb1 VG vol_grp1 lvm2 [580.00 MiB / 80.00 MiB free]
PV /dev/sdc1 VG vol_grp1 lvm2 [580.00 MiB / 60.00 MiB free]
PV /dev/sdd1 VG vol_grp1 lvm2 [580.00 MiB / 0 free]
Total: 3 [1.70 GiB] / in use: 3 [1.70 GiB] / in no VG: 0 [0 ]
root@Microknoppix:~#
root@Microknoppix:~# pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name vol_grp1
PV Size 582.16 MiB / not usable 2.16 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 145
Free PE 20
Allocated PE 125
PV UUID if9z2Y-vpoR-7PyH-ReAL-0Hpz-hCky-o8IT2d
--- Physical volume ---
PV Name /dev/sdc1
VG Name vol_grp1
PV Size 582.16 MiB / not usable 2.16 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 145
Free PE 15
Allocated PE 130
PV UUID cX7Sc6-Xhy8-WE72-ET6e-RmhN-VFjG-ZHv24Q
--- Physical volume ---
PV Name /dev/sdd1
VG Name vol_grp1
PV Size 582.16 MiB / not usable 2.16 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 145
Free PE 0
Allocated PE 145
PV UUID EnRms2-s7ka-a9c0-CjVL-Shyz-QeJ0-UatOpY
root@Microknoppix:~#
2. Excute following command to get details of volume group created.
root@Microknoppix:~# vgdisplay
--- Volume group ---
VG Name vol_grp1
System ID
Format lvm2
Metadata Areas 3
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 3
Act PV 3
VG Size 1.70 GiB
PE Size 4.00 MiB
Total PE 435
Alloc PE / Size 0 / 0
Free PE / Size 435 / 1.70 GiB
VG UUID QSba44-K2uv-Hwws-iN73-0Ndq-IxW8-aFbcY0
root@Microknoppix:~#
3. Excute following command to get details of logical volume created.
root@Microknoppix:~# lvdisplay
--- Logical volume ---
LV Path /dev/vol_grp1/logical_vol700
LV Name logical_vol700
VG Name vol_grp1
LV UUID gJP2gk-a1Cm-XEN1-ZMM5-8lmr-QJQ6-tIXfwn
LV Write Access read/write
LV Creation host, time Microknoppix, 2015-08-19 16:55:16 +0000
LV Status available
# open 1
LV Size 500.00 MiB
Current LE 125
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
--- Logical volume ---
LV Path /dev/vol_grp1/logical_vol500
LV Name logical_vol500
VG Name vol_grp1
LV UUID xoOjH0-3HMN-nEo0-nDzH-R14h-k4cV-0Qs56O
LV Write Access read/write
LV Creation host, time Microknoppix, 2015-08-19 16:57:05 +0000
LV Status available
# open 1
LV Size 500.00 MiB
Current LE 125
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:1
--- Logical volume ---
LV Path /dev/vol_grp1/logical_vol500_2
LV Name logical_vol500_2
VG Name vol_grp1
LV UUID GqBroa-e2d2-SoWy-ZlU3-2doF-73EY-UWkyqZ
LV Write Access read/write
LV Creation host, time Microknoppix, 2015-08-19 16:58:12 +0000
LV Status available
# open 1
LV Size 600.00 MiB
Current LE 150
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:2
root@Microknoppix:~#
Help Url:
The physical volumes are divided into 4MB units, since that is the extent size. So a content of 100 extebd will have a size of 400M(4*100).