Logical volumes

Create and manage logical volumes from storage devices, and format them with file systems or prepare them with swap spaces.

Task 1:

One Logical Volume named lv1is created under vg0. The initial size of the logical volume is 100mb. Now you required to size 500mb. Make successfully the size of that logical volume 500mb without losing any data. As well as size should be increased online.

Solution:

fdisk /dev/sda # first create new partition using fdisk
n # new partition
p # primary
# first sector press enter
second sector +501M
w # save changes

---

mkfs.ext4 /dev/sda1 /dev/sda1 #format partition
vgcreate vg0 /dev/sda1 #create volume group named vg0
vgdisplay #check status of vg
lvcreate -n lv1 -L 100M vg0  # create logical volume with size 100M and name lv1
lvdisplay /dev/vg0/lv1  # to check status of logical volume
lvextend -L 500M /dev/vg0/lv1  #extend to 500M
resize2fs /dev/vg0/lv1  #resize filesystem on lv1 to match the new lv size if needed.

Task 2:

Create a logical volme as required:

Name the logical volume as database, belongs to datastore of the volume group size is 50PE.

Expansion size of each volume group datastore is 16MB.

Use ext3 to format this new logical volume, this logical volume should automatically mount to /mnt/database

Solution:

pvcreate /dev/sdX
vgcreate datastore /dev/sdX
vgcreate -s 16M datastore /dev/sdX
lvcreate -l 50 -n database datastore
mkfs.ext3 /dev/datastore/database
mkdir -p /mnt/database
mount /dev/datastore/database /mnt/database
echo '/dev/datastore/database /mnt/database ext3 defaults 0 0' >> /etc/fstab
mount -a
df -h

Task 3:

One logical volume named /dev/test0/testvolume1is created. The initial size of that disk is 100mb now you required more 200MB. Increase the size of Logical Volume, size should be increase on online.

Solution:

fdisk /dev/sda
n
p
1
enter
+310M
w

---

partprobe /dev/sda
vgcreate test0 /dev/sda1
lvcreate -n testvolume1 -L 100M test0
lvextend -L +200M /dev/test0/testvolume1

Task 4:

Resize the logical volume, lvrz and reduce filesystem to 4600MiB. Make sure the filesystem contents remain intact with mount point /datarz

(Note: partitions are seldom exactly the size required, so anything with the range of 4200MiB to 4900MiB is acceptable)

Solution:

# backup data:
tar -czvf /backup/datarz_backup.tar.gz /datarz

umount /datarz
fsck -f /dev/datastore/lvrz
resize2fs /dev/datastore/lvrz 4600M
lvreduce -L 4600M /dev/datastore/lvrz
mount /dev/datastore/lvrz /datarz
echo '/dev/datastore/lvrz /datarz ext3 defaults 0 0' >> /etc/fstab
lvdisplay /dev/datastore/lvrz
df -h /datarz

Task 5:

We are working on /datainitially the size is 2GB. The /dev/test0/lvtestvolumeis mount on /data. Now you required more space on /databut you already added all disks belong to physical volume. You saw that you have unallocated space around 5GB on your harddisk. Increase the size of lvtestvolume by 5GB.

Solution:

fdisk /dev/sda
n
p
1
enter
+5.1G
w
partprobe /dev/sda
pvccreate /dev/sda
lsblk
vgcreate test0 /dev/sda1
lvcreate -L 2G -n lvtestvolume test0
lvdisplay
mkdir -p /data
mount /dev/test0/lvtestvolume /data
lvextend -L +3G /dev/test0/lvtestvolume
lvdisplay

Task 6

Adjust the size of the vo logical volume, its file system size should be 290M. Make sure that the content of this system is complte.

NOTE: the partition size is rarely accurate to the same size as required, so in the range 270M to 320M is acceptable.

Solution:

fdisk /dev/sdX  # X is a,b and so on, in my case it is a
n
p
1
enter
+320M
w
partprobe /dev/sda1
pvcreate /dev/sda1
vgcreate vg0 /dev/sda1
lvcreate -L 190M -n vo /dev/vg0
lvdisplay
lvextend -L +100M /dev/vg0/vo

Task 7:

There us a local logical volume in your system, named with common and belong to vgsrv volume group, mount to the /common directory. the definition of the size is 128MB.

Requirement:

Extend the logical volume to 190MB without any loss of data. The size is allowed between 160MB after extending.

Solution:

