{"id":99,"date":"2019-06-02T00:00:33","date_gmt":"2019-06-01T23:00:33","guid":{"rendered":"https:\/\/blog.inplico.uk\/?p=99"},"modified":"2023-06-30T19:42:30","modified_gmt":"2023-06-30T18:42:30","slug":"partitioning-the-logical-volume-manager","status":"publish","type":"post","link":"https:\/\/blog.inplico.uk\/?p=99","title":{"rendered":"Partitioning &#8211; The Logical Volume Manager"},"content":{"rendered":"<p>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\u2019s 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.<\/p>\n<p><strong>Shrinking the \/home partition:\u00a0 <\/strong>First you need to find out where it is by running<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#lvdisplay<\/pre>\n<p>which should return information about each partition similar to<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">--- Logical volume ---\r\nLV Path\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/dev\/caa-vg\/home\r\nLV Name \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0home\r\nVG Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 caa-vg\r\nLV UUID\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 xxxx-xxxx-xxxxxxx-xxxxxx-xxxxxx\r\nLV Write Access\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 read\/write\r\nLV Creation host, time caa, 2016-05-04 22:17:43 +0100\r\nLV Status\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 available\r\n# open\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a01\r\nLV Size\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 381.46 GiB\r\nCurrent LE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 97654\r\nSegments\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1\r\nAllocation\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 inherit\r\nRead ahead sectors\u00a0\u00a0\u00a0\u00a0 auto\r\n- currently set to\u00a0\u00a0\u00a0\u00a0 256\r\nBlock device\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 254:6<\/pre>\n<p>If you do not have Logical Volume Manager installed then do so:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#apt-get update &amp;&amp; apt-get install lvm2<\/pre>\n<p>To reduce the partition simply run:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#umount \/home\r\n#lvreduce --resizefs -L 100G \/dev\/caa-vg\/home\r\n#mount \/home\r\n<\/pre>\n<p>This will then change the partition size to 100GB so that you will have enough space to create the new partitions<\/p>\n<p>Note <strong>caa-vg<\/strong> is the name of the volume group on our example machine.<\/p>\n<p><strong>To increase volume size of a partition run:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#umount \/home\r\n#lvextend --resizefs -L 100G \/dev\/caa-vg\/home\r\n#mount \/home\r\n<\/pre>\n<p><strong>To display the current size of the patition run<\/strong>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#lvdisplay \/dev\/caa-vg\/home<\/pre>\n<p><strong>To create a new logical volume for the pgsql partition run<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\"># lvcreate -L 100G -n pgsql caa-vg<\/pre>\n<p>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 <strong>\/dev\/caa-vg\/pgsql<\/strong> you can check this by running <strong>lvdisplay<\/strong><\/p>\n<p>Now you need to create the filesystem:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#mkfs.ext4 -L pgsql \/dev\/caa-vg\/pgslq<\/pre>\n<p>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:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#mount \/dev\/caa-vg\/pgsql \/pgsql<\/pre>\n<p>from the command line<\/p>\n<p><strong>To list the partitions run<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#lsblk<\/pre>\n<p><strong>To display free space on the physical volume run<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#pvs<\/pre>\n<p><strong>or for the volume group<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#vgs<\/pre>\n<p><strong>Other useful commands that may be useful for recovering lost volumes.<\/strong><\/p>\n<ul style=\"padding-left: 40px;\">\n<li><strong>lvscan<\/strong> &#8211; displays information about logical volumens<\/li>\n<li><strong>lvchange -ay \/dev\/volume-group\/volume<\/strong> &#8211; sets an inactive volume to active<\/li>\n<li><strong>vgscan<\/strong> &#8211; displays volume group names<\/li>\n<li><strong>vgcreate<\/strong> &#8211; create a new volume group<\/li>\n<li><strong>pvdislplay<\/strong> &#8211; shows information about physical volumes<\/li>\n<li><strong>lvdisplay<\/strong> &#8211; shows volume information<\/li>\n<li><strong>df -Th<\/strong> &#8211; shows the type (ext3, ext4, etc..) of the logical volumes<\/li>\n<li><strong>fsck \/dev\/volume-greoup\/logical-volume<\/strong> &#8211; checks the volume (can only be used when volume is not mounted)<\/li>\n<\/ul>\n<p><strong>Creating a new volume group from a new disk.<\/strong><\/p>\n<p>To do this the first thing you need to do is get os to see the disk.\u00a0 First use lsblk to list the devices and determine which one you are looking for.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"godzilla\">lsblk<\/pre>\n<p>this will generate output that looks something like<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"godzilla\">NAME                 MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT\r\nsda                    8:0    0 223.6G  0 disk \r\n\u251c\u2500sda1                 8:1    0   243M  0 part \/boot\r\n\u251c\u2500sda2                 8:2    0     1K  0 part \r\n\u2514\u2500sda5                 8:5    0 223.3G  0 part \r\n  \u251c\u2500balsa--vg-root   254:0    0  23.3G  0 lvm  \/\r\n  \u251c\u2500balsa--vg-swap_1 254:1    0    40G  0 lvm  [SWAP]\r\n  \u251c\u2500balsa--vg-var    254:2    0   8.4G  0 lvm  \/var\r\n  \u251c\u2500balsa--vg-tmp    254:3    0   1.5G  0 lvm  \/tmp\r\n  \u251c\u2500balsa--vg-home   254:4    0  54.5G  0 lvm  \/home\r\n  \u2514\u2500balsa--vg-xpws   254:5    0    80G  0 lvm  \r\nsdb                    8:16   0 931.5G  0 disk \r\nsr0                   11:0    1  1024M  0 rom<\/pre>\n<p>Select your disk and create a volume group with vgcreate.\u00a0 If for some reason this fails try using pvcreate to make the logical volume manager aware of the disk<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"godzilla\">vgcreate caa-data-vg \/dev\/sde \/dev\/sdf<\/pre>\n<p>You can then go on to create you volume groups etc. as described at the top of this page.<\/p>\n<p>NOTE:\u00a0 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.<\/p>\n<p>If you want to extend and existing volume group with a new disk then you can use <strong>vgextend<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\">vgextend caa-daa-vg \/dev\/sdb<\/pre>\n<p>Where \/dev\/sdb is your new disk.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>EFI Boot disks<\/strong><\/p>\n<p>There are times when you may want more than one partition on a disk with some as logical volumes and others as ordinary partitions.\u00a0 If you are installing an operating system on a UEFI machine for example then you need to format a small partition for grub.\u00a0 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.<\/p>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-99","post","type-post","status-publish","format-standard","hentry","category-debian-server"],"_links":{"self":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts\/99","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=99"}],"version-history":[{"count":12,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":448,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions\/448"}],"wp:attachment":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}