# Adding physical volume into VG

***

### **Prerequisites**

* A new disk (`/dev/sdb` in this case) that you wish to add to the volume group.
* `sudo` privileges or root access to perform LVM management tasks.

***

### **Step-by-Step Guide**

#### **Step 1: Formatting the Disk Using `fdisk`**

Before you can add the new disk to the LVM, you need to partition it.

1. **Open `fdisk` to format the new disk** (e.g., `/dev/sdb`):

   ```bash
   sudo fdisk /dev/sdb
   ```
2. **Create a new partition**:
   * Type `n` to create a new partition.
   * Select the partition type and size (accept default values if unsure).
   * Type `t` to change the partition type.
   * Set the type to `8e` (Linux LVM).
3. **Write the changes**:

   * Type `w` to write the partition table and exit `fdisk`.

   This creates a new partition, e.g., `/dev/sdb1` or `/dev/sdb3`, depending on how you partitioned the disk.

***

#### **Step 2: Verify the Volume Group with `vgdisplay`**

Before adding the new partition to the volume group, you need to identify your existing volume group.

1. **Check the current volume groups**:

   ```bash
   sudo vgdisplay
   ```

   This will show information about the current volume group, such as its name, size, and free space. Make a note of the volume group name (e.g., `ubuntu-vg`), as you’ll need it for the next steps.

***

#### **Step 3: Add the New Disk to the Volume Group**

Now that you have a partition ready (`/dev/sdb3`), you can add it to your existing volume group.

1. **Extend the volume group with the new physical volume**:

   ```bash
   sudo vgextend <volume_group> /dev/sdb3
   ```

   Replace `<volume_group>` with the name of your volume group (e.g., `ubuntu-vg`).

   Example:

   ```bash
   sudo vgextend ubuntu-vg /dev/sdb3
   ```

   This command adds `/dev/sdb3` to the volume group. You can verify the success of this command by running `vgdisplay` again. The "Free PE" (free space) should increase after extending the volume group.

***

#### **Step 4: Extend Logical Volumes (Optional)**

If you wish to allocate the newly added space to a logical volume, you need to extend it.

1. **Check the logical volumes available**:

   ```bash
   sudo lvdisplay
   ```
2. **Extend a specific logical volume** to use the newly added space:

   ```bash
   sudo lvextend -l +100%FREE /dev/<volume_group>/<logical_volume>
   ```

   * Replace `<volume_group>` with your volume group name (e.g., `ubuntu-vg`).
   * Replace `<logical_volume>` with the name of the logical volume you wish to extend (e.g., `ubuntu-lv`).
   * The `-l +100%FREE` option means you want to use all the available free space in the volume group.

   Example:

   ```bash
   sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
   ```

***

#### **Step 5: Resize the Filesystem**

After extending the logical volume, you need to resize the filesystem to take advantage of the new space.

1. **Resize the filesystem** (for ext4 filesystems, for example):

   ```bash
   sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
   ```

   This command will resize the filesystem to utilize all the newly available space in the logical volume.

***

#### **Step 6: Verify the Changes**

1. **Check the logical volume size**:

   ```bash
   sudo lvdisplay
   ```

   This will show the updated size of your logical volume.
2. **Check the filesystem size**:

   ```bash
   df -h
   ```

   This will show the updated space available on the mounted filesystem.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ghoulsec.gitbook.io/ghoulsec-vault/server-are-fun/managing-partitions/lvm/adding-physical-volume-into-vg.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
