fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
Added new hard disk(2 GB) using Vmware settings
From the host, used following command to scan new disk
echo "- - -" > /sys/class/scsi_host/host2/scan
Disk /dev/sda: 8589 MB, 8589934592 bytes
Disk /dev/sdb: 2147 MB, 2147483648 bytes
Noticed new disk /dev/sdb after scan
Now Creating new LVM using new disk
1) Creating Physical volume
[root@Ram ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
2) Assign physical volume to volume group
[root@Ram ~]# vgcreate vg1 /dev/sdb
Volume group "vg1" successfully created
3) Check your work
[root@Ram ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 1 0 0 wz--n- 2.00g 2.00g
[root@Ram ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb vg1 lvm2 a- 2.00g 2.00g
Now Create Logical Volumes of 1 GB initially. I will explain how to extend and reduce after this
[root@Ram ~]# lvcreate -L 1GB -n lg1 vg1
Logical volume "lg1" created
[root@Ram ~]# mke2fs -j /dev/vg1/lg1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
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.
Now Create new filesystem
[root@Ram ~]# mkdir /test
[root@Ram ~]# mount /dev/vg1/lg1 /test
[root@Ram ~]# df -h
/dev/mapper/vg1-lg1 1008M 34M 924M 4% /test
Now filesystem is mounted but when you restart the system, it will not mount it again. For that, we need to update /etc/fstab file
/dev/mapper/vg1-lg1 /test ext4 defaults 0 0
After updating, we can make sure it is correct by unmounting and mounting it again
[root@Ram ~]# umount /test
[root@Ram ~]# mount /test
Cool. Now we will extend the filesystem from 1 GB to 1.5 GB.
First we will check if we have enough space for this
[root@Ram ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 1 1 0 wz--n- 2.00g 1020.00m
Yep, we have space.
[root@Ram ~]# lvextend -L +512MB /dev/vg1/lg1
Extending logical volume lg1 to 1.50 GiB
Logical volume lg1 successfully resized
It will still show 1 GB
/dev/mapper/vg1-lg1 1008M 34M 924M 4% /test
Now we have to execute following command to extend
root@Ram ~]# resize2fs /dev/vg1/lg1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg1/lg1 is mounted on /test; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg1/lg1 to 393216 (4k) blocks.
The filesystem on /dev/vg1/lg1 is now 393216 blocks long.
[root@Ram ~]# df -h
/dev/mapper/vg1-lg1 1.5G 34M 1.4G 3% /test
We got email from developer to reduce the filesystem to 1 GB since he accidently sent wrong filesystem
Ok, the problem for reducing filesystem, we have to unmount the filesystem
[root@Ram ~]# umount /test
Check the filesytem
[root@Ram ~]# e2fsck -f /dev/vg1/lg1
e2fsck 1.41.12 (17-May-2010)
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/vg1/lg1: 11/98304 files (0.0% non-contiguous), 14765/393216 blocks
[root@Ram ~]# resize2fs /dev/vg1/lg1 1024M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg1/lg1 to 262144 (4k) blocks.
The filesystem on /dev/vg1/lg1 is now 262144 blocks long.
[root@Ram ~]# lvreduce -L 1024M /dev/vg1/lg1
WARNING: Reducing active logical volume to 1.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lg1? [y/n]: y
Reducing logical volume lg1 to 1.00 GiB
Logical volume lg1 successfully resized
Mount the filesystem
[root@Ram ~]# mount /test
[root@Ram ~]# df -h
/dev/mapper/vg1-lg1 1008M 34M 924M 4% /test
No comments:
Post a Comment