Thursday, August 8, 2013

HOWTO LVM

LVM stands for Logical Volume Manager.

With LVM, we can create Logical Partitions that can span across one or more Physical hard drives. The hard drives are divided into Physical Volumes (PV), then those Physical Volumes are combined together to create the Volume Group (VG) and finally the Logical Volumes (LV) are created from Volume Group to, at the end, be able to create your Filesystem.

Before proceed, we need install the lvm2 package, which mostly is not installed by default on a basic Debian distribution.

ximena@anneke:~$ sudo apt-get intall lvm2

To create a LVM, we need to run through the following steps:
  •     Select and create the Physical Partitions (PV)
  •     Create the Volume Group
  •     Create Logical Volumes

Select and Create the Physical Storage Devices

In this step, we need to choose the Physical Volumes that will be used to create the LV. We can create the physical volumes using pvcreate command, but before, we will check our current partitions:

ximena@anneke:~$ sudo fdisk -l

Disk /dev/sda: 600.1 GB, 600093712384 bytes
255 heads, 63 sectors/track, 72957 cylinders, total 1172058032 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes
Disk identifier: 0x000c8553

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *         512      292863      146176   83  Linux
/dev/sda2          292864    15918079     7812608   82  Linux swap / Solaris
/dev/sda3        15918080   211230719    97656320   83  Linux
/dev/sda4       211231230  1172057599   480413185    5  Extended
Partition 4 does not start on physical sector boundary.
/dev/sda5       211231232   406543359    97656064   83  Linux
/dev/sda6       406543872  1172057599   382756864   83  Linux

ximena@anneke:~$

Now I know that /dev/sda6 is the free space that will be used for my PV.

I can also check the structure of my HDD by running:

ximena@anneke:~$ sudo lsblk
NAME                           MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                              8:0    0 558.9G  0 disk
├─sda1                           8:1    0 142.8M  0 part /boot
├─sda2                           8:2    0   7.5G  0 part [SWAP]
├─sda3                           8:3    0  93.1G  0 part /
├─sda4                           8:4    0     1K  0 part
├─sda5                           8:5    0  93.1G  0 part /var
└─sda6                           8:6    0   365G  0 part
ximena@anneke:~$


Which give us a more "friendly" output.

Now, it's time to create our PV

ximena@anneke:~$ sudo pvcreate /dev/sda6
Physical volume "/dev/sda6" successfully created
ximena@anneke:~$


As shown above one PV (physical Volume) is created: /dev/sda6.

If the physical volumes is already created, you can view it using the pvscan and pvdisplay command:

ximena@anneke:~$ sudo pvscan
  PV /dev/sda6   VG lb01   lvm2 [365.02 GiB / 350.02 GiB free]
  Total: 1 [365.02 GiB] / in use: 0 [0] / in no VG: 1 [365.02 GiB]
ximena@anneke:~$


You can view the list of PVs with attributes like Size, Physical Extent Size, Total Physical Extent Size, the Free Space, etc., using pvdisplay command:

ximena@anneke:~$ sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda6
  VG Name               lb01
  PV Size               365.03 GiB / not usable 2.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              93446
  Free PE               89606
  Allocated PE          3840
  PV UUID               Q0e3tN-McgT-FBqI-2MAh-BZjr-Rvoj-57FuG9
  
ximena@anneke:~$


Note: PE stands for: Physical Extents, and they are nothing but equal-sized chunks. The default size of extent is 4MB.

Creating a Volume Group


Volume groups are a pool of storage that consists of one or more physical volumes. Once you create the PV, you can create the Volume Group (VG).

ximena@anneke:~$ sudo vgcreate vg01 /dev/sda6
  Volume  group "vg01" successfully created
ximena@anneke:~$


LVM processes the storage in terms of extents. We can also change the extent size (from the default size 4MB) using -s flag.

The following command lists the created VG:

ximena@anneke:~$ sudo vgdisplay
  --- Volume group ---
  VG Name               vg01
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               365.02 GiB
  PE Size               4.00 MiB
  Total PE              93446
  Alloc PE / Size       0 / 0 GiB
  Free  PE / Size       93446 / 365.02 GiB
  VG UUID               5HwOD6-cqKP-2xvm-B90G-2RMq-0mfv-Pl3G8d
  
ximena@anneke:~$