fdisk /dev/sda
n
p
1
enter
+201M
t
8e
w
partprobe /dev/sda
pvcreate /dev/sda1
vgcreate vgsrv /dev/sda1
lvcreate -L 128M -n common /dev/vgsrv
lvdisplay
lvextend -L 190M /dev/vgsrv/common
resize2fs /dev/vgsrv/common
mkdir -p /common
mount /dev/vgsrv/common /common

Task 8:

Create thin-provisioned filesystem with the name think_fs from pool think_pool using the devices. The filesystem should be mounted on /strav and must be persistent accross reboot.

Solution:

pvcreate /dev/sda1 /dev/sda2
vgcreate think_pool /dev/sda1 /dev/sda2
lvcreate -n think_fs -L 1.5G think_pool
mkfs.ext4 /dev/think_pool/think_fs
mkdir -p /strav
vim /etc/fstab
/dev/think_pool/think_fs /strav    ext4    defaults 0 2
mount /dev/think_pool/think_fs /strav
df -hT

Task 9:

Change the logical volume capacity named vo from 190M to 300M. and the size of the floating range should set between 280 and 320.

Solution:

fdisk /dev/sda
n
p
1
enter
+300M
t
8e
w
partprobe /dev/sda
pvcreate /dev/sda1
vgcreate vg2 /dev/sda1
lvcreate -L 190M -n lv2 /dev/vg2
lvdisplay
lvextend -L +110M /dev/vg2/lv2
resize2fs /dev/vg2/lv2
mount -a

Task 10:

Create volume group, and set the size is 500M, the size of single pe is 16M. Create logical volume named lv0 in this volume group, set size is 20pe, make it as ext3 file system, and mounted automatically under data.

Solution:

fdisk /dev/sda
n
p
1
enter
+500M
w
partprobe /dev/sda
pvcreeate /dev/sda1
vgcreate -s 16M vg0 /dev/sda1
lvcreate -n lv0 -l 20 /dev/vg0
mkfs.ext3 /dev/mapper/vg0-lv0
mkdir /data
vim /etc/fstab
/dev/mapper/vg0-lv0    /data    ext3    defaults 0 0
mount -a
mount | grep data

Task 11:

One logical volume is created named as myvol under vo volume group and is mounted. The initial size of that logical volume is 400MB. Make successfully that the size of logical volume is 200MB without losing any data. The size of logical volume 200MB to 210MB. will be acceptable.

Solution:

fdisk /dev/sda
n
p
1
enter
+404M
w
partprobe /dev/sda
pvcreate /dev/sda1
vgcreate vo /dev/sda1
lvcreate -n myvol -L 400M /dev/vo
mkdir /data
mkfs.ext3 /dev/mapper/vo-myvol
mount /dev/mapper/mo-myvol /data
umount /dev/mapper/vo-myvol
e2fsck -f /dev/vo/myvol
resize2fs /dev/vo/myvol 200M
lvreduce -L 200M /dev/vo/myvol
mount /dev/mapper/vo-myvol /data
lvdisplay

Task 12:

There is logical volumes in your system, named with shrink and belong to vgsrv volume group, mount to the /shrink directory. The definition of size is 320MB.

Requirement:

Reduce the logical volume to 220MB without any loss of data. The size is allowed between 200-260MB after reucing.

Solution:

fdisk /dev/sda
n
p
1
enter
+321M
w
lsblk
partprobe /dev/sda
pvcreate /dev/sda1
vgcreate vgsrv /dev/sda1
lvcreate -n shrink -L 320M /dev/vgsrv
mkdir /shrink
mkfs.ext3 /dev/mapper/vgsrv-shrink
mount /dev/mapper/vgsrv-shrink /shrink
umount /dev/mapper/vgsrv-shrink
e2fsck -f /dev/mapper/vgsrv-shrink
resize2fs /dev/mapper/vgsrv-shrink 220M
lvreduce -L 220M /dev/mapper/vgsrv-shrink
lvdisplay
mount /dev/mapper/vgsrv-shrink /shrink
lsblk

Task 13:

Create volume group, and set 16M as a extends. And divided a volume group containing 50 extends on volume group lv, make it as ext4 files system, and mounted automatically under /mnt/data

Solution:

fdisk /dev/sda
n
p
1
enter
+815M
w
partprobe /dev/sda
pvcreate /dev/sda1
vgcreate -s 16M vg1 /dev/sda1
lvcreate -l 50 lv /dev/vg1
mkfs.ext4 /dev/vg1/lv
vim /etc/fstab
/dev/vg1/lv /mnt/data ext4 defaults 0 0
mkdir -p /mnt/data
mount -a

Last updated

Was this helpful?