For backup or testing, you can create a snapshot of a Logical Volume:

sudo lvcreate -s -L 5G -n vm1_snap -p r /dev/vmvg/vm1 #Create a snapshot for vm1 (the -p r parameter means the snapshot will be read-only)
A snapshot allows you to get a consistent view of the data at a specific point in time.

TermDescription
PV (Physical Volume)A physical disk or partition used by LVM.
VG (Volume Group)A group of one or more PVs combined into a single storage pool.
LV (Logical Volume)A logical volume created in the VG and used to store data.
Using LVM with iSCSI provides powerful tools for managing virtual machine storage, providing flexibility, scalability, and reliability. Proper configuration and use of LVM can greatly simplify storage management and improve the performance of your virtual machines.

In conclusion, proper storage configuration for virtual machines, especially using iSCSI and LVM, is a key factor in ensuring the high performance and reliability of your virtualization infrastructure. Understanding and applying the techniques described will allow you to effectively manage storage and adapt to the changing requirements of your environment.
VPS хостинг

Виртуальные серверы с гарантированными ресурсами

Выбрать VPS

Add an entry to `/etc/fstab` for automatic mounting:

echo "/dev/vmvg/vm1 /mnt/vm1 ext4 defaults 0 0" | sudo tee -a /etc/fstab

Example: Increasing the Size of a Logical Volume

If a virtual machine needs more space, you can easily increase the size of the Logical Volume:

sudo lvextend -L +10G /dev/vmvg/vm1  # Add 10GB to LV
sudo resize2fs /dev/vmvg/vm1  # Extend the file system
These commands allow you to increase the size of the Logical Volume and file system without virtual machine downtime.

Example: Creating a Snapshot of a Logical Volume

For backup or testing, you can create a snapshot of a Logical Volume:

sudo lvcreate -s -L 5G -n vm1_snap -p r /dev/vmvg/vm1 #Create a snapshot for vm1 (the -p r parameter means the snapshot will be read-only)
A snapshot allows you to get a consistent view of the data at a specific point in time.

TermDescription
PV (Physical Volume)A physical disk or partition used by LVM.
VG (Volume Group)A group of one or more PVs combined into a single storage pool.
LV (Logical Volume)A logical volume created in the VG and used to store data.
Using LVM with iSCSI provides powerful tools for managing virtual machine storage, providing flexibility, scalability, and reliability. Proper configuration and use of LVM can greatly simplify storage management and improve the performance of your virtual machines.

In conclusion, proper storage configuration for virtual machines, especially using iSCSI and LVM, is a key factor in ensuring the high performance and reliability of your virtualization infrastructure. Understanding and applying the techniques described will allow you to effectively manage storage and adapt to the changing requirements of your environment.

Add an entry to `/etc/fstab` for automatic mounting:

echo "/dev/vmvg/vm1 /mnt/vm1 ext4 defaults 0 0" | sudo tee -a /etc/fstab

Example: Increasing the Size of a Logical Volume

If a virtual machine needs more space, you can easily increase the size of the Logical Volume:

sudo lvextend -L +10G /dev/vmvg/vm1  # Add 10GB to LV
sudo resize2fs /dev/vmvg/vm1  # Extend the file system
These commands allow you to increase the size of the Logical Volume and file system without virtual machine downtime.

Example: Creating a Snapshot of a Logical Volume

For backup or testing, you can create a snapshot of a Logical Volume:

sudo lvcreate -s -L 5G -n vm1_snap -p r /dev/vmvg/vm1 #Create a snapshot for vm1 (the -p r parameter means the snapshot will be read-only)
A snapshot allows you to get a consistent view of the data at a specific point in time.

TermDescription
PV (Physical Volume)A physical disk or partition used by LVM.
VG (Volume Group)A group of one or more PVs combined into a single storage pool.
LV (Logical Volume)A logical volume created in the VG and used to store data.
Using LVM with iSCSI provides powerful tools for managing virtual machine storage, providing flexibility, scalability, and reliability. Proper configuration and use of LVM can greatly simplify storage management and improve the performance of your virtual machines.

In conclusion, proper storage configuration for virtual machines, especially using iSCSI and LVM, is a key factor in ensuring the high performance and reliability of your virtualization infrastructure. Understanding and applying the techniques described will allow you to effectively manage storage and adapt to the changing requirements of your environment.

To automatically mount the disk at system startup, add an entry to `/etc/fstab`:

echo "/dev/sdd /mnt/iscsi ext4 defaults,_netdev 0 0" | sudo tee -a /etc/fstab
The `_netdev` option indicates that this is a network device and needs to be mounted after the network is initialized.

Now the iSCSI storage is connected and ready to be used by virtual machines.

Using LVM to Manage iSCSI Storage

LVM (Logical Volume Manager) is a powerful tool for managing storage. It allows you to create Logical Volumes on top of Physical Volumes, combine multiple disks into a single Volume Group, and dynamically resize Logical Volumes. Using LVM in conjunction with iSCSI provides additional flexibility and convenience for managing storage for virtual machines.

Advantages of Using LVM with iSCSI

  • Dynamic Resizing: You can easily increase or decrease the size of logical volumes without virtual machine downtime (when using online resizing).
  • Snapshots: LVM allows you to create snapshots of logical volumes, which is useful for backups and testing.
  • Disk Aggregation: You can combine multiple iSCSI disks into one volume group and create one large logical volume.
  • Block-Level Management: LVM provides flexibility in managing storage at the block level, allowing you to optimize performance and resource allocation.

Step 1: Creating a Physical Volume (PV) on the iSCSI Disk

After connecting the iSCSI disk, you need to create a Physical Volume on it:

sudo pvcreate /dev/sdd  # Replace /dev/sdd with the name of your iSCSI disk

Step 2: Creating a Volume Group (VG)

Then create a Volume Group using the created Physical Volume:

sudo vgcreate vmvg /dev/sdd  # vmvg - Volume Group name

Step 3: Creating a Logical Volume (LV)

Now you can create a Logical Volume inside the Volume Group:

sudo lvcreate -L 20G -n vm1 vmvg  # Create LV with 20GB for VM1
sudo lvcreate -L 30G -n vm2 vmvg  # Create LV with 30GB for VM2
Now we have two Logical Volumes that can be used for virtual machines. These logical volumes can be found in `/dev/vmvg/vm1` and `/dev/vmvg/vm2`.

Step 4: Creating a File System and Mounting the LV

Create a file system on the Logical Volume and mount it:

sudo mkfs.ext4 /dev/vmvg/vm1
sudo mkdir /mnt/vm1
sudo mount /dev/vmvg/vm1 /mnt/vm1
Add an entry to `/etc/fstab` for automatic mounting:

echo "/dev/vmvg/vm1 /mnt/vm1 ext4 defaults 0 0" | sudo tee -a /etc/fstab

Example: Increasing the Size of a Logical Volume

If a virtual machine needs more space, you can easily increase the size of the Logical Volume:

sudo lvextend -L +10G /dev/vmvg/vm1  # Add 10GB to LV
sudo resize2fs /dev/vmvg/vm1  # Extend the file system
These commands allow you to increase the size of the Logical Volume and file system without virtual machine downtime.

