{"id":59,"date":"2018-04-20T06:52:52","date_gmt":"2018-04-20T06:52:52","guid":{"rendered":"http:\/\/boernig.de\/wordpress\/?p=59"},"modified":"2018-04-20T06:52:52","modified_gmt":"2018-04-20T06:52:52","slug":"how-to-add-a-ssd-disk-as-cache-to-a-given-file-system-on-lvm","status":"publish","type":"post","link":"http:\/\/boernig.de\/wordpress\/2018\/04\/20\/how-to-add-a-ssd-disk-as-cache-to-a-given-file-system-on-lvm\/","title":{"rendered":"How to add a SSD disk as cache to a given file system on LVM"},"content":{"rendered":"<p>Today a quick one: I want to add a fast SSD disk as accelerator to a given file system running on software RAID and LVM.<\/p>\n<p>I run a hosted server that has two 3 TB hard drives that operate in software RAID 1 mode:<\/p>\n<pre>[root@iboernig-hosted ~]# lsblk\r\nNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT\r\nsda 8:0 0 223.6G 0 disk\r\nsdb 8:16 0 2.7T 0 disk \r\n\u251c\u2500sdb1 8:17 0 512M 0 part \r\n\u2502 \u2514\u2500md0 9:0 0 511.4M 0 raid1 \/boot\r\n\u251c\u2500sdb2 8:18 0 2.7T 0 part \r\n\u2502 \u2514\u2500md1 9:1 0 2.7T 0 raid1 \r\n\u2502 \u251c\u2500vg0-root 253:0 0 100G 0 lvm \/\r\n\u2502 \u251c\u2500vg0-swap 253:1 0 20G 0 lvm [SWAP]\r\n\u2502 \u251c\u2500vg0-home 253:3 0 200G 0 lvm \/home\r\n\u2502 \u2514\u2500vg0-var_corig 253:8 0 1T 0 lvm \r\n\u2502 \u2514\u2500vg0-var 253:2 0 1T 0 lvm \/var\r\n\u2514\u2500sdb3 8:19 0 1M 0 part \r\nsdc 8:32 0 2.7T 0 disk \r\n\u251c\u2500sdc1 8:33 0 512M 0 part \r\n\u2502 \u2514\u2500md0 9:0 0 511.4M 0 raid1 \/boot\r\n\u251c\u2500sdc2 8:34 0 2.7T 0 part \r\n\u2502 \u2514\u2500md1 9:1 0 2.7T 0 raid1 \r\n\u2502 \u251c\u2500vg0-root 253:0 0 100G 0 lvm \/\r\n\u2502 \u251c\u2500vg0-swap 253:1 0 20G 0 lvm [SWAP]\r\n\u2502 \u251c\u2500vg0-home 253:3 0 200G 0 lvm \/home\r\n\u2502 \u2514\u2500vg0-var_corig 253:8 0 1T 0 lvm \r\n\u2502 \u2514\u2500vg0-var 253:2 0 1T 0 lvm \/var\r\n\u2514\u2500sdc3 8:35 0 1M 0 part<\/pre>\n<p>As you can see the disks are called \/dev\/sdb and \/dev\/sdc respectively. And there is a lot of free space still available.<\/p>\n<p>Additionally the sda disk is 240 GB SSD. Now I want use the SSD as caching device and use half of the capacity as persistent cache for the \/var file system.<\/p>\n<p>First of all I have to add the device to the volume group:<\/p>\n<pre>$ pvcreate \/dev\/sda\r\n\r\n$ vgextend vg0 \/dev\/sda<\/pre>\n<p>For the next step I have to create two logical volumes, one for the cache data itself and a smaller one for the metadata and make sure that they are created using the \/dev\/sda physical volume:<\/p>\n<pre>$\u00a0lvcreate -L 100G -n cachedisk1 vg0 \/dev\/sda\r\n\r\n$\u00a0lvcreate -L 4G -n metadisk1 vg0 \/dev\/sda<\/pre>\n<p>Now I create the cachepool and link the cache to the meta data:<\/p>\n<pre>$\u00a0lvconvert --type cache-pool \/dev\/vg0\/cachedisk1 --poolmetadata \/dev\/vg0\/metadisk1<\/pre>\n<p>At a last step I configure the cache for the \/var file system:<\/p>\n<pre>$\u00a0lvconvert --type cache \/dev\/vg0\/var --cachepool cachedisk1<\/pre>\n<p>Done:<\/p>\n<pre>[root@iboernig-hosted ~]# lvs -a\r\n LV G Attr LSize  Pool Origin Data% Meta% Move Log Cpy%Sync Convert\r\n [cachedisk1] vg0 Cwi---C--- 100.00g 0.14 0.16 0.00 \r\n [cachedisk1_cdata] vg0 Cwi-ao---- 100.00g \r\n [cachedisk1_cmeta] vg0 ewi-ao---- 4.00g \r\n cachedisk2 vg0 -wi-a----- 100.00g \r\n home vg0 -wi-ao---- 200.00g \r\n [lvol0_pmspare] vg0 ewi------- 4.00g \r\n metadisk2 vg0 -wi-a----- 4.00g \r\n root vg0 -wi-ao---- 100.00g \r\n swap vg0 -wi-ao---- 20.00g \r\n var vg0 Cwi-aoC--- 1.00t [cachedisk1] [var_corig] 0.14 0.16 0.00 \r\n [var_corig] vg0 owi-aoC--- 1.00t<\/pre>\n<p>That was easy! I can see the cache usage and now I can observe things getting faster!<\/p>\n<p>For the record: Tested on Centos 7.4 and RHEL 7.4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today a quick one: I want to add a fast SSD disk as accelerator to a given file system running on software RAID and LVM. I run a hosted server that has two 3 TB hard drives that operate in software RAID 1 mode: [root@iboernig-hosted ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda &hellip; <a href=\"http:\/\/boernig.de\/wordpress\/2018\/04\/20\/how-to-add-a-ssd-disk-as-cache-to-a-given-file-system-on-lvm\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to add a SSD disk as cache to a given file system on LVM&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,4],"tags":[],"_links":{"self":[{"href":"http:\/\/boernig.de\/wordpress\/wp-json\/wp\/v2\/posts\/59"}],"collection":[{"href":"http:\/\/boernig.de\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/boernig.de\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/boernig.de\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/boernig.de\/wordpress\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":2,"href":"http:\/\/boernig.de\/wordpress\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":61,"href":"http:\/\/boernig.de\/wordpress\/wp-json\/wp\/v2\/posts\/59\/revisions\/61"}],"wp:attachment":[{"href":"http:\/\/boernig.de\/wordpress\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/boernig.de\/wordpress\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/boernig.de\/wordpress\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}