# Работа с дисками lvm

##### Команды с описанием

`df -h` - отображает статус дисков в файловой системе

`fdisk -l` - показать какие есть диски

`lsblk` - показать какие есть диски

`cfdisk /dev/sdb` - редактирование раздела sdb

`/etc/fstab` - тут прописываем новые диски

`mount /media/hdd2` - присоединяет диск, прописанный в файле *fstab* с именем *hdd2*

### Обновление инфы о дисках

```bash
echo 1 > /sys/block/sda/device/rescan
```

```bash
echo "- - -" | tee /sys/class/scsi_host/host*/scan
```

# How to add an extra second hard drive on Linux LVM and increase the size of storage

<div class="headline_area" id="bkmrk-author%3A%C2%A0vivek-gite%C2%A0l"><div class="byline"><span class="post_author_intro">Author:</span> <span class="post_author">Vivek Gite</span> <span class="post_date_intro">Last updated:</span> <span class="post_date date_modified" title="2023-08-06">August 6, 2023</span> [<span class="num_comments">48</span> comments](https://www.cyberciti.biz/faq/howto-add-disk-to-lvm-volume-on-linux-to-increase-size-of-pool/#comments)</div></div><div class="post_content" id="bkmrk-ihave-250gb-disk-ins"><div>  
</div>*<span class="drop_cap">I</span>have 250GB disk installed on my home Linux server. I just bought a brand new 250GB SATA disk and I want to add a new disk to my existing LVM volume to increase its size total size to 500GB. How do I add a disk to LVM and extend an LVM volume on Linux operating system?*  
<span id="bkmrk--1"></span>  
Logical volume management (LVM) creates an easy to use layer over physical disks. You can combine multiple disks and create logical storage volumes. This provides specific benefits such as:</div><div class="post_content" id="bkmrk--2"><div class="card"><div class="card-body">  
</div></div></div><div class="post_content" id="bkmrk-no-restriction-on-di"><div class="card" id="bkmrk--3"><div class="card-body"><div class="card-text">  
</div></div></div>1. No restriction on disk size
2. Increased disk throughput
3. Mirroring volumes for business critical data
4. Volume snapshots
5. Easy backups and restores using snapshots
6. Easy data relocation
7. Resizing storage pools (add or remove disks) without reformatting disks

This tutorial **shows you how to make partitioning, formatting, and add a new disk to LVM volume on Linux**. For demo purpose, I am using Ubuntu VM, but the commands remain same for bare metal or any other virtualization technology such as KVM, Xen, VMware and so on.</div>**Warning**: Be careful with lvm/mkfs.ext4 and other commands, and device names as wrong device name can wipe out all data. **Proceed with caution** and always keep full backups. The nixCraft or author is not responsible for data loss.

## Step 1 – Find out information about existing LVM

LVM Storage Management divided into three parts:

<div class="post_content" id="bkmrk-physical-volumes-%28pv">1. **Physical Volumes (PV)** – Actual disks (e.g. /dev/sda, /dev,sdb, /dev/vdb and so on)
2. **Volume Groups (VG)** – Physical volumes are combined into volume groups. (e.g. my\_vg = /dev/sda + /dev/sdb.)
3. **Logical Volumes (LV)** – A volume group is divided up into logical volumes (e.g. my\_vg divided into my\_vg/data, my\_vg/backups, my\_vg/home, my\_vg/mysqldb and so on)

</div>Type the following commands to find out information about each part.

### How to display physical volumes (pv)

Type the following pvs command to see info about physical volumes:  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo pvs`  
Sample outputs:

<div class="post_content" id="bkmrk--4"><div class="wp-caption aligncenter">[![Fig.01: How to display information about LVM physical volumes](https://www.cyberciti.biz/media/new/faq/2017/02/pvs-command-to-display-lvm-physical-volumes.jpg)](https://www.cyberciti.biz/faq/howto-add-disk-to-lvm-volume-on-linux-to-increase-size-of-pool/pvs-command-to-display-lvm-physical-volumes/)</div></div>Fig.01: How to display information about LVM physical volumes

<div class="post_content" id="bkmrk-so-currently-my-lvm-"><div class="wp-caption aligncenter" id="bkmrk--5"></div>So currently my LVM include a physical volume (actual disk) called /dev/vda5. To see detailed attributes information, type:  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo pvdisplay`  
Sample outputs:  
<div class="wp-caption aligncenter">[![Fig.02: See attributes of a physical volume (PV)](https://www.cyberciti.biz/media/new/faq/2017/02/pvdisplay-show.jpg)](https://www.cyberciti.biz/faq/howto-add-disk-to-lvm-volume-on-linux-to-increase-size-of-pool/pvdisplay-show/)</div></div>Fig.02: See attributes of a physical volume (PV)

<div class="post_content" id="bkmrk-from-above-output-it"><div class="wp-caption aligncenter" id="bkmrk--6"></div>From above output it is clear that our volume group named ubuntu-box-1-vg is made of a physical volume named /dev/vda5.</div>### How to display information about LVM volume Groups (vg)

Type any one of the following vgs command/vgdisplay command to see information about volume groups and its attributes:  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo vgs`  
OR  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo vgdisplay`  
Sample outputs:

<div class="post_content" id="bkmrk--7"><div class="wp-caption aligncenter">[![Fig.03: How to see information about LVM volume groups (vg)](https://www.cyberciti.biz/media/new/faq/2017/02/howto-see-lvm-volume-groups-infomation.jpg)](https://www.cyberciti.biz/faq/howto-add-disk-to-lvm-volume-on-linux-to-increase-size-of-pool/howto-see-lvm-volume-groups-infomation/)</div></div>Fig.03: How to see information about LVM volume groups (vg)

<div class="post_content" id="bkmrk--8"><div class="wp-caption aligncenter" id="bkmrk--9"></div></div>### How to display information about LVM logical volume (lv)

Type any one of the following lvs command/lvdisplay command to see information about volume groups and its attributes:  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo lvs`  
OR  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo lvdisplay`  
Sample outputs:

<div class="post_content" id="bkmrk--10"><div class="wp-caption aligncenter">[![Fig.04: How to display information about logical volumes (lv)](https://www.cyberciti.biz/media/new/faq/2017/02/howto-see-display-information-lvm-logical-volumes.jpg)](https://www.cyberciti.biz/faq/howto-add-disk-to-lvm-volume-on-linux-to-increase-size-of-pool/howto-see-display-information-lvm-logical-volumes/)</div></div>Fig.04: How to display information about logical volumes (lv)

<div class="post_content" id="bkmrk-my-ubuntu-box-1-vg-v"><div class="wp-caption aligncenter" id="bkmrk--11"></div>My ubuntu-box-1-vg volume group divided into two logical volumes:</div><div class="post_content" id="bkmrk-%2Fdev%2Fubuntu-box-1-vg">1. /dev/ubuntu-box-1-vg/root – Root file system
2. /dev/ubuntu-box-1-vg/swap\_1 – Swap space

</div>Based upon above commands, you can get a basic idea how LVM organizes storage device into Physical Volumes (PV), Volume Groups (VG), and Logical Volumes (LV):

<div class="post_content" id="bkmrk--12"><div class="wp-caption aligncenter">[![Fig.05: How LVM organizes storage device into Physical Volumes (PV), Volume Groups (VG), & Logical Volumes (LV)](https://www.cyberciti.biz/media/new/faq/2017/02/understanding-LVM-Architecture.jpg)](https://www.cyberciti.biz/faq/howto-add-disk-to-lvm-volume-on-linux-to-increase-size-of-pool/understanding-lvm-architecture/)</div></div>Fig.05: How LVM organizes storage device into Physical Volumes (PV), Volume Groups (VG), &amp; Logical Volumes (LV)

<div class="post_content" id="bkmrk--13"><div class="wp-caption aligncenter" id="bkmrk--14"></div></div>## Step 2 – Find out information about new disk

You need to add a new disk to your server. In this example, for demo purpose I added a new disk drive, and it has 5GiB size. To find out information about new disks run:  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo fdisk -l`  
OR  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo fdisk -l | grep '^Disk /dev/'`  
Sample outputs:

<div class="post_content" id="bkmrk--15"><div class="wp-caption aligncenter">[![Fig.06: Find out installed disk names on Linux](https://www.cyberciti.biz/media/new/faq/2017/02/list-linux-disks-using-fdisk-lcommand.jpg)](https://www.cyberciti.biz/faq/howto-add-disk-to-lvm-volume-on-linux-to-increase-size-of-pool/list-linux-disks-using-fdisk-lcommand/)</div></div>Fig.06: Find out installed disk names on Linux

<div class="post_content" id="bkmrk-another-option-is-to"><div class="wp-caption aligncenter" id="bkmrk--16"></div>Another option is to scan for all devices visible to LVM2:  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo lvmdiskscan`  
Sample outputs:</div>```
  /dev/ram0                   [      64.00 MiB] 
  /dev/ubuntu-box-1-vg/root   [      37.49 GiB] 
  /dev/ram1                   [      64.00 MiB] 
  /dev/ubuntu-box-1-vg/swap_1 [       2.00 GiB] 
  /dev/vda1                   [     487.00 MiB] 
  /dev/ram2                   [      64.00 MiB] 
  /dev/ram3                   [      64.00 MiB] 
  /dev/ram4                   [      64.00 MiB] 
  /dev/ram5                   [      64.00 MiB] 
  /dev/vda5                   [      39.52 GiB] LVM physical volume
  /dev/ram6                   [      64.00 MiB] 
  /dev/ram7                   [      64.00 MiB] 
  /dev/ram8                   [      64.00 MiB] 
  /dev/ram9                   [      64.00 MiB] 
  /dev/ram10                  [      64.00 MiB] 
  /dev/ram11                  [      64.00 MiB] 
  /dev/ram12                  [      64.00 MiB] 
  /dev/ram13                  [      64.00 MiB] 
  /dev/ram14                  [      64.00 MiB] 
  /dev/ram15                  [      64.00 MiB] 
  /dev/vdb                    [       5.00 GiB] 
  2 disks
  18 partitions
  0 LVM physical volume whole disks
  1 LVM physical volume
```

## Step 3 – Create physical volumes (pv) on new disk named /dev/vdb

Type the following command:  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo pvcreate /dev/vdb`  
Sample outputs:

```
  Physical volume "/dev/vdb" successfully created
```

Now run the following command to verify:  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo lvmdiskscan -l`  
Sample outputs:

```
  WARNING: only considering LVM devices
  /dev/vda5                   [      39.52 GiB] LVM physical volume
  /dev/vdb                    [       5.00 GiB] LVM physical volume
  1 LVM physical volume whole disk
  1 LVM physical volume
```

## Step 4 – Add newly created pv named /dev/vdb to an existing lv

Type the following command to add a physical volume /dev/vdb to “ubuntu-box-1-vg” volume group:  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo vgextend ubuntu-box-1-vg /dev/vdb`  
Sample outputs:

```
  Volume group "ubuntu-box-1-vg" successfully extended
```

Finally, you need extend the /dev/ubuntu-box-1-vg/root to create total 45GB (/dev/vdb (5G)+ existing /dev/ubuntu-box-1-vg/root (40G))  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo lvm lvextend -l +100%FREE /dev/ubuntu-box-1-vg/root`  
Sample outputs:

```
  Size of logical volume ubuntu-box-1-vg/root changed from 37.49 GiB (9597 extents) to 42.52 GiB (10885 extents).
  Logical volume root successfully resized.
```

However, if you run df -h or any other command you will still see /dev/ubuntu-box-1-vg/root as 40G. You need to run the following command to enlarge the filesystem created inside the “root” volume:  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>sudo resize2fs -p /dev/mapper/ubuntu--box--1--vg-root`  
Sample outputs:

```
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mapper/ubuntu--box--1--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 3
The filesystem on /dev/mapper/ubuntu--box--1--vg-root is now 11146240 (4k) blocks long.
```

Verify it again using the [df command](https://www.cyberciti.biz/faq/df-command-examples-in-linux-unix/ "How to use df command in Linux / Unix {with examples}") or mount command. For example:  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>mount<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>mount | <a href="https://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/" title="How to use grep command in Linux/ Unix with examples">grep</a> '/dev/mapper/ubuntu'`  
OR  
`<span class="normaluserprompt" title="The shell prompt usually ends in a $ sign and is not part of the command for the nonprivileged user.">$ </span>df -H`  
Sample outputs:

```
Filesystem                           Size  Used Avail Use% Mounted on
udev                                 1.1G     0  1.1G   0% /dev
tmpfs                                146M   12M  135M   9% /run
<strong>/dev/mapper/ubuntu--box--1--vg-root   45G  2.3G   41G   6% /</strong>
tmpfs                                512M     0  512M   0% /dev/shm
tmpfs                                5.3M     0  5.3M   0% /run/lock
tmpfs                                512M     0  512M   0% /sys/fs/cgroup
/dev/vda1                            495M  109M  361M  24% /boot
tmpfs                                103M     0  103M   0% /run/user/0
```