Example: Creating a Snapshot of a Logical Volume

For backup or testing, you can create a snapshot of a Logical Volume:

sudo lvcreate -s -L 5G -n vm1_snap -p r /dev/vmvg/vm1 #Create a snapshot for vm1 (the -p r parameter means the snapshot will be read-only)
A snapshot allows you to get a consistent view of the data at a specific point in time.

TermDescription
PV (Physical Volume)A physical disk or partition used by LVM.
VG (Volume Group)A group of one or more PVs combined into a single storage pool.
LV (Logical Volume)A logical volume created in the VG and used to store data.
Using LVM with iSCSI provides powerful tools for managing virtual machine storage, providing flexibility, scalability, and reliability. Proper configuration and use of LVM can greatly simplify storage management and improve the performance of your virtual machines.

In conclusion, proper storage configuration for virtual machines, especially using iSCSI and LVM, is a key factor in ensuring the high performance and reliability of your virtualization infrastructure. Understanding and applying the techniques described will allow you to effectively manage storage and adapt to the changing requirements of your environment.

To automatically mount the disk at system startup, add an entry to `/etc/fstab`:

echo "/dev/sdd /mnt/iscsi ext4 defaults,_netdev 0 0" | sudo tee -a /etc/fstab
The `_netdev` option indicates that this is a network device and needs to be mounted after the network is initialized.

Now the iSCSI storage is connected and ready to be used by virtual machines.

Using LVM to Manage iSCSI Storage

LVM (Logical Volume Manager) is a powerful tool for managing storage. It allows you to create Logical Volumes on top of Physical Volumes, combine multiple disks into a single Volume Group, and dynamically resize Logical Volumes. Using LVM in conjunction with iSCSI provides additional flexibility and convenience for managing storage for virtual machines.

Advantages of Using LVM with iSCSI

  • Dynamic Resizing: You can easily increase or decrease the size of logical volumes without virtual machine downtime (when using online resizing).
  • Snapshots: LVM allows you to create snapshots of logical volumes, which is useful for backups and testing.
  • Disk Aggregation: You can combine multiple iSCSI disks into one volume group and create one large logical volume.
  • Block-Level Management: LVM provides flexibility in managing storage at the block level, allowing you to optimize performance and resource allocation.

Step 1: Creating a Physical Volume (PV) on the iSCSI Disk

After connecting the iSCSI disk, you need to create a Physical Volume on it:

sudo pvcreate /dev/sdd  # Replace /dev/sdd with the name of your iSCSI disk

Step 2: Creating a Volume Group (VG)

Then create a Volume Group using the created Physical Volume:

sudo vgcreate vmvg /dev/sdd  # vmvg - Volume Group name

Step 3: Creating a Logical Volume (LV)

Now you can create a Logical Volume inside the Volume Group:

sudo lvcreate -L 20G -n vm1 vmvg  # Create LV with 20GB for VM1
sudo lvcreate -L 30G -n vm2 vmvg  # Create LV with 30GB for VM2
Now we have two Logical Volumes that can be used for virtual machines. These logical volumes can be found in `/dev/vmvg/vm1` and `/dev/vmvg/vm2`.

Step 4: Creating a File System and Mounting the LV

Create a file system on the Logical Volume and mount it:

sudo mkfs.ext4 /dev/vmvg/vm1
sudo mkdir /mnt/vm1
sudo mount /dev/vmvg/vm1 /mnt/vm1
Add an entry to `/etc/fstab` for automatic mounting:

echo "/dev/vmvg/vm1 /mnt/vm1 ext4 defaults 0 0" | sudo tee -a /etc/fstab

Example: Increasing the Size of a Logical Volume

If a virtual machine needs more space, you can easily increase the size of the Logical Volume:

sudo lvextend -L +10G /dev/vmvg/vm1  # Add 10GB to LV
sudo resize2fs /dev/vmvg/vm1  # Extend the file system
These commands allow you to increase the size of the Logical Volume and file system without virtual machine downtime.

Example: Creating a Snapshot of a Logical Volume

For backup or testing, you can create a snapshot of a Logical Volume:

sudo lvcreate -s -L 5G -n vm1_snap -p r /dev/vmvg/vm1 #Create a snapshot for vm1 (the -p r parameter means the snapshot will be read-only)
A snapshot allows you to get a consistent view of the data at a specific point in time.

TermDescription
PV (Physical Volume)A physical disk or partition used by LVM.
VG (Volume Group)A group of one or more PVs combined into a single storage pool.
LV (Logical Volume)A logical volume created in the VG and used to store data.
Using LVM with iSCSI provides powerful tools for managing virtual machine storage, providing flexibility, scalability, and reliability. Proper configuration and use of LVM can greatly simplify storage management and improve the performance of your virtual machines.

In conclusion, proper storage configuration for virtual machines, especially using iSCSI and LVM, is a key factor in ensuring the high performance and reliability of your virtualization infrastructure. Understanding and applying the techniques described will allow you to effectively manage storage and adapt to the changing requirements of your environment.

Now you can create a file system on the iSCSI disk and mount it:

sudo mkfs.ext4 /dev/sdd # Replace /dev/sdd with the name of your iSCSI disk
sudo mkdir /mnt/iscsi
sudo mount /dev/sdd /mnt/iscsi
To automatically mount the disk at system startup, add an entry to `/etc/fstab`:

echo "/dev/sdd /mnt/iscsi ext4 defaults,_netdev 0 0" | sudo tee -a /etc/fstab
The `_netdev` option indicates that this is a network device and needs to be mounted after the network is initialized.

Now the iSCSI storage is connected and ready to be used by virtual machines.

Using LVM to Manage iSCSI Storage

LVM (Logical Volume Manager) is a powerful tool for managing storage. It allows you to create Logical Volumes on top of Physical Volumes, combine multiple disks into a single Volume Group, and dynamically resize Logical Volumes. Using LVM in conjunction with iSCSI provides additional flexibility and convenience for managing storage for virtual machines.

Advantages of Using LVM with iSCSI

  • Dynamic Resizing: You can easily increase or decrease the size of logical volumes without virtual machine downtime (when using online resizing).
  • Snapshots: LVM allows you to create snapshots of logical volumes, which is useful for backups and testing.
  • Disk Aggregation: You can combine multiple iSCSI disks into one volume group and create one large logical volume.
  • Block-Level Management: LVM provides flexibility in managing storage at the block level, allowing you to optimize performance and resource allocation.

Step 1: Creating a Physical Volume (PV) on the iSCSI Disk

After connecting the iSCSI disk, you need to create a Physical Volume on it:

sudo pvcreate /dev/sdd  # Replace /dev/sdd with the name of your iSCSI disk

Step 2: Creating a Volume Group (VG)

Then create a Volume Group using the created Physical Volume:

sudo vgcreate vmvg /dev/sdd  # vmvg - Volume Group name

Step 3: Creating a Logical Volume (LV)

Now you can create a Logical Volume inside the Volume Group:

