0% found this document useful (0 votes)
51 views10 pages

Create A Phy-Vol-lvm

The document provides steps to create logical volumes using Linux Logical Volume Management (LVM). It involves: 1. Creating partitions on two disks and designating one partition on each as physical volumes for LVM using fdisk. 2. Initializing the physical volumes with pvcreate and assigning them to a new volume group called "myvolg" using vgcreate. 3. Creating a 500MB logical volume called "myvol" from the volume group with lvcreate. 4. Formatting the logical volume with an ext4 file system using mkfs.ext4 and mounting it at /myvol. 5. Editing /etc/fstab to ensure the logical volume mounts

Uploaded by

Farhat Antoun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views10 pages

Create A Phy-Vol-lvm

The document provides steps to create logical volumes using Linux Logical Volume Management (LVM). It involves: 1. Creating partitions on two disks and designating one partition on each as physical volumes for LVM using fdisk. 2. Initializing the physical volumes with pvcreate and assigning them to a new volume group called "myvolg" using vgcreate. 3. Creating a 500MB logical volume called "myvol" from the volume group with lvcreate. 4. Formatting the logical volume with an ext4 file system using mkfs.ext4 and mounting it at /myvol. 5. Editing /etc/fstab to ensure the logical volume mounts

Uploaded by

Farhat Antoun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

In this task, you create new partitions and change the system ID to Linux LVM

on /dev/sdc and /dev/sdd.

1. Use the fdisk command to create two partitions on /dev/sdc.

2. fdisk /dev/sdc

The interactive program opens with a short statement on its use, information
about the device selected, and a command prompt.
a. Enter n to add a new primary partition.
b. Enter p, followed by the number 1 for the first primary partition.
c. Press Enter to accept the default (2048) as the start of the first sector.
d. Enter +1G to set the last sector using the size notation.
Note: fdisk returns a message telling you that the new partition is of
the type ‘Linux’ with a size of 1 GiB.
e. Enter n, to create a second primary partition.
f. Enter p, followed by the number 2 for the second primary partition.
g. Press Enter to accept the default as the start of the second sector.
h. Enter +1G to set the last sector using the size notation.
Note: fdisk returns a message telling you of the new partition of the
type ‘Linux’ with a size of 1 GiB.
i. Enter t to change the partition type on partition 2.
j. Press Enter to accept the default of partition 2.
k. Enter 8e as the Hex code for the Linux LVM partition type.
Note: Pressing the letter L displays the Hex codes for the partition
types.

l. Enter p to print the new partition table.


Note: The output lists two partitions, /dev/sdc1 and /dev/sdc2,
with sdc2 being an Linux LVM partition.
m. Enter w to save the new partition table.
3. Use the fdisk command to create two partitions on /dev/sdd.

4. fdisk /dev/sdd
a. Enter n to add a new primary partition.
b. Enter p, followed by the number 1 for the first primary partition.
c. Press Enter to accept the default (2048) as the start of the first sector.
d. Enter +1G to set the last sector using the size notation.
Note: fdisk returns a message telling you that the new partition is of
the type ‘Linux filesystem’ with a size of 1 GiB.

e. Enter nfor the second new partition.


f. Enter p, followed by the number 2 for the second primary partition.
g. Press Enter to accept the default as the start of the second sector.
h. Enter +1G to set the last sector using the size notation.
Note: fdisk returns a message telling you of the new partition of the
type ‘Linux’ with a size of 1 GiB.

i. Enter t to change the partition type on partition 2.


j. Press Enter to accept the default of partition 2.
k. Enter 8e as the Hex code for the Linux LVM partition type.
Note: Pressing the letter L displays the Hex codes for all partition types.

l. Enter p to print the new partition table.


Note: The output lists two partitions, /dev/sdd1 and /dev/sdd2,
with sdd2 being an Linux LVM partition.
m. Enter w to save the new partition table.

Task 3: Create Logical Volume


In this task, you create physical volumes, a volume group, and a logical volume. You
also use LVM utilities to display information about the LVM entities.

