Please guide that how to do following tasks with executing command.

  • 1.Create a new physical volume, create a new volume group in the name of dataconresize, vg extent is 16.00MB.
  • 2.Create a new logical volume in the name of datacopyresize with the size of 50 extents and file system must ext4
  • 3.Then mount it under /dataresize
  • 4.Resize the logical volume, logical-data and it filesystem to 400MB.
  • 5.Resize the logical volume, logical-data and it filesystem to 600MB. Make sure that the filesystem contents remain intact.

Note: partitions are seldom exactly the size requested,so any thing within the range of 370MB to 430MB is acceptable.

I tried first three steps as follows.

fdisk /dev/vdb 

----- > Create the Partition and set it's type 8e (which is LVM type)

partprobe /dev/vdb  

-----> get the partition

pvcreate /dev/vdb1
vgcreate -s 16M dataconresize /dev/vdb1

-----> Check the vg extent size, its should be this (PE Size 16.00 MiB)

lvcreate -l 50 -n datacopyresize dataconresize

-----> Check the size of extents

mkfs.ext4 /dev/dataconresize/datacopyresize  

-----> Make a filesystem on it

mkdir -p /dataresize  

-----> Create Directory to mount on it

blkid /dev/dataconresize/datacopyresize  

-----> Get the UUID of /dev/datacontainer/datacopy

vim /etc/fstab 

-----> Create the mount point inside the fstab

UUID=C553-2BF5 /dataresize ext4 defaults 0 0  
mount -a

df -hT  

-----> get the mount point of it

But I am stuck with task 4 and task 5.


You have a LV called "datacopyresize" of size PE_size x 50 = 800 Mb.

To shrink it to 400 Mb you will need to resize first the filesystem, then the LV (otherwise you'll lose data):

resize2fs /dev/dataconresize/datacopyresize 400M
lvresize -L 400M /dev/dataconresize/datacopyresize

Then to extend it to 600 Mb, you first resize the LV and then the filesystem:

lvresize -L 600M /dev/dataconresize/datacopyresize
resize2fs /dev/dataconresize/datacopyresize 600M

Note: you could use instead lvreduce to shrink the LV and lvextend to extend it; the advantage of lvresize is that it offers an unique command for both operations.
Also, you could pass the --resizefs argument to lvresize to automatically resize the fs along with the LV, instead of using resize2fs; I suggest you try my method, which uses two separate commands, to better understand what you're doing.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.