sudo lvcreate -L 20G -n vm1 vmvg  # Create LV with 20GB for VM1
sudo lvcreate -L 30G -n vm2 vmvg  # Create LV with 30GB for VM2
Now we have two Logical Volumes that can be used for virtual machines. These logical volumes can be found in `/dev/vmvg/vm1` and `/dev/vmvg/vm2`.

Step 4: Creating a File System and Mounting the LV

Create a file system on the Logical Volume and mount it:

sudo mkfs.ext4 /dev/vmvg/vm1
sudo mkdir /mnt/vm1
sudo mount /dev/vmvg/vm1 /mnt/vm1
Add an entry to `/etc/fstab` for automatic mounting:

echo "/dev/vmvg/vm1 /mnt/vm1 ext4 defaults 0 0" | sudo tee -a /etc/fstab

Example: Increasing the Size of a Logical Volume

If a virtual machine needs more space, you can easily increase the size of the Logical Volume:

sudo lvextend -L +10G /dev/vmvg/vm1  # Add 10GB to LV
sudo resize2fs /dev/vmvg/vm1  # Extend the file system
These commands allow you to increase the size of the Logical Volume and file system without virtual machine downtime.

Example: Creating a Snapshot of a Logical Volume

For backup or testing, you can create a snapshot of a Logical Volume:

sudo lvcreate -s -L 5G -n vm1_snap -p r /dev/vmvg/vm1 #Create a snapshot for vm1 (the -p r parameter means the snapshot will be read-only)
A snapshot allows you to get a consistent view of the data at a specific point in time.

TermDescription
PV (Physical Volume)A physical disk or partition used by LVM.
VG (Volume Group)A group of one or more PVs combined into a single storage pool.
LV (Logical Volume)A logical volume created in the VG and used to store data.
Using LVM with iSCSI provides powerful tools for managing virtual machine storage, providing flexibility, scalability, and reliability. Proper configuration and use of LVM can greatly simplify storage management and improve the performance of your virtual machines.

In conclusion, proper storage configuration for virtual machines, especially using iSCSI and LVM, is a key factor in ensuring the high performance and reliability of your virtualization infrastructure. Understanding and applying the techniques described will allow you to effectively manage storage and adapt to the changing requirements of your environment.

Now you can create a file system on the iSCSI disk and mount it:

sudo mkfs.ext4 /dev/sdd # Replace /dev/sdd with the name of your iSCSI disk
sudo mkdir /mnt/iscsi
sudo mount /dev/sdd /mnt/iscsi
To automatically mount the disk at system startup, add an entry to `/etc/fstab`:

echo "/dev/sdd /mnt/iscsi ext4 defaults,_netdev 0 0" | sudo tee -a /etc/fstab
The `_netdev` option indicates that this is a network device and needs to be mounted after the network is initialized.

Now the iSCSI storage is connected and ready to be used by virtual machines.

Using LVM to Manage iSCSI Storage

LVM (Logical Volume Manager) is a powerful tool for managing storage. It allows you to create Logical Volumes on top of Physical Volumes, combine multiple disks into a single Volume Group, and dynamically resize Logical Volumes. Using LVM in conjunction with iSCSI provides additional flexibility and convenience for managing storage for virtual machines.

Advantages of Using LVM with iSCSI

  • Dynamic Resizing: You can easily increase or decrease the size of logical volumes without virtual machine downtime (when using online resizing).
  • Snapshots: LVM allows you to create snapshots of logical volumes, which is useful for backups and testing.
  • Disk Aggregation: You can combine multiple iSCSI disks into one volume group and create one large logical volume.
  • Block-Level Management: LVM provides flexibility in managing storage at the block level, allowing you to optimize performance and resource allocation.

Step 1: Creating a Physical Volume (PV) on the iSCSI Disk

After connecting the iSCSI disk, you need to create a Physical Volume on it:

sudo pvcreate /dev/sdd  # Replace /dev/sdd with the name of your iSCSI disk

Step 2: Creating a Volume Group (VG)

Then create a Volume Group using the created Physical Volume:

sudo vgcreate vmvg /dev/sdd  # vmvg - Volume Group name

Step 3: Creating a Logical Volume (LV)

Now you can create a Logical Volume inside the Volume Group:

sudo lvcreate -L 20G -n vm1 vmvg  # Create LV with 20GB for VM1
sudo lvcreate -L 30G -n vm2 vmvg  # Create LV with 30GB for VM2
Now we have two Logical Volumes that can be used for virtual machines. These logical volumes can be found in `/dev/vmvg/vm1` and `/dev/vmvg/vm2`.

Step 4: Creating a File System and Mounting the LV

Create a file system on the Logical Volume and mount it:

sudo mkfs.ext4 /dev/vmvg/vm1
sudo mkdir /mnt/vm1
sudo mount /dev/vmvg/vm1 /mnt/vm1
Add an entry to `/etc/fstab` for automatic mounting:

echo "/dev/vmvg/vm1 /mnt/vm1 ext4 defaults 0 0" | sudo tee -a /etc/fstab

Example: Increasing the Size of a Logical Volume

If a virtual machine needs more space, you can easily increase the size of the Logical Volume:

sudo lvextend -L +10G /dev/vmvg/vm1  # Add 10GB to LV
sudo resize2fs /dev/vmvg/vm1  # Extend the file system
These commands allow you to increase the size of the Logical Volume and file system without virtual machine downtime.

Example: Creating a Snapshot of a Logical Volume

For backup or testing, you can create a snapshot of a Logical Volume:

sudo lvcreate -s -L 5G -n vm1_snap -p r /dev/vmvg/vm1 #Create a snapshot for vm1 (the -p r parameter means the snapshot will be read-only)
A snapshot allows you to get a consistent view of the data at a specific point in time.

TermDescription
PV (Physical Volume)A physical disk or partition used by LVM.
VG (Volume Group)A group of one or more PVs combined into a single storage pool.
LV (Logical Volume)A logical volume created in the VG and used to store data.
Using LVM with iSCSI provides powerful tools for managing virtual machine storage, providing flexibility, scalability, and reliability. Proper configuration and use of LVM can greatly simplify storage management and improve the performance of your virtual machines.

In conclusion, proper storage configuration for virtual machines, especially using iSCSI and LVM, is a key factor in ensuring the high performance and reliability of your virtualization infrastructure. Understanding and applying the techniques described will allow you to effectively manage storage and adapt to the changing requirements of your environment.

Example configuration file `/etc/target/saveconfig.json`:

{
  "version": 1,
  "configuration": {
    "iscsi": {
      "iqn.2024-01.example.com:storage.vmdisk1": {
        "tpg1": {
          "luns": {
            "0": {
              "lun": 0,
              "target_portal_group_tag": 1,
              "mapped_lun": 0,
              "backstore": "/backstores/block/iscsi_disk",
              "write_cache": false
            }
          },
          "acls": {
            "iqn.2024-01.example.com:initiator.host1": {
              "authentication": {},
              "mapped_luns": [
                0
              ]
            }
          },
          "portals": {
            "10.0.0.1": {
              "port": 3260
            }
          },
          "authentication": {}
        }
      }
    },
    "backstores": {
      "block": {
        "iscsi_disk": {
          "dev_name": "/dev/iscsivg/iscsilv",
          "write_cache": false
        }
      }
    }
  }
}
This file contains the iSCSI target configuration, including IQN, logical units (LUNs), ACLs (Access Control Lists), and portals.