Creating Logical Volumes


Now, everything is ready to create the logical volumes from the volume groups. lvcreate command creates the logical volume with the size of 80MB.

ximena@anneke:~$ sudo lvcreate -L10G -n lv01 vg01
  Logical volume "lv01" created

ximena@anneke:~$


Using the command lvdisplay we can view the available logical volumes with its attributes:

ximena@anneke:~$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg01/lv01
  LV Name                lv01
  VG Name                vg01
  LV UUID                QAtkyi-HoMx-s1t1-NEYB-2r0S-IjY0-HmE1tV
  LV Write Access        read/write
  LV Creation host, time anneke, 2013-08-08 14:57:48 +0200
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0

ximena@anneke:~$


After that, we are able to create our Filesystem

ximena@anneke:~$ sudo mkfs.ext4 /dev/vg01/lv01
mke2fs 1.42.5 (29-Jul-2012)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=64 blocks, Stripe width=64 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done                           
Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

ximena@anneke:~$ 


Increasing the Size of the LVs


We can extend the size of the LVs by using lvextend utility. For examlpe:

ximena@anneke:~$ sudo lvextend -L15G /dev/vg01/lv01
  Extending logical volume lv01 to 15.00 GiB
  Logical volume lv01 successfully resized
ximena@anneke:~$


We can also add additional size to a specific LV as shown below.

ximena@anneke:~$ sudo lvextend -L+20G /dev/lb02/lv01
  Extending logical volume lv01 to 35.00 GiB
  Logical volume lv01 successfully resized
ximena@anneke:~$


Creating a Snapshot (Backup) LV


Sometimes to backup our own filesystems and/or LVs, we can use this great tool as Backup. It just simple as run this command:

ximena@anneke:~$ lvcreate -L5G -s -n lv01-SNAP vg01/lv01
  Logical volume "lv01-SNAP" created
ximena@anneke:~$


Where "-s" stands for "snapshot".

And now, our LVs will look like:

ximena@anneke:~$ lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg01/lv01
  LV Name                lv01
  VG Name                vg01
  LV UUID                QAtkyi-HoMx-s1t1-NEYB-2r0S-IjY0-HmE1tV
  LV Write Access        read/write
  LV Creation host, time anneke, 2013-08-08 14:57:48 +0200
  LV snapshot status     source of
                         lv01-SNAP [active]
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             8960
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0
  
  --- Logical volume ---
  LV Path                /dev/vg01/lv01-SNAP
  LV Name                lv01-SNAP
  VG Name                vg01
  LV UUID                i1LP4O-xEeB-3UNd-eQf3-OMKK-L9ug-C5cEj5
  LV Write Access        read/write
  LV Creation host, time anneke, 2013-08-08 15:18:15 +0200
  LV snapshot status     active destination for lv01
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             8960
  COW-table size         5.00 GiB
  COW-table LE           1280
  Allocated to snapshot  0.00%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:1

ximena@anneke:~$


Hope this helps!

HOWTO Fix: Possible missing firmware /lib/firmware/tigon/tg3 Tigon 3

Having new Hardware for your new cool HP ProLiant Gen8 server and Debian Wheezy installed on it, can bring errors like the following one, when you try to install a new package or just run an update on the system:

...
W: Possible missing firmware /lib/firmware/tigon/tg3_tso5.bin for module tg3
W: Possible missing firmware /lib/firmware/tigon/tg3_tso.bin for module tg3
W: Possible missing firmware /lib/firmware/tigon/tg3.bin for module tg3
...


To get the Hardware of the new system to work. This is what are we going to do:

1. First of all we need to add the non-free repository to your sources.list
ximena@anneke:~$ vi /etc/apt/sources.list

deb http://ftp.de.debian.org/debian/ wheezy main non-free
deb-src http://ftp.de.debian.org/debian/ wheezy main non-free

deb http://security.debian.org/ wheezy/updates main contrib non-free
deb-src http://security.debian.org/ wheezy/updates main contrib non-free

# wheezy-updates, previously known as 'volatile'
deb http://ftp.de.debian.org/debian/ wheezy-updates main contrib non-free
deb-src http://ftp.de.debian.org/debian/ wheezy-updates main contrib non-free


Save the file, and then don't forget to run:
ximena@anneke:~$ apt-get upgrade

