1

we have linux machine with sdb disk

 lsblk
NAME             MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
fd0                2:0    1     4K  0 disk
sda                8:0    0   150G  0 disk
├─sda1             8:1    0   500M  0 part /boot
└─sda2             8:2    0 149.5G  0 part
  ├─lp55-lv_root 253:0    0    40G  0 lvm  /
  ├─lp55-lv_swap 253:1    0   7.7G  0 lvm  [SWAP]
  └─lp55-lv_var  253:2    0 100.9G  0 lvm  /var
sdb                8:16   0   100G  0 disk

for now sdb isnt LVM

we want to create the sdb to LVM with new VG group as new1 so we can increase the sdb as we want later

what is the procedure to convert sdb to LVM

# pvs
# lvdisplay
  No volume groups found
# pvdisplay
# vgdisplay
  No volume groups found
#

rpm -qa | grep -i lvm
lvm2-2.02.100-8.el6.x86_64
lvm2-libs-2.02.100-8.el6.x86_64
  • Do you need to save any data on sdb or can it be wiped? – Stephen Harris Nov 4 '18 at 15:17
  • wiped - like a new disk – yael Nov 4 '18 at 15:20
3

You could partition the /dev/sdb to make it recognizable to other operating systems that the disk is in use, but that will make extending the disk more complicated in the future, and since it's a VMDK its name on the virtualization host should make its purpose obvious anyway. So I'd recommend omitting the partitioning in this case, and just using the whole virtual disk for the LVM. So:

pvcreate /dev/sdb

Then you could just extend your existing VG with the new PV (with vgextend lp55 /dev/sdb), but as you said you want to create a new VG, so:

vgcreate new1 /dev/sdb

At this point, the new VG is created but has no LVs allocated. If you want to use all the available capacity into a single LV/filesystem, then you could do this:

lvcreate -n lv_name -l 100%FREE new1

If you want to create a LV of some specific size, you can use -L nnnG to specify the size in GiB instead of -l 100%FREE.

(You probably should replace lv_name with something that describes the intended use of the LV.)

After the LV is created, you are free to use it as you wish. You may put a filesystem (of whatever type) onto it and mount it, or use it as a raw storage for a database engine, or whatever you want to do with it.

For example, to create an ext4 filesystem on it:

mkfs.ext4 /dev/new1/lv_name

Then, create a mountpoint wherever is appropriate to you:

mkdir /some/where

Create an entry in /etc/fstab:

/dev/new1/lv_name /some/where ext4 defaults 0 2

And mount it:

mount /some/where

and you're done.

  • what about ext4 filesystem – yael Nov 4 '18 at 15:29
  • can we use - mkfs.xfs /dev/new1/lv_name ( insted mkfs.ext4 ) ? – yael Nov 4 '18 at 16:40
  • Sure, but that will result in an XFS filesystem, rather than ext4. If you specifically need an ext4 filesystem, then you must use mkfs.ext4. On RHEL/CentOS 7.x, XFS is the default filesystem type, but RHEL/CentOS 6.x and older used ext4 as the default. In RHEL 6.x, I think XFS support used to be restricted somehow and full support required an add-on support subscription. – telcoM Nov 5 '18 at 7:44
1

Since you don't need to save any data you can following the standard process:

pvcreate /dev/sdb
vgcreate new1 /dev/sdb

And now you can lvcreate volumes on that VG

lvcreate -L10G -n testvol1 new1

If you increase the size of sdb afterwards, you can use the pvresize to make the new space available.

  • what about ext4 filesystem – yael Nov 4 '18 at 15:29
  • Once you've created the LV, you can mke2fs on it, same as any other partition or volume (eg mke2fs -t ext4 /dev/new1/testvol1) – Stephen Harris Nov 4 '18 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.