Step 4: Starting and Enabling the `target` Service

Enable and start the `target` service:

sudo systemctl enable target
sudo systemctl start target
Now the iSCSI Target is configured and ready to use. In the next section, we will look at configuring the iSCSI Initiator on the client.

Configuring iSCSI Initiator on the Client (Virtualization Host)

Configuring an iSCSI Initiator on a virtualization host allows that host to connect to the iSCSI Target and use the provided storage for virtual machines.

Step 1: Installing iSCSI Initiator Packages

As with the Target, you first need to install the necessary packages. In Debian/Ubuntu:

sudo apt update
sudo apt install open-iscsi
In CentOS/RHEL:

sudo yum install iscsi-initiator-utils

Step 2: Configuring the iSCSI Initiator Name

You need to configure the iSCSI Initiator name. It must match what was specified in the ACL on the iSCSI Target. Edit the file `/etc/iscsi/initiatorname.iscsi`:

sudo nano /etc/iscsi/initiatorname.iscsi
And change the `InitiatorName=` line to:

InitiatorName=iqn.2024-01.example.com:initiator.host1
Important: Make sure this name matches what you specified in the ACL on the iSCSI Target.

Step 3: Discovering the iSCSI Target

Start the iscsid service and perform iSCSI Target discovery:

sudo systemctl enable iscsid
sudo systemctl start iscsid
sudo iscsiadm -m discovery -t st -p 10.0.0.1  # Replace 10.0.0.1 with the IP address of the iSCSI Target
This command discovers available iSCSI Targets on the specified IP address. The output will be similar to:

10.0.0.1:3260,1 iqn.2024-01.example.com:storage.vmdisk1

Step 4: Connecting to the iSCSI Target

Now connect to the iSCSI Target:

sudo iscsiadm -m node -T iqn.2024-01.example.com:storage.vmdisk1 -p 10.0.0.1 -l # Replace IQN and IP address
This command establishes a connection to the iSCSI Target. You can check the connection with the `lsblk` command:

lsblk
You should see a new block device corresponding to your iSCSI disk.

Step 5: Creating a File System and Mounting

Now you can create a file system on the iSCSI disk and mount it:

sudo mkfs.ext4 /dev/sdd # Replace /dev/sdd with the name of your iSCSI disk
sudo mkdir /mnt/iscsi
sudo mount /dev/sdd /mnt/iscsi
To automatically mount the disk at system startup, add an entry to `/etc/fstab`:

echo "/dev/sdd /mnt/iscsi ext4 defaults,_netdev 0 0" | sudo tee -a /etc/fstab
The `_netdev` option indicates that this is a network device and needs to be mounted after the network is initialized.

Now the iSCSI storage is connected and ready to be used by virtual machines.

Using LVM to Manage iSCSI Storage

LVM (Logical Volume Manager) is a powerful tool for managing storage. It allows you to create Logical Volumes on top of Physical Volumes, combine multiple disks into a single Volume Group, and dynamically resize Logical Volumes. Using LVM in conjunction with iSCSI provides additional flexibility and convenience for managing storage for virtual machines.

Advantages of Using LVM with iSCSI

  • Dynamic Resizing: You can easily increase or decrease the size of logical volumes without virtual machine downtime (when using online resizing).
  • Snapshots: LVM allows you to create snapshots of logical volumes, which is useful for backups and testing.
  • Disk Aggregation: You can combine multiple iSCSI disks into one volume group and create one large logical volume.
  • Block-Level Management: LVM provides flexibility in managing storage at the block level, allowing you to optimize performance and resource allocation.

Step 1: Creating a Physical Volume (PV) on the iSCSI Disk

After connecting the iSCSI disk, you need to create a Physical Volume on it:

sudo pvcreate /dev/sdd  # Replace /dev/sdd with the name of your iSCSI disk

Step 2: Creating a Volume Group (VG)

Then create a Volume Group using the created Physical Volume:

sudo vgcreate vmvg /dev/sdd  # vmvg - Volume Group name

Step 3: Creating a Logical Volume (LV)

Now you can create a Logical Volume inside the Volume Group:

sudo lvcreate -L 20G -n vm1 vmvg  # Create LV with 20GB for VM1
sudo lvcreate -L 30G -n vm2 vmvg  # Create LV with 30GB for VM2
Now we have two Logical Volumes that can be used for virtual machines. These logical volumes can be found in `/dev/vmvg/vm1` and `/dev/vmvg/vm2`.

Step 4: Creating a File System and Mounting the LV

Create a file system on the Logical Volume and mount it:

sudo mkfs.ext4 /dev/vmvg/vm1
sudo mkdir /mnt/vm1
sudo mount /dev/vmvg/vm1 /mnt/vm1
Add an entry to `/etc/fstab` for automatic mounting:

echo "/dev/vmvg/vm1 /mnt/vm1 ext4 defaults 0 0" | sudo tee -a /etc/fstab

Example: Increasing the Size of a Logical Volume

If a virtual machine needs more space, you can easily increase the size of the Logical Volume:

sudo lvextend -L +10G /dev/vmvg/vm1  # Add 10GB to LV
sudo resize2fs /dev/vmvg/vm1  # Extend the file system
These commands allow you to increase the size of the Logical Volume and file system without virtual machine downtime.

Example: Creating a Snapshot of a Logical Volume

For backup or testing, you can create a snapshot of a Logical Volume:

sudo lvcreate -s -L 5G -n vm1_snap -p r /dev/vmvg/vm1 #Create a snapshot for vm1 (the -p r parameter means the snapshot will be read-only)
A snapshot allows you to get a consistent view of the data at a specific point in time.

TermDescription
PV (Physical Volume)A physical disk or partition used by LVM.
VG (Volume Group)A group of one or more PVs combined into a single storage pool.
LV (Logical Volume)A logical volume created in the VG and used to store data.
Using LVM with iSCSI provides powerful tools for managing virtual machine storage, providing flexibility, scalability, and reliability. Proper configuration and use of LVM can greatly simplify storage management and improve the performance of your virtual machines.

In conclusion, proper storage configuration for virtual machines, especially using iSCSI and LVM, is a key factor in ensuring the high performance and reliability of your virtualization infrastructure. Understanding and applying the techniques described will allow you to effectively manage storage and adapt to the changing requirements of your environment.

Inside `targetcli`, create an iSCSI target:

/backstores/block create iscsi_disk /dev/iscsivg/iscsilv  # For LVM
# or
/backstores/fileio create iscsi_disk /iscsi/iscsi_disk.img  # For file

