3

I am new to LVM and VM yet, and I need to be able to access sdb like /mybackup/ 1 - should I have sdb1 created then mount? 2 - should I mount sdb as whole disk without LVM? 3 - create lvm and than mount?

what is the best way?

so far here what I have:

[root@localhost /]# lsblk
NAME                        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0                          11:0    1 1024M  0 rom  
sda                           8:0    0   60G  0 disk 
├─sda1                        8:1    0  500M  0 part /boot
└─sda2                        8:2    0 59.5G  0 part 
  ├─VolGroup-lv_root (dm-0) 253:0    0 48.8G  0 lvm  /
  ├─VolGroup-lv_swap (dm-1) 253:1    0    6G  0 lvm  [SWAP]
  └─VolGroup-lv_home (dm-2) 253:2    0  4.8G  0 lvm  /home
sdb                           8:16   0  320G  0 disk 
[root@localhost /]# 

[root@localhost /]# pvscan
  PV /dev/sda2   VG VolGroup   lvm2 [59.51 GiB / 0    free]
  Total: 1 [59.51 GiB] / in use: 1 [59.51 GiB] / in no VG: 0 [0   ]

[root@localhost /]# pvscan
  PV /dev/sda2   VG VolGroup   lvm2 [59.51 GiB / 0    free]
  Total: 1 [59.51 GiB] / in use: 1 [59.51 GiB] / in no VG: 0 [0   ]

[root@localhost /]# lvscan
  ACTIVE            '/dev/VolGroup/lv_root' [48.75 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_home' [4.76 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_swap' [6.00 GiB] inherit


[root@localhost /]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0000e17a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        7833    62401536   8e  Linux LVM

Disk /dev/sdb: 343.6 GB, 343597383680 bytes
255 heads, 63 sectors/track, 41773 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00025293

   Device Boot      Start         End      Blocks   Id  System

Disk /dev/mapper/VolGroup-lv_root: 52.3 GB, 52344913920 bytes
255 heads, 63 sectors/track, 6363 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/VolGroup-lv_swap: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/VolGroup-lv_home: 5108 MB, 5108662272 bytes
255 heads, 63 sectors/track, 621 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


[root@localhost /]# cat /proc/partitions 
major minor  #blocks  name

   8        0   62914560 sda
   8        1     512000 sda1
   8        2   62401536 sda2
   8       16  335544320 sdb
 253        0   51118080 dm-0
 253        1    6291456 dm-1
 253        2    4988928 dm-2
[root@localhost /]# 

1
  • It's unclear what you're asking. Do you want to use /dev/sdb as an extra physical device for LVM, or do you just want to use it as a file system for backups?
    – wurtel
    Mar 11, 2015 at 10:03

3 Answers 3

2

I think that what you're asking for is to know if you need to create a logical volume in order to use the device /dev/sdb. If that's the question, no, you don't need to use LVM at all. You can directly create a file system on /dev/sdb and then mount it in your desired directory. Basically:

mkdir /mybackup
mkfs.ext4 /dev/sdb
echo "/dev/sdb /mybackup ext4 defaults 0 0" >> /etc/fstab
mount -a

If you want to use LVM anyway, you can create a new physical volume, then add it to the volume group present in your system (VolGroup), create a logical volume and then use it the same way explained above:

pvcreate /dev/sdb  # Tags /dev/sdb as a physical volume
vgextend VolGroup /dev/sdb  # Extends volume group VolGroup with the new PV
lvcreate -l 100%FREE VolGroup -n lv_mybackup   # Creates a new LV from VolGroup
mkdir /mybackup
mkfs.ext4 /dev/VolGroup/lv_mybackup
echo "/dev/VolGroup/lv_mybackup /mybackup ext4 defaults 0 0" >> /etc/fstab"
mount -a

The first approach is the easy one, and the second one gives you the advantages of LVM.

1

If your question is "should I bother figuring out this LMV stuff? It is weird." The answer is yes! I am fairly new, but the one thing I really love about LVM is that it is much easier to make changes when you need more space. It is more complicated than that, so read up here (and other places):

What is LVM and what is it used for?

If you want to know if you should create a partition on the block device or not before doing the LVM steps, I can tell you that it works fine without, but... The 'greybeard' here at work noticed me doing that and started giving my crap about it. He said that it is the "preferred method" to create a partition on the block device first. So I can tell you that Daniel Sanchez's solution should work (and even looks elegant to me), but I think that the documented 'right way' is more like:

fdisk /dev/sdb  
# make a new partition with all defaults
# change the partition type to '8e'
# save your changes and exit fdisk
pvcreate /dev/sdb1  # Tags /dev/sdb1 as a physical volume
vgextend VolGroup /dev/sdb1  # Extends volume group VolGroup with the new PV
lvcreate -l 100%FREE VolGroup -n lv_mybackup   # Creates a new LV from VolGroup
mkdir /mybackup
mkfs.ext4 /dev/VolGroup/lv_mybackup
echo "/dev/VolGroup/lv_mybackup /mybackup ext4 defaults 0 0" >> /etc/fstab"
mount -a

You can read up on this stuff until your eyes bleed, but this page is a place to start:

A Beginner's Guide To LVM

2
  • 1
    The advantage of this procedure is that if the disk is accidentally presented to a Windows system, it will see the disk is in use and won't offer a single-click option to format it. The disadvantage is that if the capacity of the disk is increased (e.g. if it's a SAN LUN or a virtual disk of some virtualization platform), taking advantage of the increased capacity will be more complicated.
    – telcoM
    Mar 29, 2018 at 7:35
  • 1
    Also, if data alignment is an issue, you may need to make sure fdisk is not using the ancient DOS-compatible scheme to set the start of partition at the start of a disk cylinder, and instead place the start of the partition to proper alignment, e.g. exactly 1Mbyte from the start of the disk (block #2048 if regular 512-byte disk blocks are used). For e.g. RHEL 6.x, you'll want to use fdisk -uc /dev/sdb and then use the defaults. Different OS versions will need different options for fdisk for proper alignment.
    – telcoM
    Mar 29, 2018 at 7:40
0

You must create /dev/sdb1 and change the type of partition to 8e in order to use it as LVM. See the below example, without changing the partition type it will not show type as LVM partition:

Without:

[root@node01 example]# fdisk -l
Disk /dev/sdb: 375.8 GB, 375809638400 bytes, 734003200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/sda: 136.4 GB, 136365211648 bytes, 266338304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x000bffe2
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   266338303   132119552   8e  Linux LVM

With type as "8e"

[root@node01 example]# fdisk -l
Disk /dev/sdb: 375.8 GB, 375809638400 bytes, 734003200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x3248e605
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   734003199   367000576   8e  Linux LVM
Disk /dev/sda: 136.4 GB, 136365211648 bytes, 266338304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x000bffe2
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   266338303   132119552   8e  Linux LVM

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.