2. Now we will install "apt-file" to find the missing firmaware for our distro:
ximena@anneke:~$ apt-get install apt-file
ximena@anneke:~$ apt-file update


3. Now we want to find out where those “Possible missing firmware” files are located:
ximena@anneke:~$ apt-file find /lib/firmware/tigon/tg3_tso.bin

The output should look like:
firmware-linux-nonfree: /lib/firmware/tigon/tg3_tso.bin

4. So we find out /lib/firmware/tigon/tg3_tso.bin is located in the firmware-linux-nonfree package. A little info about firmware-linux-nonfree:

ximena@anneke:~$ aptitude show firmware-linux-nonfree
Package: firmware-linux-nonfree       
State: installed
Automatically installed: no
Multi-Arch: foreign
Version: 0.36+wheezy.1
Priority: optional
Section: non-free/kernel
Maintainer: Debian Kernel Team <debian-kernel@lists.debian.org>
Architecture: all
Uncompressed Size: 1,564 k
Suggests: initramfs-tools, linux-image
Conflicts: firmware-linux (< 0.19)
Replaces: firmware-linux (< 0.19)
Description: Binary firmware for various drivers in the Linux kernel
 This package contains the binary firmware for  various drivers in the Linux kernel.  This is a collection of firmware
 blobs which are not individually large enough to warrant a standalone package.
 
 Contents:
 * 3Com Typhoon firmware, version 03.001.008 (3com/typhoon.bin)
 * AdvanSys ASC-3550 firmware (advansys/3550.bin)
 * AdvanSys ASC-38C0800 firmware (advansys/38C0800.bin)
 * AdvanSys ASC-38C1600 firmware (advansys/38C1600.bin)
 * AdvanSys SCSI controller microcode (advansys/mcode.bin)
 * Agere/Prism/Symbol Orinoco firmware (AP mode), version 9.48 Hermes I (agere_ap_fw.bin)
 * Agere/Prism/Symbol Orinoco firmware (STA mode), version 9.48 Hermes I (agere_sta_fw.bin)
 * Chelsio T3 optical EDC firmware (AEL2005 PHY) (cxgb3/ael2005_opt_edc.bin)
 * Chelsio T3 twinax EDC firmware (AEL2005 PHY) (cxgb3/ael2005_twx_edc.bin)
 * Chelsio T3 twinax EDC firmware (AEL2020 PHY) (cxgb3/ael2020_twx_edc.bin)
 * Chelsio T3B protocol engine firmware, version 1.1.0 (cxgb3/t3b_psram-1.1.0.bin)
 * Chelsio T3C protocol engine firmware, version 1.1.0 (cxgb3/t3c_psram-1.1.0.bin)
 * Chelsio T3 main firmware, version 7.4.0 (cxgb3/t3fw-7.4.0.bin)
 * Chelsio T3 main firmware, version 7.10.0 (cxgb3/t3fw-7.10.0.bin)
 * Chelsio T4 firmware, version 1.4.16.0 (cxgb4/t4fw-1.4.16.0.bin)
 * DAB-USB FPGA bitfile (dabusb/bitstream.bin)
 * DAB-USB firmware (dabusb/firmware.fw)
 * Xceive 5000 tuner firmware, version 1.6.114 (dvb-fe-xc5000-1.6.114.fw)
 * DiBcom dib0700 USB DVB bridge firmware, version 1.20 (dvb-usb-dib0700-1.20.fw)
 * Intel 82559 D101M microcode (e100/d101m_ucode.bin)
 * Intel 82559 D101S microcode (e100/d101s_ucode.bin)
 * Intel 82551-F and 82551-10 microcode (e100/d102e_ucode.bin)
 * ENE UB6250 MS Pro read/write firmware (ene-ub6250/msp_rdwr.bin)
 * ENE UB6250 MS init firmware (ene-ub6250/ms_init.bin)
 * ENE UB6250 MS read/write firmware (ene-ub6250/ms_rdwr.bin)
 * ENE UB6250 SD init stage 1 firmware (ene-ub6250/sd_init1.bin)
 * ENE UB6250 SD init stage 2 firmware (ene-ub6250/sd_init2.bin)
 * ENE UB6250 SD read/write firmware (ene-ub6250/sd_rdwr.bin)
 * kaweth/new_code.bin
 * kaweth/new_code_fix.bin
 * kaweth/trigger_code.bin
 * kaweth/trigger_code_fix.bin
 * Matrox G200 WARP engine microcode (matrox/g200_warp.fw)
 * Matrox G400/G550 WARP engine microcode (matrox/g400_warp.fw)
 * Multi-Tech USB CDMA modem firmware (mts_cdma.fw)
 * Multi-Tech USB EDGE modem firmware (mts_edge.fw)
 * Multi-Tech USB GPRS modem firmware (mts_gsm.fw)
 * Rage 128 CCE microcode (r128/r128_cce.bin)
 * Radeon HD IGP 7500/7600 series ME microcode (radeon/ARUBA_me.bin)
 * Radeon HD IGP 7500/7600 series PFP microcode (radeon/ARUBA_pfp.bin)
 * Radeon HD IGP 7500/7600 series RLC microcode (radeon/ARUBA_rlc.bin)
 * Radeon HD 6800 series MC microcode (radeon/BARTS_mc.bin)
 * Radeon HD 6800 series ME microcode (radeon/BARTS_me.bin)
 * Radeon HD 6800 series PFP microcode (radeon/BARTS_pfp.bin)
 * Radeon HD 6300/6500/6800 series RLC microcode (radeon/BTC_rlc.bin)
 * Radeon HD 6300 series MC microcode (radeon/CAICOS_mc.bin)
 * Radeon HD 6300 series ME microcode (radeon/CAICOS_me.bin)
 * Radeon HD 6300 series PFP microcode (radeon/CAICOS_pfp.bin)
 * Radeon HD 6900 series MC microcode (radeon/CAYMAN_mc.bin)
 * Radeon HD 6900 series ME microcode (radeon/CAYMAN_me.bin)
 * Radeon HD 6900 series PFP microcode (radeon/CAYMAN_pfp.bin)
 * Radeon HD 6900 series RLC microcode (radeon/CAYMAN_rlc.bin)
 * Radeon HD 5400 series ME microcode (radeon/CEDAR_me.bin)
 * Radeon HD 5400 series PFP microcode (radeon/CEDAR_pfp.bin)
 * Radeon HD 5400 series RLC microcode (radeon/CEDAR_rlc.bin)
 * Radeon HD 5800/5900 series ME microcode (radeon/CYPRESS_me.bin)
 * Radeon HD 5800/5900 series PFP microcode (radeon/CYPRESS_pfp.bin)
 * Radeon HD 5800/5900 series RLC microcode (radeon/CYPRESS_rlc.bin)
 * Radeon HD 5700 series ME microcode (radeon/JUNIPER_me.bin)
 * Radeon HD 5700 series PFP microcode (radeon/JUNIPER_pfp.bin)
 * Radeon HD 5700 series RLC microcode (radeon/JUNIPER_rlc.bin)
 * Radeon HD IGP 6200/6300/7300 series ME microcode (radeon/PALM_me.bin)
 * Radeon HD IGP 6200/6300/7300 series PFP microcode (radeon/PALM_pfp.bin)
 * Radeon HD 7800 series CE microcode (radeon/PITCAIRN_ce.bin)
 * Radeon HD 7800 series MC microcode (radeon/PITCAIRN_mc.bin)
 * Radeon HD 7800 series ME microcode (radeon/PITCAIRN_me.bin)
 * Radeon HD 7800 series PFP microcode (radeon/PITCAIRN_pfp.bin)
 * Radeon HD 7800 series RLC microcode (radeon/PITCAIRN_rlc.bin)
 * Radeon R100-family CP microcode (radeon/R100_cp.bin)
 * Radeon R200-family CP microcode (radeon/R200_cp.bin)
 * Radeon R300-family CP microcode (radeon/R300_cp.bin)
 * Radeon R400-family CP microcode (radeon/R420_cp.bin)
 * Radeon R500-family CP microcode (radeon/R520_cp.bin)
 * Radeon R600 ME microcode (radeon/R600_me.bin)
 * Radeon R600 PFP microcode (radeon/R600_pfp.bin)
 * Radeon R600-family RLC microcode (radeon/R600_rlc.bin)
 * Radeon R700-family RLC microcode (radeon/R700_rlc.bin)
 * Radeon HD 5500/5600 series ME microcode (radeon/REDWOOD_me.bin)
 * Radeon HD 5500/5600 series PFP microcode (radeon/REDWOOD_pfp.bin)
 * Radeon HD 5500/5600 series RLC microcode (radeon/REDWOOD_rlc.bin)
 * Radeon RS600 CP microcode (radeon/RS600_cp.bin)
 * Radeon RS690 CP microcode (radeon/RS690_cp.bin)
 * Radeon RS780 ME microcode (radeon/RS780_me.bin)
 * Radeon RS780 PFP microcode (radeon/RS780_pfp.bin)
 * Radeon RV610 ME microcode (radeon/RV610_me.bin)
 * Radeon RV610 PFP microcode (radeon/RV610_pfp.bin)
 * Radeon RV620 ME microcode (radeon/RV620_me.bin)
 * Radeon RV620 PFP microcode (radeon/RV620_pfp.bin)
 * Radeon RV630 ME microcode (radeon/RV630_me.bin)
 * Radeon RV630 PFP microcode (radeon/RV630_pfp.bin)
 * Radeon RV635 ME microcode (radeon/RV635_me.bin)
 * Radeon RV635 PFP microcode (radeon/RV635_pfp.bin)
 * Radeon RV670 ME microcode (radeon/RV670_me.bin)
 * Radeon RV670 PFP microcode (radeon/RV670_pfp.bin)
 * Radeon RV710 ME microcode (radeon/RV710_me.bin)
 * Radeon RV710 PFP microcode (radeon/RV710_pfp.bin)
 * Radeon RV730 ME microcode (radeon/RV730_me.bin)
 * Radeon RV730 PFP microcode (radeon/RV730_pfp.bin)
 * Radeon RV770 ME microcode (radeon/RV770_me.bin)
 * Radeon RV770 PFP microcode (radeon/RV770_pfp.bin)
 * Radeon HD IGP 6400/6500/6600 series ME microcode (radeon/SUMO_me.bin)
 * Radeon HD IGP 6400/6500/6600 series PFP microcode (radeon/SUMO_pfp.bin)
 * Radeon HD IGP 6200/6300/6400/6500/6600/7300 series RLC microcode (radeon/SUMO_rlc.bin)
 * Radeon HD 6370D/6380G/6410D ME microcode (radeon/SUMO2_me.bin)
 * Radeon HD 6370D/6380G/6410D PFP microcode (radeon/SUMO2_pfp.bin)
 * Radeon HD 7900 series CE microcode (radeon/TAHITI_ce.bin)
 * Radeon HD 7900 series MC microcode (radeon/TAHITI_mc.bin)
 * Radeon HD 7900 series ME microcode (radeon/TAHITI_me.bin)
 * Radeon HD 7900 series PFP microcode (radeon/TAHITI_pfp.bin)
 * Radeon HD 7900 series RLC microcode (radeon/TAHITI_rlc.bin)
 * Radeon HD 6500/6600/7500 series MC microcode (radeon/TURKS_mc.bin)
 * Radeon HD 6500/6600/7500 series ME microcode (radeon/TURKS_me.bin)
 * Radeon HD 6500/6600/7500 series PFP microcode (radeon/TURKS_pfp.bin)
 * Radeon HD 7700 series CE microcode (radeon/VERDE_ce.bin)
 * Radeon HD 7700 series MC microcode (radeon/VERDE_mc.bin)
 * Radeon HD 7700 series ME microcode (radeon/VERDE_me.bin)
 * Radeon HD 7700 series PFP microcode (radeon/VERDE_pfp.bin)
 * Radeon HD 7700 series RLC microcode (radeon/VERDE_rlc.bin)
 * Tehuti network card firmware (tehuti/bdx.bin)
 * Broadcom BCM5703/BCM5704 TSO firmware (tigon/tg3_tso.bin)
 * Broadcom BCM5701A0 firmware (tigon/tg3.bin)
 * Broadcom BCM5705 TSO firmware (tigon/tg3_tso5.bin)
 * VIA VT6656 firmware (vntwusb.fw)
Homepage: http://git.kernel.org/?p=linux/kernel/git/firmware/linux-firmware.git

ximena@anneke:~$



5. Now, we will install our missing firmware:
ximena@anneke:~$ apt-get install firmware-linux-nonfree


At the end of the process, check dmesg or /var/log/messages to check if everything is in order after the installation of the new firmware.