/iscsi create iqn.2024-01.example.com:storage.vmdisk1
/iscsi/iqn.2024-01.example.com:storage.vmdisk1/tpg1/luns create 0 /backstores/block/iscsi_disk
/iscsi/iqn.2024-01.example.com:storage.vmdisk1/tpg1/acls create iqn.2024-01.example.com:initiator.host1  # Allow access from initiator
/iscsi/iqn.2024-01.example.com:storage.vmdisk1/tpg1/portals create 10.0.0.1 # IP address of iSCSI Target
Important: Replace `iqn.2024-01.example.com:storage.vmdisk1` and `iqn.2024-01.example.com:initiator.host1` with your own IQN (iSCSI Qualified Name). Also replace `10.0.0.1` with the IP address of your iSCSI Target server.

After configuring, save the configuration and exit `targetcli`:

saveconfig
exit
Example configuration file `/etc/target/saveconfig.json`:

{
  "version": 1,
  "configuration": {
    "iscsi": {
      "iqn.2024-01.example.com:storage.vmdisk1": {
        "tpg1": {
          "luns": {
            "0": {
              "lun": 0,
              "target_portal_group_tag": 1,
              "mapped_lun": 0,
              "backstore": "/backstores/block/iscsi_disk",
              "write_cache": false
            }
          },
          "acls": {
            "iqn.2024-01.example.com:initiator.host1": {
              "authentication": {},
              "mapped_luns": [
                0
              ]
            }
          },
          "portals": {
            "10.0.0.1": {
              "port": 3260
            }
          },
          "authentication": {}
        }
      }
    },
    "backstores": {
      "block": {
        "iscsi_disk": {
          "dev_name": "/dev/iscsivg/iscsilv",
          "write_cache": false
        }
      }
    }
  }
}
This file contains the iSCSI target configuration, including IQN, logical units (LUNs), ACLs (Access Control Lists), and portals.

Step 4: Starting and Enabling the `target` Service

Enable and start the `target` service:

sudo systemctl enable target
sudo systemctl start target
Now the iSCSI Target is configured and ready to use. In the next section, we will look at configuring the iSCSI Initiator on the client.

Configuring iSCSI Initiator on the Client (Virtualization Host)

Configuring an iSCSI Initiator on a virtualization host allows that host to connect to the iSCSI Target and use the provided storage for virtual machines.

Step 1: Installing iSCSI Initiator Packages

As with the Target, you first need to install the necessary packages. In Debian/Ubuntu:

sudo apt update
sudo apt install open-iscsi
In CentOS/RHEL:

sudo yum install iscsi-initiator-utils

Step 2: Configuring the iSCSI Initiator Name

You need to configure the iSCSI Initiator name. It must match what was specified in the ACL on the iSCSI Target. Edit the file `/etc/iscsi/initiatorname.iscsi`:

sudo nano /etc/iscsi/initiatorname.iscsi
And change the `InitiatorName=` line to:

InitiatorName=iqn.2024-01.example.com:initiator.host1
Important: Make sure this name matches what you specified in the ACL on the iSCSI Target.

Step 3: Discovering the iSCSI Target

Start the iscsid service and perform iSCSI Target discovery:

sudo systemctl enable iscsid
sudo systemctl start iscsid
sudo iscsiadm -m discovery -t st -p 10.0.0.1  # Replace 10.0.0.1 with the IP address of the iSCSI Target
This command discovers available iSCSI Targets on the specified IP address. The output will be similar to:

10.0.0.1:3260,1 iqn.2024-01.example.com:storage.vmdisk1

Step 4: Connecting to the iSCSI Target

Now connect to the iSCSI Target:

sudo iscsiadm -m node -T iqn.2024-01.example.com:storage.vmdisk1 -p 10.0.0.1 -l # Replace IQN and IP address
This command establishes a connection to the iSCSI Target. You can check the connection with the `lsblk` command:

lsblk
You should see a new block device corresponding to your iSCSI disk.

Step 5: Creating a File System and Mounting

Now you can create a file system on the iSCSI disk and mount it:

sudo mkfs.ext4 /dev/sdd # Replace /dev/sdd with the name of your iSCSI disk
sudo mkdir /mnt/iscsi
sudo mount /dev/sdd /mnt/iscsi
To automatically mount the disk at system startup, add an entry to `/etc/fstab`:

echo "/dev/sdd /mnt/iscsi ext4 defaults,_netdev 0 0" | sudo tee -a /etc/fstab
The `_netdev` option indicates that this is a network device and needs to be mounted after the network is initialized.

Now the iSCSI storage is connected and ready to be used by virtual machines.

Using LVM to Manage iSCSI Storage

LVM (Logical Volume Manager) is a powerful tool for managing storage. It allows you to create Logical Volumes on top of Physical Volumes, combine multiple disks into a single Volume Group, and dynamically resize Logical Volumes. Using LVM in conjunction with iSCSI provides additional flexibility and convenience for managing storage for virtual machines.

Advantages of Using LVM with iSCSI

  • Dynamic Resizing: You can easily increase or decrease the size of logical volumes without virtual machine downtime (when using online resizing).
  • Snapshots: LVM allows you to create snapshots of logical volumes, which is useful for backups and testing.
  • Disk Aggregation: You can combine multiple iSCSI disks into one volume group and create one large logical volume.
  • Block-Level Management: LVM provides flexibility in managing storage at the block level, allowing you to optimize performance and resource allocation.

Step 1: Creating a Physical Volume (PV) on the iSCSI Disk

After connecting the iSCSI disk, you need to create a Physical Volume on it:

sudo pvcreate /dev/sdd  # Replace /dev/sdd with the name of your iSCSI disk

Step 2: Creating a Volume Group (VG)

Then create a Volume Group using the created Physical Volume:

sudo vgcreate vmvg /dev/sdd  # vmvg - Volume Group name

Step 3: Creating a Logical Volume (LV)

Now you can create a Logical Volume inside the Volume Group:

sudo lvcreate -L 20G -n vm1 vmvg  # Create LV with 20GB for VM1
sudo lvcreate -L 30G -n vm2 vmvg  # Create LV with 30GB for VM2
Now we have two Logical Volumes that can be used for virtual machines. These logical volumes can be found in `/dev/vmvg/vm1` and `/dev/vmvg/vm2`.

Step 4: Creating a File System and Mounting the LV

Create a file system on the Logical Volume and mount it:

sudo mkfs.ext4 /dev/vmvg/vm1
sudo mkdir /mnt/vm1
sudo mount /dev/vmvg/vm1 /mnt/vm1
Add an entry to `/etc/fstab` for automatic mounting:

echo "/dev/vmvg/vm1 /mnt/vm1 ext4 defaults 0 0" | sudo tee -a /etc/fstab

Example: Increasing the Size of a Logical Volume

If a virtual machine needs more space, you can easily increase the size of the Logical Volume:

sudo lvextend -L +10G /dev/vmvg/vm1  # Add 10GB to LV
sudo resize2fs /dev/vmvg/vm1  # Extend the file system
These commands allow you to increase the size of the Logical Volume and file system without virtual machine downtime.

Example: Creating a Snapshot of a Logical Volume

For backup or testing, you can create a snapshot of a Logical Volume:

sudo lvcreate -s -L 5G -n vm1_snap -p r /dev/vmvg/vm1 #Create a snapshot for vm1 (the -p r parameter means the snapshot will be read-only)
A snapshot allows you to get a consistent view of the data at a specific point in time.

