[ About | Licence | Contacts ]
Written by Oleksandr Gavenko (AKA gavenkoa), compiled on 2017-01-30 from rev ccaa2f364422+.

LVM

Debian package

$ sudo apt-get install lvm

List partitions

$ sudo sfdisk -l

or use gparted(1).

Setup physical volume

$ sudo pvcreate /dev/sdc3
Physical volume "/dev/sdc3" successfully created

Setup volume group

$ sudo vgcreate vg0 /dev/sdc3
Volume group "vg0" successfully created

Show info about volume group

$ sudo vgdisplay
--- Volume group ---
VG Name               vg0
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               77.22 GB
PE Size               4.00 MB
Total PE              19769
Alloc PE / Size       0 / 0
Free  PE / Size       19769 / 77.22 GB
VG UUID               ZOQvrP-PnJ2-kKsH-7aLU-eOa3-K5M2-sRstJH

Create logical volume

$ sudo lvcreate -L 10G -n home vg0
Logical volume "home" created

Show info about logical volume

$ sudo lvdisplay
--- Logical volume ---
LV Name                /dev/vg0/home
VG Name                vg0
LV UUID                XWJFnF-LjQg-Xsvm-IeQI-68mX-jiYd-pSpA00
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                20.00 GB
Current LE             5120
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           254:0

--- Logical volume ---
LV Name                /dev/vg0/swap
VG Name                vg0
LV UUID                BHBQd0-1RlO-hHn7-jAij-Gyg6-KnqE-lRBgPY
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                1.00 GB
Current LE             256
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           254:1

Create fs on logical volume

$  sudo mke2fs -j /dev/vg0/home
mke2fs 1.40-WIP (14-Nov-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1310720 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
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

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

Remove logical volume

$ sudo lvremove  /dev/vg0/home

Move home dir to lvm

$ su
...
$ mv /home /home2
$ lvcreate -L 10G -n home vg0
$ mke2fs -j /dev/vg0/home
$ emacs /etc/fstab
...
$ cat /etc/fstab
...
/dev/vg0/home   /home  ext3  defaults  0  2
...
$ mount -a
$ (cd /home2; tar -cf - .) | (cd /home; tar -xpf -)
$ rm -r /home2

Creating swap on lvm

$ su
...
$ lvcreate -L 1G -n swap vg0
$ mkswap -v1 /dev/vg0/swap
$ emacs /etc/fstab
...
$ cat /etc/fstab
...
/dev/vg0/swap   swap  swap  defaults  0  0
...
$ swapon -a