Print this Page

Home Server setup LVM

Index

14-Jun-2011: initial release.
28-Dec-2011: added nodev and noexec mount options.

 

Install LVM.

In this example we have about 620 GB space in our Logical Volume Management partition. You need to make a plan how to use it. Let’s make four logical volumes:

  1. vg00-vserver, 40 GB for virtual servers.
  2. vg00-home, 80 GB for users home directories.
  3. vg00-users, 80 GB for users common directories.
  4. vg00-media, 100 GB for multimedia storage.

Because we don’t know how these partition will fill in the future, we will start with these amounts of space. Later, if a partition fills too much, you can grow that logical volume by adding unused space and grow the filesystem in that volume to make more space available for the users.

[root@myhost ~]# modprobe dm-mod
[root@myhost ~]# pvcreate /dev/md2
 Physical volume "/dev/md2" successfully created
[root@myhost ~]# vgcreate vg00 /dev/md2
 Volume group "vg00" successfully created
[root@myhost ~]# lvcreate -L 40G -n vserver vg00
 Logical volume "vserver" created
[root@myhost ~]# lvcreate -L 80G -n users vg00
 Logical volume "users" created
[root@myhost ~]# lvcreate -L 80G -n home vg00
 Logical volume "home" created
[root@myhost ~]# lvcreate -L 100G -n media vg00
 Logical volume "media" created
[root@myhost ~]# vgdisplay vg00
 --- Volume group ---
 VG Name               vg00
 System ID
 Format                lvm2
 Metadata Areas        1
 Metadata Sequence No  5
 VG Access             read/write
 VG Status             resizable
 MAX LV                0
 Cur LV                4
 Open LV               0
 Max PV                0
 Cur PV                1
 Act PV                1
 VG Size               618.13 GiB
 PE Size               4.00 MiB
 Total PE              158241
 Alloc PE / Size       76800 / 300.00 GiB
 Free  PE / Size       81441 / 318.13 GiB
 VG UUID               Bv0b3l-RPF9-7M3r-d5Ah-WjsU-wisZ-0J18xP

[root@myhost ~]#

Now we can create the filesystems and mountpoints:

[root@myhost ~]# mke2fs -j -L VSERVER /dev/vg00/vserver
mke2fs 1.41.14 (22-Dec-2010)
Filesystem label=VSERVER
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2621440 inodes, 10485760 blocks
524288 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
320 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, 2654208,
 4096000, 7962624

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

This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@myhost ~]# mke2fs -j -L HOME /dev/vg00/home
mke2fs 1.41.14 (22-Dec-2010)
Filesystem label=HOME
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
5242880 inodes, 20971520 blocks
1048576 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
640 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, 2654208,
 4096000, 7962624, 11239424, 20480000

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

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@myhost ~]# mke2fs -j -L USERS /dev/vg00/users
mke2fs 1.41.14 (22-Dec-2010)
Filesystem label=USERS
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
5242880 inodes, 20971520 blocks
1048576 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
640 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, 2654208,
 4096000, 7962624, 11239424, 20480000

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

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@myhost ~]# mke2fs -j -L MEDIA /dev/vg00/media
mke2fs 1.41.14 (22-Dec-2010)
Filesystem label=MEDIA
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
800 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, 2654208,
 4096000, 7962624, 11239424, 20480000, 23887872

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

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@myhost ~]# mkdir -p /mnt/{vserver,users,media}
[root@myhost ~]#

Now, edit /etc/fstab so that it looks like this:

#
# /etc/fstab: static file system information
#
#<file system> <dir>          <type>  <options>                   <dump> <pass>
devpts         /dev/pts       devpts  defaults                        0   0
shm            /dev/shm       tmpfs   nodev,nosuid                    0   0

LABEL=ROOT     /              ext3    defaults,acl,noatime            0   1
/dev/sda3      swap           swap    defaults                        0   0
/dev/sdb3      swap           swap    defaults                        0   0

/dev/vg00/home    /home        ext3 defaults,nodev,acl,user_xattr,noatime 1 2
/dev/vg00/users   /mnt/users   ext3 defaults,nodev,acl,user_xattr,noatime 1 2
/dev/vg00/media   /mnt/media   ext3 defaults,nodev,noexec,acl,user_xattr,noatime 1 2
/dev/vg00/vserver /mnt/vserver ext3 defaults,nodev,noexec,acl,user_xattr,noatime 1 2