TermDescription
PV (Physical Volume)A physical disk or partition used by LVM.
VG (Volume Group)A group of one or more PVs combined into a single storage pool.
LV (Logical Volume)A logical volume created in the VG and used to store data.
Using LVM with iSCSI provides powerful tools for managing virtual machine storage, providing flexibility, scalability, and reliability. Proper configuration and use of LVM can greatly simplify storage management and improve the performance of your virtual machines.

In conclusion, proper storage configuration for virtual machines, especially using iSCSI and LVM, is a key factor in ensuring the high performance and reliability of your virtualization infrastructure. Understanding and applying the techniques described will allow you to effectively manage storage and adapt to the changing requirements of your environment.

Inside `targetcli`, create an iSCSI target:

/backstores/block create iscsi_disk /dev/iscsivg/iscsilv  # For LVM
# or
/backstores/fileio create iscsi_disk /iscsi/iscsi_disk.img  # For file

/iscsi create iqn.2024-01.example.com:storage.vmdisk1
/iscsi/iqn.2024-01.example.com:storage.vmdisk1/tpg1/luns create 0 /backstores/block/iscsi_disk
/iscsi/iqn.2024-01.example.com:storage.vmdisk1/tpg1/acls create iqn.2024-01.example.com:initiator.host1  # Allow access from initiator
/iscsi/iqn.2024-01.example.com:storage.vmdisk1/tpg1/portals create 10.0.0.1 # IP address of iSCSI Target
Important: Replace `iqn.2024-01.example.com:storage.vmdisk1` and `iqn.2024-01.example.com:initiator.host1` with your own IQN (iSCSI Qualified Name). Also replace `10.0.0.1` with the IP address of your iSCSI Target server.

After configuring, save the configuration and exit `targetcli`:

saveconfig
exit
Example configuration file `/etc/target/saveconfig.json`:

{
  "version": 1,
  "configuration": {
    "iscsi": {
      "iqn.2024-01.example.com:storage.vmdisk1": {
        "tpg1": {
          "luns": {
            "0": {
              "lun": 0,
              "target_portal_group_tag": 1,
              "mapped_lun": 0,
              "backstore": "/backstores/block/iscsi_disk",
              "write_cache": false
            }
          },
          "acls": {
            "iqn.2024-01.example.com:initiator.host1": {
              "authentication": {},
              "mapped_luns": [
                0
              ]
            }
          },
          "portals": {
            "10.0.0.1": {
              "port": 3260
            }
          },
          "authentication": {}
        }
      }
    },
    "backstores": {
      "block": {
        "iscsi_disk": {
          "dev_name": "/dev/iscsivg/iscsilv",
          "write_cache": false
        }
      }
    }
  }
}
This file contains the iSCSI target configuration, including IQN, logical units (LUNs), ACLs (Access Control Lists), and portals.

Step 4: Starting and Enabling the `target` Service

Enable and start the `target` service:

sudo systemctl enable target
sudo systemctl start target
Now the iSCSI Target is configured and ready to use. In the next section, we will look at configuring the iSCSI Initiator on the client.

Configuring iSCSI Initiator on the Client (Virtualization Host)

Configuring an iSCSI Initiator on a virtualization host allows that host to connect to the iSCSI Target and use the provided storage for virtual machines.

Step 1: Installing iSCSI Initiator Packages

As with the Target, you first need to install the necessary packages. In Debian/Ubuntu:

sudo apt update
sudo apt install open-iscsi
In CentOS/RHEL:

sudo yum install iscsi-initiator-utils

Step 2: Configuring the iSCSI Initiator Name

You need to configure the iSCSI Initiator name. It must match what was specified in the ACL on the iSCSI Target. Edit the file `/etc/iscsi/initiatorname.iscsi`:

sudo nano /etc/iscsi/initiatorname.iscsi
And change the `InitiatorName=` line to:

InitiatorName=iqn.2024-01.example.com:initiator.host1
Important: Make sure this name matches what you specified in the ACL on the iSCSI Target.

Step 3: Discovering the iSCSI Target

Start the iscsid service and perform iSCSI Target discovery:

sudo systemctl enable iscsid
sudo systemctl start iscsid
sudo iscsiadm -m discovery -t st -p 10.0.0.1  # Replace 10.0.0.1 with the IP address of the iSCSI Target
This command discovers available iSCSI Targets on the specified IP address. The output will be similar to:

10.0.0.1:3260,1 iqn.2024-01.example.com:storage.vmdisk1

Step 4: Connecting to the iSCSI Target

Now connect to the iSCSI Target:

sudo iscsiadm -m node -T iqn.2024-01.example.com:storage.vmdisk1 -p 10.0.0.1 -l # Replace IQN and IP address
This command establishes a connection to the iSCSI Target. You can check the connection with the `lsblk` command:

lsblk
You should see a new block device corresponding to your iSCSI disk.

Step 5: Creating a File System and Mounting

Now you can create a file system on the iSCSI disk and mount it:

sudo mkfs.ext4 /dev/sdd # Replace /dev/sdd with the name of your iSCSI disk
sudo mkdir /mnt/iscsi
sudo mount /dev/sdd /mnt/iscsi
To automatically mount the disk at system startup, add an entry to `/etc/fstab`:

echo "/dev/sdd /mnt/iscsi ext4 defaults,_netdev 0 0" | sudo tee -a /etc/fstab
The `_netdev` option indicates that this is a network device and needs to be mounted after the network is initialized.

Now the iSCSI storage is connected and ready to be used by virtual machines.

Using LVM to Manage iSCSI Storage

LVM (Logical Volume Manager) is a powerful tool for managing storage. It allows you to create Logical Volumes on top of Physical Volumes, combine multiple disks into a single Volume Group, and dynamically resize Logical Volumes. Using LVM in conjunction with iSCSI provides additional flexibility and convenience for managing storage for virtual machines.

Advantages of Using LVM with iSCSI

  • Dynamic Resizing: You can easily increase or decrease the size of logical volumes without virtual machine downtime (when using online resizing).
  • Snapshots: LVM allows you to create snapshots of logical volumes, which is useful for backups and testing.
  • Disk Aggregation: You can combine multiple iSCSI disks into one volume group and create one large logical volume.
  • Block-Level Management: LVM provides flexibility in managing storage at the block level, allowing you to optimize performance and resource allocation.

Step 1: Creating a Physical Volume (PV) on the iSCSI Disk

After connecting the iSCSI disk, you need to create a Physical Volume on it:

sudo pvcreate /dev/sdd  # Replace /dev/sdd with the name of your iSCSI disk

Step 2: Creating a Volume Group (VG)

Then create a Volume Group using the created Physical Volume:

sudo vgcreate vmvg /dev/sdd  # vmvg - Volume Group name

Step 3: Creating a Logical Volume (LV)

Now you can create a Logical Volume inside the Volume Group:

