Home Server setup LVM

Index

14-Jun-2011: initial release.
28-Dec-2011: added nodev and noexec mount options.
25-Jul-2012: updated for the 2012 installer.
28-Jul-2012: fixed /etc/fstab
02-Jan-2013: Adjusted for Slackware.

 

Install LVM.

In this example we have about 610 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@homsrv:~# modprobe dm-mod
root@homsrv:~# pvcreate /dev/md3
 Physical volume "/dev/md3" successfully created
root@homsrv:~# vgcreate vg00 /dev/md3
 Volume group "vg00" successfully created
root@homsrv:~# lvcreate -L 40G -n vserver vg00
 Logical volume "vserver" created
root@homsrv:~# lvcreate -L 80G -n users vg00
 Logical volume "users" created
root@homsrv:~# lvcreate -L 80G -n home vg00
 Logical volume "home" created
root@homsrv:~# lvcreate -L 100G -n media vg00
 Logical volume "media" created
root@homsrv:~# 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               609.89 GiB
 PE Size               4.00 MiB
 Total PE              156127
 Alloc PE / Size       76800 / 300.00 GiB
 Free  PE / Size       79327 / 309.87 GiB
 VG UUID               Bv0b3l-RPF9-7M3r-d5Ah-WjsU-wisZ-0J18xP

root@homsrv:~#

 

Now we can create the filesystems and mountpoints:

root@homsrv:~# mkfs.ext4 -L VSERVER /dev/vg00/vserver
mke2fs 1.42.4 (12-June-2012)
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

root@homsrv:~# mkfs.ext4 -L HOME /dev/vg00/home
mke2fs 1.42.4 (12-June-2012)
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

root@homsrv:~# mkfs.ext4 -L USERS /dev/vg00/users
mke2fs 1.42.4 (12-June-2012)
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

root@homsrv:~# mkfs.ext4 -L MEDIA /dev/vg00/media
mke2fs 1.42.4 (12-June-2012)
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: done

root@homsrv:~# mkdir -p /mnt/{vserver,users,media}
root@homsrv:~#

 

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

#
# /etc/fstab: static file system information
#
#<file system> <dir>          <type>  <options>                   <dump> <pass>
tmpfs         /tmp         tmpfs nodev,nosuid                          0 0

LABEL=ROOT    /            ext4  defaults,acl,noatime                  0 1
LABEL=SwapA   swap         swap  defaults                              0 0
LABEL=SwapB   swap         swap  defaults                              0 0

LABEL=HOME    /home        ext4  defaults,nodev,acl,user_xattr,noatime 1 2
LABEL=USERS   /mnt/users   ext4  defaults,nodev,acl,user_xattr,noatime 1 2
LABEL=MEDIA   /mnt/media   ext4  defaults,nodev,noexec,acl,user_xattr,noatime 1 2
LABEL=VSERVER /mnt/vserver ext4  defaults,nodev,noexec,acl,user_xattr,noatime 1 2

 

Then you can mount everything and check it.

root@homsrv:~# mount -a
root@homsrv:~# df -T
Filesystem               Type     1K-blocks    Used Available Use% Mounted on
rootfs                   rootfs    26126060 1121068  23695100   5% /
dev                      devtmpfs    253692       0    253692   0% /dev
run                      tmpfs       255972     232    255740   1% /run
/dev/md1                 ext4      26126060 1121068  23695100   5% /
shm                      tmpfs       255972       0    255972   0% /dev/shm
tmpfs                    tmpfs       255972       0    255972   0% /tmp
/dev/mapper/vg00-users   ext4      83746440 1364696  78187440   2% /mnt/users
/dev/mapper/vg00-media   ext4     104693300 1673096  97777324   2% /mnt/media
/dev/mapper/vg00-vserver ext4      41852720  747896  39007672   2% /mnt/vserver
/dev/mapper/vg00-home    ext4      83746440 1364696  78187440   2% /home
root@homsrv:~#

 

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. That’s it, check if it works after a reboot.

 

Grow a LVM partition.

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

root@homsrv:/etc# df /home
Filesystem            1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg00-home  83746440 1364696  78187440   2% /home
root@homsrv:/etc# lvextend -L +40G --resizefs /dev/vg00/home
  Extending logical volume home to 120.00 GiB
  Logical volume home successfully resized
resize2fs 1.42.4 (12-June-2012)
Filesystem at /dev/mapper/vg00-home is mounted on /home; on-line resizing requir
ed
old_desc_blocks = 5, new_desc_blocks = 8
The filesystem on /dev/mapper/vg00-home is now 31457280 blocks long.

root@homsrv:/etc# df /home
Filesystem            1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg00-home 125644260 1981496 117769808   2% /home
root@homsrv:/etc#