Then you can mount everything and check it.

[root@myhost ~]# mount -a
[root@myhost ~]# df -T
Filesystem               Type     1K-blocks   Used Available Use% Mounted on
udev                     devtmpfs     10240      4     10236   1% /dev
run                      tmpfs        10240    160     10080   2% /run
/dev/md0                 ext3      10284920 690608   9071856   8% /
shm                      tmpfs       126304      0    126304   0% /dev/shm
/dev/mapper/vg00-home    ext3      82569904 188292  78187308   1% /home
/dev/mapper/vg00-users   ext3      82569904 188292  78187308   1% /mnt/users
/dev/mapper/vg00-media   ext3     103212320 192248  97777192   1% /mnt/media
/dev/mapper/vg00-vserver ext3      41284928 180236  39007540   1% /mnt/vserver
[root@myhost ~]#

The extra acl and user_xattr mount options are useful for servers like Samba and Dovecot, and they are absolutely necessary for the future Samba-4 servers. The extra nodev and noexec options on some file systems  are used to give some extra system security by preventing to create device files on that file system or to prevent to execute binaries.

Edit /etc/rc.conf and set USELVM=”yes”. Finally edit /etc/mkinitcpio.conf and change the MODULES and HOOKS lines like this:

MODULES="raid1 dm-mod"
HOOKS="base udev autodetect pata scsi sata mdadm lvm2 filesystems"

To make sure that it works after a reboot, you must run mkinitcpio like this:

[root@myhost etc]# mkinitcpio -p kernel26
==> Building image "default"
==> Running command: /sbin/mkinitcpio -k 2.6.38-ARCH -c /etc/mkinitcpio.conf \
    -g /boot/kernel26.img
:: Begin build
:: Parsing hook [base]
:: Parsing hook [udev]
:: Parsing hook [autodetect]
:: Parsing hook [pata]
:: Parsing hook [scsi]
:: Parsing hook [sata]
:: Parsing hook [mdadm]
Custom /etc/mdadm.conf file will be used in initramfs for assembling arrays.
:: Parsing hook [lvm2]
:: Parsing hook [filesystems]
:: Generating module dependencies
:: Generating image '/boot/kernel26.img'...SUCCESS
==> SUCCESS
==> Building image "fallback"
==> Running command: /sbin/mkinitcpio -k 2.6.38-ARCH -c /etc/mkinitcpio.conf \
    -g /boot/kernel26-fallback.img -S autodetect
:: Begin build
:: Parsing hook [base]
:: Parsing hook [udev]
:: Parsing hook [pata]
:: Parsing hook [scsi]
:: Parsing hook [sata]
:: Parsing hook [mdadm]
Custom /etc/mdadm.conf file will be used in initramfs for assembling arrays.
:: Parsing hook [lvm2]
:: Parsing hook [filesystems]
:: Generating module dependencies
:: Generating image '/boot/kernel26-fallback.img'...SUCCESS
==> SUCCESS
[root@myhost etc]#

That’s it, check if it works.

 

Grow a LVM partition.

The following commands demonstrate how to grow a filesystem on a running system:

[root@myhost etc]# df /home
Filesystem            1K-blocks   Used Available Use% Mounted on
/dev/mapper/vg00-home  82569904 188292  78187308   1% /home
[root@myhost etc]# lvextend -L +40G --resizefs /dev/vg00/home
Extending logical volume home to 120.00 GiB
Logical volume home successfully resized
resize2fs 1.41.14 (22-Dec-2010)
Filesystem at /dev/mapper/vg00-home is mounted on /home; on-line resizing required
old desc_blocks = 5, new_desc_blocks = 8
Performing an on-line resize of /dev/mapper/vg00-home to 31457280 (4k) blocks.
The filesystem on /dev/mapper/vg00-home is now 31457280 blocks long.

[root@myhost etc]# df /home
Filesystem            1K-blocks   Used Available Use% Mounted on
/dev/mapper/vg00-home 123854820 192188 117371688   1% /home
[root@myhost etc]#

Permanent link to this article: http://www.mbse.eu/linux/homeserver/baseinstall/lvm/