The first step in implementing LVM is to create physical volumes.

1. Use the fdisk command and pipe the output to grep to list the ‘Linux LVM’
partitions. The command uses the lowercase letter l and not the numeral one.

2. fdisk -l | grep 8e

3. Use the pvcreate command to create physical volumes on sdc2 and sdd2. You


can initialize multiple disks or partitions in the same command.
4. pvcreate -v /dev/sdc2 /dev/sdd2

Note: Review the command output and notice the actions taken to set up the
physical volume.

a. Use the pvdisplay command to display attributes of the new physical


volume.

b. pvdisplay /dev/sdc2 /dev/sdd2

c. Use the pvs command to report information in a more condensed


form.

d. pvs /dev/sdc2 /dev/sdd2

Note: The physical volumes are not part of a volume group.


e. Use the pvscan command to scan all disks for all physical volumes on
the system.

f. pvscan

5. The next step in implementing LVM is to assign the physical volumes to an


existing or new volume group.
a. Use the vgcreate command to create a volume group
named myvolg from the /dev/sdc2 physical volume.

b. vgcreate -v myvolg /dev/sdc2

Note: Review the command output and notice the actions taken to


create a volume group.
c. Use the vgdisplay command to display attributes of the volume group,
and its associated physical volumes and logical volumes.

d. vgdisplay myvolg

Note: The volume group contains one physical volume and zero logical
volumes.
e. Use the vgs command to report information in a more condensed
form.

f. vgs myvolg

g. Use the vgscan command to scan all supported LVM devices in the


system for volume groups.

h. vgscan

Note: The output confirms that myvolg uses a LVM device.


i. Use the pvs command to display information about the physical
volumes.

j. pvs /dev/sdc2

Note: The format of /dev/sdc2 is lvm2 and assigned to


the myvolg volume group, with 1020 MB of free space.
6. The next step in implementing LVM is to create a logical volume from the
space allocated to the volume group.
a. Use the lvcreate command to create a 500 MB logical volume
named myvol from the myvolg volume group.

b. lvcreate -v -L 500m -n myvol myvolg

Note: Review the command output for the actions taken to create a


logical volume.
c. Use the lvdisplay command to display attributes of the logical
volume. Some of the attributes to note are its directory pach, its size,
and its status.

d. lvdisplay

e. Use the lvs command to report information in a more condensed


form.

f. lvs
g. Use the lvscan command to scan all disks for logical volumes.

h. lvscan

i. Use the pvs command to display information about the physical


volumes.

j. pvs

Note: The free space in the /dev/sdc2 physical volume has been


reduced to 520 MB.
k. Use the vgs command to display information about the volume group.

l. vgs

Note: The free space in the myvolg volume group has also been


reduced.

Task 4: Create a File System


The next two sections represent the remaining tasks in implementing LVM. You first
create a file system on the logical volume.

1. List the /dev entries for the myvol logical volume. The lvcreate command


created two entries in the /dev directory for the logical volume.

2. ls -l /dev/myvolg/myvol
3. ls -l /dev/mapper/myvolg-myvol

Note: The two entries created automatically are both symbolic links


to /dev/dm-2.
4. List the /dev/dm-2 entry.

5. ls -l /dev/dm-2

Note: /dev/dm-2 is a block device.


6. Use the mkfs.ext4 command to create an ext4 file system on
the myvol logical volume.
7. mkfs.ext4 /dev/mapper/myvolg-myvol

Note: Alternatively, you could use /dev/myvolg/myvol when making a file


system.

Task 5: Mount the File System


In this task, you create a mount point, and attach the logical volume to the directory
hierarchy. Next, you update the /etc/fstab file.

1. Use the mkdir command to create a /myvol mount point.

2. mkdir /myvol

3. Use the mount command to mount the file system, and then use


the df command to display the mounted file systems.

4. mount /dev/mapper/myvolg-myvol /myvol


5. df -h

6. Use the command vi /etc/fstab and add the following entry:

