How to add a disk in Nethserver with LVM

#How to add a disk in Nethserver with LVM

We will see how to add a hard drive in an existing Virtual Group.

Version and revision: V1.0 / R3

Skill: General audience.

Published: 2015-09-08
Review: 2015-11-12

Author: Jim
Contact: Nethserver community forum: Jim

At first, I`m strongly recommending to read this LVM Administrator’s Guide:
https://www.centos.org/docs/5/html/Cluster_Logical_Volume_Manager/

There’s all you need to understand what is LVM and how to play safely with it.

In my Microserver Gen8 I have one 160 GB disk in the bay one. This one was configuring like this: ( disk -l output )

    Disque /dev/sda: 160.0 Go, 160041885696 octets
    255 têtes, 63 secteurs/piste, 19457 cylindres
    Unités = cylindres de 16065 * 512 = 8225280 octets
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Identifiant de disque : 0x0002bf10
    
    Périphérique Amorce  Début        Fin      Blocs     Id  Système
    /dev/sda1   *           1          64      512000   83  Linux
    La partition 1 ne se termine pas sur une frontière de cylindre.
    /dev/sda2              64       19458   155777024   8e  Linux LVM
    
    Disque /dev/mapper/vg_microserver-lv_root: 53.7 Go, 53687091200 octets
    255 têtes, 63 secteurs/piste, 6527 cylindres
    Unités = cylindres de 16065 * 512 = 8225280 octets
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Identifiant de disque : 0x00000000
    
    Disque /dev/mapper/vg_microserver-lv_home: 101.8 Go, 101833506816 octets
255 têtes, 63 secteurs/piste, 12380 cylindres
Unités = cylindres de 16065 * 512 = 8225280 octets
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Identifiant de disque : 0x00000000

    Disque /dev/mapper/vg_microserver-lv_swap: 3992 Mo, 3992977408 octets
    255 têtes, 63 secteurs/piste, 485 cylindres
    Unités = cylindres de 16065 * 512 = 8225280 octets
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Identifiant de disque : 0x00000000

When I went to put one more 1Tb disk in the second bay, I didn`t want to simply add one
partition, but wanted to expend the LVM volume to have flexibility of LVM for futures upgrades.

So when I plugged the 1TB drive, I went to connect in SSH to the server and became root.
did a fdisk -l to ensure the this was well seeing, with the output, I saw a /dev/sdb drive.

So I had create the physical volume:

pvcreate /dev/sdb

When done

pvdisplay

To extend the VolumeGroup, I needed the name of this one, so:

vgdisplay

In this case the VG name is vg_microserver.
So, to extend the actual volume group

vgextend vg_microserver /dev/sdb

To be able to use the new disk space in the volume group, I needed to create a new logical volume in the volume group.
In my case, I want to use all the free space, and the logical volume need a name, it will be tmbackup

lvcreate -l 100%FREE -n tmbackup vg_microserver

here the output of the lvdisplay command

 --- Logical volume ---
  LV Path                /dev/vg_microserver/lv_root
  LV Name                lv_root
  VG Name                vg_microserver
  LV UUID                uw6t0l-RpXQ-dHzo-LmNY-wHBY-NpTE-qA6UT7
  LV Write Access        read/write
  LV Creation host, time nethserver, 2015-07-26 20:21:10 -0300
  LV Status              available
  # open                 1
  LV Size                50,00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/vg_microserver/lv_home
  LV Name                lv_home
  VG Name                vg_microserver
  LV UUID                QBk1ca-fD7E-DbaG-Yk2O-WD15-2biU-dKfjww
  LV Write Access        read/write
  LV Creation host, time nethserver, 2015-07-26 20:21:30 -0300
  LV Status              available
  # open                 1
  LV Size                94,84 GiB
  Current LE             24279
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/vg_microserver/lv_swap
  LV Name                lv_swap
  VG Name                vg_microserver
  LV UUID                7tAuVa-zzpY-gBnr-nc95-P35Y-gg2f-kSkMfn
  LV Write Access        read/write
  LV Creation host, time nethserver, 2015-07-26 20:22:16 -0300
  LV Status              available
  # open                 1
  LV Size                3,72 GiB
  Current LE             952
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/vg_microserver/lv_tmbackup
  LV Name                lv_tmbackup
  VG Name                vg_microserver
  LV UUID                lyioV1-8q8e-sTDz-mxpv-tBrD-M5Eb-h8WKRR
  LV Write Access        read/write
  LV Creation host, time nethserver, 2015-08-04 21:07:20 -0300
  LV Status              available
  # open                 1
  LV Size                931,51 GiB
  Current LE             238467
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3

When all was done, i need to create the ext4 partition in this new volume:

mkfs.ext4 /dev/vg_microserver/lv_tmbackup

Finally, I mounted the partition in /home/tmbackup

mount -t ext4 /dev/mapper/vg_microserver-lv_tmbackup /home/tmbackup

I adjusted the /etc/fstab to automatically mount the partition at startup

 /dev/mapper/vg_microserver-lv_root      /       ext4    defaults        1 1
UUID=6409d507-3801-4089-b451-4d671026c268       /boot   ext4    defaults        1 2
/dev/mapper/vg_microserver-lv_home      /home   ext4    defaults        1 2
/dev/mapper/vg_microserver-lv_swap      swap    swap    defaults        0 0
/dev/mapper/vg_microserver-lv_tmbackup  /home/tmbackup  ext4  defaults   1 2
tmpfs   /dev/shm        tmpfs   defaults        0 0
devpts  /dev/pts        devpts  gid=5,mode=620  0 0
sysfs   /sys    sysfs   defaults        0 0
proc    /proc   proc    defaults        0 0

That’s all ! :grinning:

5 Likes

Nice write up. Did you run the command to update the e-smith db after modifying fstab? I came across a situation that a manually added fstab entry was not kept after a reboot. Luckily it did not have anything to do with the boot or system partition. There is a page in the development manual that states you need to run the fstab-update event. Here’s a snippet from the manual.

"NethServer add a special fstab key inside the configuration e-smith db. Each prop of fstab is in the form mountpoint=options.

For example:

fstab=configuration
/=defaults,acl
/boot=defaults

The entries are not mandatory, if a filesystem hasn’t an associated property, no modification will be done.

After each modification to fstab properties, the fstab-update event must be fired. The fstab-update event will expand the /etc/fstab file and then remount all filesystems except for types: swap proc sysfs devpts."

I remember read such thing. but…I reboot.
Why? Because I want to see if the installation is ok…I mean definitive.

Thank you for reading and give your feedback. I will enhence this howto :wink: