I like to keep postgresql data and mail on completely separate independent partitions. If you are installing Debian from scratch and you use LVM with separate partitions for /home /var and /tmp (RECOMMENDED) then you can use the lvm tools to resize your /home partition to create space for /mailstore and /pgsql. If it is a server that is being installed at a customer’s site then I would also recommend creating a small partition to back up the conf files that you can mount manually but is not in fstab.
Shrinking the /home partition: First you need to find out where it is by running
#lvdisplay
which should return information about each partition similar to
--- Logical volume --- LV Path /dev/caa-vg/home LV Name home VG Name caa-vg LV UUID xxxx-xxxx-xxxxxxx-xxxxxx-xxxxxx LV Write Access read/write LV Creation host, time caa, 2016-05-04 22:17:43 +0100 LV Status available # open 1 LV Size 381.46 GiB Current LE 97654 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:6
If you do not have Logical Volume Manager installed then do so:
#apt-get update && apt-get install lvm2
To reduce the partition simply run:
#umount /home #lvreduce --resizefs -L 100G /dev/caa-vg/home #mount /home
This will then change the partition size to 100GB so that you will have enough space to create the new partitions
Note caa-vg is the name of the volume group on our example machine.
To increase volume size of a partition run:
#umount /home #lvextend --resizefs -L 100G /dev/caa-vg/home #mount /home
To display the current size of the patition run:
#lvdisplay /dev/caa-vg/home
To create a new logical volume for the pgsql partition run
# lvcreate -L 100G -n pgsql caa-vg
This will create a 50GB logical volume called pgsql. Next you need to format the partition. The logical volume should have been created with the name /dev/caa-vg/pgsql you can check this by running lvdisplay
Now you need to create the filesystem:
#mkfs.ext4 -L pgsql /dev/caa-vg/pgslq
Now all you need to do is create a mount point and add it to /etc/fstab if you want it to mount automatically. If you want to mount it manually then run:
#mount /dev/caa-vg/pgsql /pgsql
from the command line
To list the partitions run
#lsblk
To display free space on the physical volume run
#pvs
or for the volume group
#vgs
Other useful commands that may be useful for recovering lost volumes.
- lvscan – displays information about logical volumens
- lvchange -ay /dev/volume-group/volume – sets an inactive volume to active
- vgscan – displays volume group names
- vgcreate – create a new volume group
- pvdislplay – shows information about physical volumes
- lvdisplay – shows volume information
- df -Th – shows the type (ext3, ext4, etc..) of the logical volumes
- fsck /dev/volume-greoup/logical-volume – checks the volume (can only be used when volume is not mounted)
Creating a new volume group from a new disk.
To do this the first thing you need to do is get os to see the disk. First use lsblk to list the devices and determine which one you are looking for.
lsblk
this will generate output that looks something like
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 223.6G 0 disk ├─sda1 8:1 0 243M 0 part /boot ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 223.3G 0 part ├─balsa--vg-root 254:0 0 23.3G 0 lvm / ├─balsa--vg-swap_1 254:1 0 40G 0 lvm [SWAP] ├─balsa--vg-var 254:2 0 8.4G 0 lvm /var ├─balsa--vg-tmp 254:3 0 1.5G 0 lvm /tmp ├─balsa--vg-home 254:4 0 54.5G 0 lvm /home └─balsa--vg-xpws 254:5 0 80G 0 lvm sdb 8:16 0 931.5G 0 disk sr0 11:0 1 1024M 0 rom
Select your disk and create a volume group with vgcreate. If for some reason this fails try using pvcreate to make the logical volume manager aware of the disk
vgcreate caa-data-vg /dev/sde /dev/sdf
You can then go on to create you volume groups etc. as described at the top of this page.
NOTE: In most cases it makes no sense to create multiple partitions on the same disk when using LVM as you use it to manage the volumes.
If you want to extend and existing volume group with a new disk then you can use vgextend
vgextend caa-daa-vg /dev/sdb
Where /dev/sdb is your new disk.
EFI Boot disks
There are times when you may want more than one partition on a disk with some as logical volumes and others as ordinary partitions. If you are installing an operating system on a UEFI machine for example then you need to format a small partition for grub. To do this use your favourite disk partitioning tool to create the partitions and then you can select one of those partitions for your logical volume and leave the other outside of it.
Assuming you have an EFI partition (/dev/sda1) and a second partition (/dev/sda2) on your drive then you can simply create a volume group using the second partition in the normal way using vgcreate.
Recent Comments