7. /dev/mapper/myvolg-myvol /myvol ext4 defaults,_netdev 0


0

Note: When you add an iSCSI remote block volume, you must include


the _netdev mount option or your instance will become unavailable after the
next reboot.

8. Use the umount command to unmount the file system.

9. umount /myvol

10. Use the mount –a command to mount all file system in /etc/fstab file.

11. mount -a

12. Use the command df -h to verify your new file system is mounted.
13. df -h

Note: The file system entries in fstab will automatically mount on system


reboots.

Task 6: Increase the Size of a Logical Volume


In this practice, you increase the size of a logical volume.

1. Use the vgs command to list the volume groups.

2. vgs

Note: The myvolg volume group has 520 MB of free space.

3. Use the lvs command to list the logical volume.

4. lvs

Note: The myvol logical volume is 500 MB in size.

5. Use the df command to display the /myvol file system.

6. df -h /myvol

Note: The size of the file system is 477 MB.

7. Use the lventend command to increase the size of the myvolg/myvol logical


volume and the file system by 500 MB.

8. lvextend -L +500m -r myvolg/myvol

Note: The -r option resizes the file system.


9. Use the vgs command to list the volume groups and add the following entry:

10. vgs

Note: The myvolg volume group now has only 20 MB of free space.


11. Use the lvs command to list the logical volumes.
12. lvs

Note: The myvol logical volume is now 1000 MB.


13. Use the df command to display the /myvol file system.

14. df -h /myvol

Note: The size of the file system is now 961 MB.


15. Use the command ls –l to list the contents of
the /etc/lvm/backup and /etc/lvm/archive directories.

16. ls -l /etc/lvm/backup
17. ls -l /etc/lvm/archive

Note: A new myvolg backup file was automatically created when the logical


volume was extended (notice the time stamp). Also note that a new archive
file was automatically created (notice the time stamp on
the myvolg_0000n file). For more information on these files refer to
the man pages for vgcfgbackup and vgcfgrestore.

Task 7: Add a Physical Volume to a Volume


Group
In this task, you add a physical volume to a volume group.

1. Use the pvs command to list the available physical volumes.

2. pvs

Note The /dev/sdd2 physical volume is not assigned to a volume group.


3. Use the vgs command to list the volume groups.

4. vgs myvolg

Note: The myvolg volume group is 1020 MB in size.


5. Use the vgextend command to add the /dev/sdd2 physical volume to
the myvolg volume group.

6. vgextend -v myvolg /dev/sdd2

7. List the physical volume.

8. pvs /dev/sdd2

Note: The /dev/sdd2 physical volume is now assigned to the myvolg volume


group.
9. List the volume group.

10. vgs myvolg

Note: The myvolg volume group now has two physical volumes (PVs). Also


note that VSize and VFree have also increased.

11. Use the command ls –l to list the contents of


the /etc/lvm/backup and /etc/lvm/archive directories.

12. ls -l /etc/lvm/backup
13. ls -l /etc/lvm/archive

Note: A new myvolg backup file was automatically created when the physical


volume was added to the volume group (notice the time stamp). Also note
that a new archive file was automatically created (notice the time stamp on
the myvolg_0000n+1 file). For more information on these files, refer to
the man pages for vgcfgbackup and vgcfgrestore.

Task 8: Resize the Logical Volume


In this task, you increase the size of the logical volume and the file system by another
500 MB.

1. Use the lvextend command to increase the size of the myvolg/myvol logical


volume and the file system.

2. lvextend -L +500m -r myvolg/myvol


3. List the logical volume.

4. lvs

Note: The myvol logical volume is now 1.46 GB.

5. Display the /myvol file system.

6. df -h /myvol

Task 9: Complete an Optional Lab


If time allows, there is third disk device on which you can practice any of the above
activities.

1. Use the fdisk command to list the available device.

2. fdisk -l /dev/sdb

Note: /dev/sdb is a 50 GiB disk without any partitions.

3. Experiment and have fun.

You might also like