sudo lvcreate -L 20G -n vm1 vmvg  # Create LV with 20GB for VM1
sudo lvcreate -L 30G -n vm2 vmvg  # Create LV with 30GB for VM2
Now we have two Logical Volumes that can be used for virtual machines. These logical volumes can be found in `/dev/vmvg/vm1` and `/dev/vmvg/vm2`.

Step 4: Creating a File System and Mounting the LV

Create a file system on the Logical Volume and mount it:

sudo mkfs.ext4 /dev/vmvg/vm1
sudo mkdir /mnt/vm1
sudo mount /dev/vmvg/vm1 /mnt/vm1
Add an entry to `/etc/fstab` for automatic mounting:

echo "/dev/vmvg/vm1 /mnt/vm1 ext4 defaults 0 0" | sudo tee -a /etc/fstab

Example: Increasing the Size of a Logical Volume

If a virtual machine needs more space, you can easily increase the size of the Logical Volume:

sudo lvextend -L +10G /dev/vmvg/vm1  # Add 10GB to LV
sudo resize2fs /dev/vmvg/vm1  # Extend the file system
These commands allow you to increase the size of the Logical Volume and file system without virtual machine downtime.

Example: Creating a Snapshot of a Logical Volume

For backup or testing, you can create a snapshot of a Logical Volume:

sudo lvcreate -s -L 5G -n vm1_snap -p r /dev/vmvg/vm1 #Create a snapshot for vm1 (the -p r parameter means the snapshot will be read-only)
A snapshot allows you to get a consistent view of the data at a specific point in time.

TermDescription
PV (Physical Volume)A physical disk or partition used by LVM.
VG (Volume Group)A group of one or more PVs combined into a single storage pool.
LV (Logical Volume)A logical volume created in the VG and used to store data.
Using LVM with iSCSI provides powerful tools for managing virtual machine storage, providing flexibility, scalability, and reliability. Proper configuration and use of LVM can greatly simplify storage management and improve the performance of your virtual machines.

In conclusion, proper storage configuration for virtual machines, especially using iSCSI and LVM, is a key factor in ensuring the high performance and reliability of your virtualization infrastructure. Understanding and applying the techniques described will allow you to effectively manage storage and adapt to the changing requirements of your environment.

How to Configure Storage for Virtual Machines: iSCSI and LVM

In the world of virtualization, proper storage configuration is critical for the performance and stability of virtual machines. A misconfigured storage can lead to bottlenecks, reduced performance, and ultimately, problems with your virtual machines. In this article, we will focus on using iSCSI and LVM (Logical Volume Manager) to create a robust and flexible storage solution for virtual machines running, for example, on KVM or VMware ESXi. We will cover step-by-step setup, as well as provide specific examples and configuration files.

Table of Contents

What is iSCSI and Why is it Needed for Virtual Machines?

How to configure storage for virtual machines? - Diagram illustrating the iSCSI communication process between initiator and target
iSCSI (Internet Small Computer System Interface) is a protocol that allows transmitting SCSI commands over a TCP/IP network. Essentially, it allows us to use an Ethernet network to connect to storage as if it were a local SCSI disk. For virtual machines, iSCSI provides several advantages:

  • Centralized Storage: Virtual machines can access storage located on a separate server or storage array, simplifying management and backup.
  • Cost-Effectiveness: iSCSI can be implemented using standard network hardware, reducing costs compared to Fibre Channel.
  • Flexibility: It’s easy to add or expand storage for virtual machines as needed.
  • Performance: With proper configuration and the use of fast network connections (e.g., 10 Gigabit Ethernet), iSCSI can provide high performance for virtual machines.
Consider an example: you have several servers running virtual machines. Instead of installing local disks on each server, you can use iSCSI to allow all virtual machines to access a single shared storage. This simplifies backups, virtual machine migration, and overall storage management.

Example 1: Advantages of Centralized Storage

Imagine you have three physical servers (host1, host2, host3), each managing multiple virtual machines. Without iSCSI, each server would require local storage. If a virtual machine on host1 needs more space, you would have to physically add disks to host1. With iSCSI, all three servers can use a shared iSCSI Target storage. If you need to expand storage, you only increase it on the iSCSI Target, and the changes will be automatically available to all servers.

Example 2: Shared File System and iSCSI

iSCSI is often used in conjunction with clustered file systems, such as GFS2 or OCFS2. iSCSI provides a block device, which is then mounted as a shared file system. This allows multiple virtual machines to simultaneously access the same files, which is necessary for clustered applications.

Expert Tip: When using iSCSI for virtual machines, make sure your network is properly configured for Jumbo Frames (MTU 9000). This can significantly increase performance by reducing the load on the processor when processing network packets.

In the next section, we will look at how to configure an iSCSI Target on the server.

Configuring iSCSI Target on the Server

How to configure storage for virtual machines? - Screenshot of the iSCSI target configuration file
Configuring an iSCSI Target involves installing and configuring the iSCSI Target software on the server that will provide the storage. In this example, we will use `targetcli` in Linux.

Step 1: Installing the Necessary Packages

First, we need to install the necessary packages. Depending on the Linux distribution, the command may be slightly different. For example, in Debian/Ubuntu:

sudo apt update
sudo apt install targetcli
In CentOS/RHEL:

sudo yum install targetcli

Step 2: Creating a Block Device (LVM or File)

The iSCSI Target provides a block device. This can be an LVM volume, a physical disk, or a regular file. In this example, we will create an LVM volume:

sudo vgcreate iscsivg /dev/sdb  # /dev/sdb - physical disk
sudo lvcreate -L 50G -n iscsilv iscsivg  # Create a logical volume of 50GB
Instead of LVM, you can use a file, but this is not recommended for production environments due to performance:

sudo dd if=/dev/zero of=/iscsi/iscsi_disk.img bs=1M count=51200 # Create a 50GB file

Step 3: Configuring iSCSI Target with `targetcli`

Run `targetcli`:

sudo targetcli
Inside `targetcli`, create an iSCSI target:

/backstores/block create iscsi_disk /dev/iscsivg/iscsilv  # For LVM
# or
/backstores/fileio create iscsi_disk /iscsi/iscsi_disk.img  # For file

/iscsi create iqn.2024-01.example.com:storage.vmdisk1
/iscsi/iqn.2024-01.example.com:storage.vmdisk1/tpg1/luns create 0 /backstores/block/iscsi_disk
/iscsi/iqn.2024-01.example.com:storage.vmdisk1/tpg1/acls create iqn.2024-01.example.com:initiator.host1  # Allow access from initiator
/iscsi/iqn.2024-01.example.com:storage.vmdisk1/tpg1/portals create 10.0.0.1 # IP address of iSCSI Target
Important: Replace `iqn.2024-01.example.com:storage.vmdisk1` and `iqn.2024-01.example.com:initiator.host1` with your own IQN (iSCSI Qualified Name). Also replace `10.0.0.1` with the IP address of your iSCSI Target server.

After configuring, save the configuration and exit `targetcli`:

saveconfig
exit
Example configuration file `/etc/target/saveconfig.json`:

