[root@GLPI ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─cs-root 253:0 0 17G 0 lvm /
└─cs-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 3G 0 disk
sdc 8:32 0 3G 0 disk
sr0 11:0 1 1024M 0 rom
Step 1: Install LVM2
First, ensure that the LVM2 package is installed on your system. This package provides the necessary tools for managing LVM.
sudo dnf install lvm2
sudo
: Runs the command with superuser privileges.dnf
: The package manager for CentOS Stream.install lvm2
: Installs the LVM2 package.
Step 2: Prepare Physical Volumes
You need to have one or more physical disks or partitions to create LVM. You can use existing partitions or create new ones. For this example, let's assume you have two disks: /dev/sdb
and /dev/sdc
.
Note: Make sure to replace /dev/sdb
and /dev/sdc
with your actual disk identifiers.
To create physical volumes, use the following command:
sudo pvcreate /dev/sdb /dev/sdc
pvcreate
: This command initializes the specified disk(s) as physical volumes for LVM./dev/sdb /dev/sdc
: The disks you are initializing.
Step 3: Create a Volume Group
Next, you need to create a volume group (VG) that will contain the physical volumes. You can name your volume group anything you like; in this example, we will call it vg01
.
sudo vgcreate vg01 /dev/sdb /dev/sdc
vgcreate
: This command creates a new volume group.vg01
: The name of the volume group you are creating./dev/sdb /dev/sdc
: The physical volumes that will be included in this volume group.
Step 4: Create Logical Volumes
Now that you have a volume group, you can create logical volumes (LVs) within that group. For example, let's create a logical volume named lv01
with a size of 10GB.
sudo lvcreate -n lv01 -L 5G vg01
lvcreate
: This command creates a new logical volume.-n lv01
: Specifies the name of the logical volume.-L 5G
: Specifies the size of the logical volume (10 gigabytes).vg01
: The volume group in which the logical volume will be created
Step 5: Format the Logical Volume
Before you can use the logical volume, you need to format it with a filesystem. For example, you can use the ext4 filesystem:
sudo mkfs.xfs /dev/vg01/lv01
mkfs.ext4
: This command formats the logical volume with the ext4 filesystem./dev/vg01/lv01
: The path to the logical volume you just created.
Step 6: Mount the Logical Volume
Now, you can mount the logical volume to a directory. First, create a mount point:
sudo mkdir /mnt/lv01
mkdir /mnt/lv01
: Creates a directory where the logical volume will be mounted.Next, mount the logical volume:
mount
: This command mounts the specified filesystem./dev/vg01/lv01
: The logical volume you want to mount./mnt/lv01
: The directory where you want to mount the logical volume.
Step 7: Verify the Setup
You can verify that the logical volume is mounted correctly by using the df
command:
df -h
df -h
: Displays the disk space usage in a human-readable format.
You should see an entry for /mnt/lv01
showing the size and usage of the logical volume.
Step 8: Make the Mount Permanent
To ensure that the logical volume is mounted automatically at boot, you need to add an entry to the /etc/fstab
file. Open the file in a text editor:
sudo nano /etc/fstab
Add the following line at the end of the file:
/dev/vg01/lv01 /mnt/lv01 xfs defaults 0 0
- This line specifies the device, mount point, filesystem type, mount options, and dump/pass options.
Save and exit the editor (in nano, press CTRL + X
, then Y
, and Enter
).
Step 9: Reboot and Verify
Finally, reboot your system to verify that the logical volume mounts automatically:
sudo reboot
Step 1: Create Some Files in lv01
First, navigate to the mounted logical volume directory:
cd /mnt/lv01
Now, create some files. You can use the touch
command to create empty files or echo
to create files with content. Here are a few examples:
touch file1.txt 2echo "This is file 2" > file2.txt 3echo "This is file 3" > file3.txt
touch file1.txt
: Creates an empty file namedfile1.txt
.echo "This is file 2" > file2.txt
: Creates a file namedfile2.txt
with the specified content.echo "This is file 3" > file3.txt
: Creates a file namedfile3.txt
with the specified content.
Step 2: Verify the Files
You can list the files in the directory to verify that they were created successfully:
ls -l
You should see file1.txt
, file2.txt
, and file3.txt
listed.
1. List Physical Volumes
To list all physical volumes (PVs) in your LVM setup, use the following command:
sudo pvs
2. List Volume Groups
To list all volume groups (VGs), use the following command:
sudo vgs
vgs
: This command displays a summary of all volume groups, including their names, number of physical volumes, number of logical volumes, total size, and free space.
3. List Logical Volumes
To list all logical volumes (LVs), use the following command:
sudo lvs
To list all logical volumes (LVs), use the following command:
sudo lvs
4. Detailed Information
If you want more detailed information about each component, you can use the following commands:
- For Physical Volumes:
- sudo pvdisplay
- For Volume Groups:
sudo vgdisplay
BACKUP
[root@localhost lv01]# yum install xfsdump -y
[root@localhost lv01]# xfsdump -f /tmp/backup.dump /mnt/lv01
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.12 (dump format 3.0) - type ^C for status and control
============================= dump label dialog ==============================
please enter label for this dump session (timeout in 300 sec)
-> backup
session label entered: "backup"
--------------------------------- end dialog ---------------------------------
xfsdump: level 0 dump of localhost.localdomain:/mnt/lv01
xfsdump: dump date: Sun Jan 5 08:14:14 2025
xfsdump: session id: 27195896-3d59-4e1b-b8a3-03503b8ec022
xfsdump: session label: "backup"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 29952 bytes
============================= media label dialog =============================
please enter label for media in drive 0 (timeout in 300 sec)
-> backup
media label entered: "backup"
--------------------------------- end dialog ---------------------------------
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 24072 bytes
xfsdump: dump size (non-dir files) : 1088 bytes
xfsdump: dump complete: 51 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /tmp/backup.dump OK (success)
xfsdump: Dump Status: SUCCESS
[root@localhost ~]# sudo umount /mnt/lv01
Remove:[root@localhost ~]# lvremove /dev/vg01/lv01
If you want more detailed information about each component, you can use the following commands:
- For Physical Volumes:
- sudo pvdisplay
- For Volume Groups:
No comments:
Post a Comment