User Tools

Site Tools


linux:logical-volume-management-in-linux

Logical Volume Management in Linux

date: 2016-09-28 14:23:22-04:00

Here are some notes on basic logical volume management in Linux (Fedora 23). The task is to create a partition for /var and move the current contents of /var to its own LV. Specifically:

  1. initialize a partition using GNU Parted: /sbin/parted
  2. create a physical volume: /sbin/pvcreate
  3. assign the physical volume to a volume group: /sbin/vgextend
  4. create a logical volume: /sbin/lvcreate
  5. create a btrfs file system for the new logical volume: mkfs.btrfs

Of course, this process assumes there is some space to create this new partition.

First, let's log in as root:

$ su root

And then start GNU Parted and proceed through the steps:

% parted /dev/sda
(parted) print
(parted) mkpart
(parted) Partion type? primary/extended? primary
(parted) File system type? [ext2]? ext4
(parted) Start? 81.1GB
(parted) End? 100%
(parted) set 3 lvm on
(parted) print
(parted) quit

Next create a physical volume:

% pvdisplay
% pvcreate /dev/sda3
% pvdisplay

Then assign a physical volume to our volume group:

% vgdisplay
% vgextend fedora /dev/sda3
% vgdisplay

Create a logical volume:

% lvdisplay
% lvcreate -l 6285 --name var fedora
% lvdisplay /dev/fedora/var

Finally, create a file system for the LV:

% mkfs.btrfs /dev/fedora/var
% cd /
% mkdir /new_var
% mount /dev/fedora/var /new_var/
% cp -vrp /var/* /new_var/
% mv /var/ /old_var
% mkdir /var
% mount --bind /new_var/ /var/
% restorecon -R /var/
% vi /etc/fstab

And, using Vim, Nano, or a text editor of choice, add the following entry to /etc/fstab:

/dev/mapper/fedora-var    /var   btrfs   defaults  1   2

Reboot to take effect:

% systemctl reboot
linux/logical-volume-management-in-linux.txt · Last modified: 2018/02/28 11:03 by seanburns