{
  "version": 1,
  "configuration": {
    "iscsi": {
      "iqn.2024-01.example.com:storage.vmdisk1": {
        "tpg1": {
          "luns": {
            "0": {
              "lun": 0,
              "target_portal_group_tag": 1,
              "mapped_lun": 0,
              "backstore": "/backstores/block/iscsi_disk",
              "write_cache": false
            }
          },
          "acls": {
            "iqn.2024-01.example.com:initiator.host1": {
              "authentication": {},
              "mapped_luns": [
                0
              ]
            }
          },
          "portals": {
            "10.0.0.1": {
              "port": 3260
            }
          },
          "authentication": {}
        }
      }
    },
    "backstores": {
      "block": {
        "iscsi_disk": {
          "dev_name": "/dev/iscsivg/iscsilv",
          "write_cache": false
        }
      }
    }
  }
}
This file contains the iSCSI target configuration, including IQN, logical units (LUNs), ACLs (Access Control Lists), and portals.

Step 4: Starting and Enabling the `target` Service

Enable and start the `target` service:

sudo systemctl enable target
sudo systemctl start target
Now the iSCSI Target is configured and ready to use. In the next section, we will look at configuring the iSCSI Initiator on the client.

Configuring iSCSI Initiator on the Client (Virtualization Host)

Configuring an iSCSI Initiator on a virtualization host allows that host to connect to the iSCSI Target and use the provided storage for virtual machines.

Step 1: Installing iSCSI Initiator Packages

As with the Target, you first need to install the necessary packages. In Debian/Ubuntu:

sudo apt update
sudo apt install open-iscsi
In CentOS/RHEL:

sudo yum install iscsi-initiator-utils

Step 2: Configuring the iSCSI Initiator Name

You need to configure the iSCSI Initiator name. It must match what was specified in the ACL on the iSCSI Target. Edit the file `/etc/iscsi/initiatorname.iscsi`:

sudo nano /etc/iscsi/initiatorname.iscsi
And change the `InitiatorName=` line to:

InitiatorName=iqn.2024-01.example.com:initiator.host1
Important: Make sure this name matches what you specified in the ACL on the iSCSI Target.

Step 3: Discovering the iSCSI Target

Start the iscsid service and perform iSCSI Target discovery:

sudo systemctl enable iscsid
sudo systemctl start iscsid
sudo iscsiadm -m discovery -t st -p 10.0.0.1  # Replace 10.0.0.1 with the IP address of the iSCSI Target
This command discovers available iSCSI Targets on the specified IP address. The output will be similar to:

10.0.0.1:3260,1 iqn.2024-01.example.com:storage.vmdisk1

Step 4: Connecting to the iSCSI Target

Now connect to the iSCSI Target:

sudo iscsiadm -m node -T iqn.2024-01.example.com:storage.vmdisk1 -p 10.0.0.1 -l # Replace IQN and IP address
This command establishes a connection to the iSCSI Target. You can check the connection with the `lsblk` command:

lsblk
You should see a new block device corresponding to your iSCSI disk.

Step 5: Creating a File System and Mounting

Now you can create a file system on the iSCSI disk and mount it:

sudo mkfs.ext4 /dev/sdd # Replace /dev/sdd with the name of your iSCSI disk
sudo mkdir /mnt/iscsi
sudo mount /dev/sdd /mnt/iscsi
To automatically mount the disk at system startup, add an entry to `/etc/fstab`:

echo "/dev/sdd /mnt/iscsi ext4 defaults,_netdev 0 0" | sudo tee -a /etc/fstab
The `_netdev` option indicates that this is a network device and needs to be mounted after the network is initialized.

Now the iSCSI storage is connected and ready to be used by virtual machines.

Using LVM to Manage iSCSI Storage

LVM (Logical Volume Manager) is a powerful tool for managing storage. It allows you to create Logical Volumes on top of Physical Volumes, combine multiple disks into a single Volume Group, and dynamically resize Logical Volumes. Using LVM in conjunction with iSCSI provides additional flexibility and convenience for managing storage for virtual machines.

Advantages of Using LVM with iSCSI

  • Dynamic Resizing: You can easily increase or decrease the size of logical volumes without virtual machine downtime (when using online resizing).
  • Snapshots: LVM allows you to create snapshots of logical volumes, which is useful for backups and testing.
  • Disk Aggregation: You can combine multiple iSCSI disks into one volume group and create one large logical volume.
  • Block-Level Management: LVM provides flexibility in managing storage at the block level, allowing you to optimize performance and resource allocation.

Step 1: Creating a Physical Volume (PV) on the iSCSI Disk

After connecting the iSCSI disk, you need to create a Physical Volume on it:

sudo pvcreate /dev/sdd  # Replace /dev/sdd with the name of your iSCSI disk

Step 2: Creating a Volume Group (VG)

Then create a Volume Group using the created Physical Volume:

sudo vgcreate vmvg /dev/sdd  # vmvg - Volume Group name

Step 3: Creating a Logical Volume (LV)

Now you can create a Logical Volume inside the Volume Group:

sudo lvcreate -L 20G -n vm1 vmvg  # Create LV with 20GB for VM1
sudo lvcreate -L 30G -n vm2 vmvg  # Create LV with 30GB for VM2
Now we have two Logical Volumes that can be used for virtual machines. These logical volumes can be found in `/dev/vmvg/vm1` and `/dev/vmvg/vm2`.

Step 4: Creating a File System and Mounting the LV

Create a file system on the Logical Volume and mount it:

sudo mkfs.ext4 /dev/vmvg/vm1
sudo mkdir /mnt/vm1
sudo mount /dev/vmvg/vm1 /mnt/vm1
Add an entry to `/etc/fstab` for automatic mounting:

echo "/dev/vmvg/vm1 /mnt/vm1 ext4 defaults 0 0" | sudo tee -a /etc/fstab

Example: Increasing the Size of a Logical Volume

If a virtual machine needs more space, you can easily increase the size of the Logical Volume:

sudo lvextend -L +10G /dev/vmvg/vm1  # Add 10GB to LV
sudo resize2fs /dev/vmvg/vm1  # Extend the file system
These commands allow you to increase the size of the Logical Volume and file system without virtual machine downtime.

Example: Creating a Snapshot of a Logical Volume

For backup or testing, you can create a snapshot of a Logical Volume:

sudo lvcreate -s -L 5G -n vm1_snap -p r /dev/vmvg/vm1 #Create a snapshot for vm1 (the -p r parameter means the snapshot will be read-only)
A snapshot allows you to get a consistent view of the data at a specific point in time.

TermDescription
PV (Physical Volume)A physical disk or partition used by LVM.
VG (Volume Group)A group of one or more PVs combined into a single storage pool.
LV (Logical Volume)A logical volume created in the VG and used to store data.
Using LVM with iSCSI provides powerful tools for managing virtual machine storage, providing flexibility, scalability, and reliability. Proper configuration and use of LVM can greatly simplify storage management and improve the performance of your virtual machines.

In conclusion, proper storage configuration for virtual machines, especially using iSCSI and LVM, is a key factor in ensuring the high performance and reliability of your virtualization infrastructure. Understanding and applying the techniques described will allow you to effectively manage storage and adapt to the changing requirements of your environment.