# 10. Resize LVM Linux

To mount `sdb` to an LVM (Logical Volume Manager) on Linux, you'll first need to prepare the disk and create the necessary partitions and volumes. Here's a step-by-step guide:

1. **Partition the disk (`sdb`)**: You can use a partitioning tool like `fdisk` or `parted` to create partitions on `sdb`. For example, you can create a single partition spanning the entire disk.
    
    <div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">bash <div class="flex items-center"><span class="" data-state="closed"><button class="flex gap-1 items-center"><svg class="icon-sm" fill="none" height="24" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path clip-rule="evenodd" d="M7 5a3 3 0 0 1 3-3h9a3 3 0 0 1 3 3v9a3 3 0 0 1-3 3h-2v2a3 3 0 0 1-3 3H5a3 3 0 0 1-3-3v-9a3 3 0 0 1 3-3h2zm2 2h5a3 3 0 0 1 3 3v5h2a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1h-9a1 1 0 0 0-1 1zM5 9a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1v-9a1 1 0 0 0-1-1z" fill="currentColor" fill-rule="evenodd"></path></svg>Copy code</button></span></div></div><div class="overflow-y-auto p-4 text-left undefined" dir="ltr">`sudo fdisk /dev/sdb`</div></div>Then follow the prompts to create a new partition (`n`), choose primary partition, select the default partition number, and use the entire disk (`+1T`).
2. **Create a Physical Volume (PV)**: After partitioning, you need to initialize the partition as a physical volume for LVM.
    
    <div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">bash <div class="flex items-center"><span class="" data-state="closed"><button class="flex gap-1 items-center"><svg class="icon-sm" fill="none" height="24" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path clip-rule="evenodd" d="M7 5a3 3 0 0 1 3-3h9a3 3 0 0 1 3 3v9a3 3 0 0 1-3 3h-2v2a3 3 0 0 1-3 3H5a3 3 0 0 1-3-3v-9a3 3 0 0 1 3-3h2zm2 2h5a3 3 0 0 1 3 3v5h2a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1h-9a1 1 0 0 0-1 1zM5 9a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1v-9a1 1 0 0 0-1-1z" fill="currentColor" fill-rule="evenodd"></path></svg>Copy code</button></span></div></div><div class="overflow-y-auto p-4 text-left undefined" dir="ltr">`sudo pvcreate /dev/sdb1`</div></div>
3. **Extend the Volume Group (VG)**: If you want to extend an existing volume group, you can use `vgextend`. If you want to create a new one, you can use `vgcreate`. For extending an existing VG, you might have to check its name.
    
    <div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">bash <div class="flex items-center"><span class="" data-state="closed"><button class="flex gap-1 items-center"><svg class="icon-sm" fill="none" height="24" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path clip-rule="evenodd" d="M7 5a3 3 0 0 1 3-3h9a3 3 0 0 1 3 3v9a3 3 0 0 1-3 3h-2v2a3 3 0 0 1-3 3H5a3 3 0 0 1-3-3v-9a3 3 0 0 1 3-3h2zm2 2h5a3 3 0 0 1 3 3v5h2a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1h-9a1 1 0 0 0-1 1zM5 9a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1v-9a1 1 0 0 0-1-1z" fill="currentColor" fill-rule="evenodd"></path></svg>Copy code</button></span></div></div><div class="overflow-y-auto p-4 text-left undefined" dir="ltr">`sudo vgextend ubuntu-vg /dev/sdb1`</div></div>Replace `ubuntu-vg` with the name of your volume group.
4. **Create a Logical Volume (LV)**: Once the volume group is extended, you can create a logical volume within it.
    
    <div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">perl <div class="flex items-center"><span class="" data-state="closed"><button class="flex gap-1 items-center"><svg class="icon-sm" fill="none" height="24" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path clip-rule="evenodd" d="M7 5a3 3 0 0 1 3-3h9a3 3 0 0 1 3 3v9a3 3 0 0 1-3 3h-2v2a3 3 0 0 1-3 3H5a3 3 0 0 1-3-3v-9a3 3 0 0 1 3-3h2zm2 2h5a3 3 0 0 1 3 3v5h2a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1h-9a1 1 0 0 0-1 1zM5 9a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1v-9a1 1 0 0 0-1-1z" fill="currentColor" fill-rule="evenodd"></path></svg>Copy code</button></span></div></div><div class="overflow-y-auto p-4 text-left undefined" dir="ltr">`sudo lvcreate -l <span class="hljs-number">100</span>%FREE -n sdb-lv ubuntu-vg`</div></div>This creates a logical volume named `sdb-lv` using all available space in the volume group `ubuntu-vg`.
5. **Format the Logical Volume**: You'll need to format the newly created logical volume with a file system. Replace `ext4` with your desired file system type.
    
    <div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">bash <div class="flex items-center"><span class="" data-state="closed"><button class="flex gap-1 items-center"><svg class="icon-sm" fill="none" height="24" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path clip-rule="evenodd" d="M7 5a3 3 0 0 1 3-3h9a3 3 0 0 1 3 3v9a3 3 0 0 1-3 3h-2v2a3 3 0 0 1-3 3H5a3 3 0 0 1-3-3v-9a3 3 0 0 1 3-3h2zm2 2h5a3 3 0 0 1 3 3v5h2a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1h-9a1 1 0 0 0-1 1zM5 9a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1v-9a1 1 0 0 0-1-1z" fill="currentColor" fill-rule="evenodd"></path></svg>Copy code</button></span></div></div><div class="overflow-y-auto p-4 text-left undefined" dir="ltr">`sudo mkfs.ext4 /dev/ubuntu-vg/sdb-lv`</div></div>
6. **Mount the Logical Volume**: Create a mount point and mount the logical volume.
    
    <div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">bash <div class="flex items-center"><span class="" data-state="closed"><button class="flex gap-1 items-center"><svg class="icon-sm" fill="none" height="24" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path clip-rule="evenodd" d="M7 5a3 3 0 0 1 3-3h9a3 3 0 0 1 3 3v9a3 3 0 0 1-3 3h-2v2a3 3 0 0 1-3 3H5a3 3 0 0 1-3-3v-9a3 3 0 0 1 3-3h2zm2 2h5a3 3 0 0 1 3 3v5h2a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1h-9a1 1 0 0 0-1 1zM5 9a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1v-9a1 1 0 0 0-1-1z" fill="currentColor" fill-rule="evenodd"></path></svg>Copy code</button></span></div></div><div class="overflow-y-auto p-4 text-left undefined" dir="ltr">`sudo <span class="hljs-built_in">mkdir</span> /mnt/sdbsudo mount /dev/ubuntu-vg/sdb-lv /mnt/sdb`</div></div>Now your `sdb` disk should be mounted to `/mnt/sdb` as an LVM.

Remember to replace volume group and logical volume names (`ubuntu-vg` and `sdb-lv` respectively) with your actual ones. Also, ensure you understand the implications of these operations on your system before proceeding.

Resize

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

Eksekusi perubahan

```bash
resize2fs /dev/mapper/ubuntu–vg-ubuntu–lv
```