{"id":756,"date":"2018-06-25T11:51:57","date_gmt":"2018-06-25T08:51:57","guid":{"rendered":"http:\/\/leonidassavvides.com\/blog\/?p=756"},"modified":"2018-06-25T11:51:57","modified_gmt":"2018-06-25T08:51:57","slug":"logical-volumes-lvm-disk-encryption-creating-a-raid-device","status":"publish","type":"post","link":"https:\/\/www.leonidassavvides.com\/blog\/2018\/06\/logical-volumes-lvm-disk-encryption-creating-a-raid-device\/","title":{"rendered":"Logical Volumes (LVM), Disk Encryption, Creating a RAID Device"},"content":{"rendered":"<div style=\"margin-top: 0px; margin-bottom: 0px;\" class=\"sharethis-inline-share-buttons\" ><\/div><h3 style=\"text-align: center;\">Logical Volumes (LVM), Disk Encryption, Creating a RAID Device<br \/>\nin Linux<\/h3>\n<h2 style=\"text-align: center;\">================<\/h2>\n<p style=\"text-align: left;\">In this post I show you these three (3) advanced procedures for CentOS 7 Linux Server&#8230;<\/p>\n<p style=\"text-align: left;\">I recommend try them in test VM Server and after in Production Server&#8230;<\/p>\n<h3 style=\"text-align: left;\"><strong>A &#8211; Disk Encryption<\/strong><\/h3>\n<p style=\"text-align: left;\"><strong>Exercise 22.1 Disk Encryption<\/strong><br \/>\nIn this exercise, you will encrypt a partition on the disk in order to provide a measure of security in the event that the hard drive or laptop is stolen. Reviewing the cryptsetup documentation first would be a good idea (man cryptsetup and cryptsetup &#8211;help).<\/p>\n<p>1. Create a new partition for the encrypted block device with fdisk. Make sure the kernel is aware of the new partition table. A reboot will do this but there are other methods.<br \/>\n2. Format the partition with cryptsetup using LUKS for the crypto layer.<br \/>\n3. Create the un-encrypted pass through device by opening the encrypted block device, i.e., secret-disk.<br \/>\n4. Add an entry to \/etc\/crypttab so that the system prompts for the passphrase on reboot.<br \/>\n5. Format the filesystem as an ext4 filesystem.<br \/>\n6. Create a mount point for the new filesystem, i.e. \/secret.<br \/>\n7. Add an entry to \/etc\/fstab so that the filesystem is mounted on boot.<br \/>\n8. Try and mount the encrypted filesystem.<br \/>\n9. Validate the entire configuration by rebooting.<\/p>\n<p><strong>Solution 22.1<\/strong><br \/>\n1. $ sudo fdisk \/dev\/sda<br \/>\nCreate a new partition (in the below \/dev\/sda4 to be concrete) and then either issue:<br \/>\n$ sudo partprobe -s<br \/>\nto have the system re-read the modified partition table, or reboot (which is far safer).<br \/>\nNote: If you can\u2019t use a real partition, use the technique in the previous chapter to use a loop device or image file for the same purpose.<br \/>\n2. $ sudo cryptsetup luksFormat \/dev\/sda4<br \/>\n3. $ sudo cryptsetup luksOpen \/dev\/sda4 secret-disk<br \/>\n4. Add the following to \/etc\/crypttab:<br \/>\nsecret-disk \/dev\/sda4<br \/>\n5. $ sudo mkfs -t ext4 \/dev\/mapper\/secret-disk<br \/>\n6. $ sudo mkdir -p \/secret<br \/>\n7. Add the following to \/etc\/fstab:<br \/>\n\/dev\/mapper\/secret-disk \/secret ext4 defaults 1 2<br \/>\n8. Mount just the one filesystem:<br \/>\n$ sudo mount \/secret<br \/>\nor mount all filesystems mentioned in \/etc\/fstab:<br \/>\n$ sudo mount -a<br \/>\n9. Reboot.<\/p>\n<h3 style=\"text-align: left;\"><strong>B &#8211; Logical Volumes (LVM)<\/strong><\/h3>\n<p style=\"text-align: left;\"><strong>Exercise 23.1 Logical Volumes<\/strong><br \/>\nWe are going to create a logical volume using two 250 MB partitions. We are going to assume you have real partition-able disk space available.<\/p>\n<p>1. Create two 250 MB partitions of type logical volume (8e).<br \/>\n2. Convert the partitions to physical volumes.<br \/>\n3. Create a volume group named myvg and add the two physical volumes to it. Use the default extent size.<br \/>\n4. Allocate a 300 MB logical volume named mylvm from volume group myvg.<br \/>\n5. Format and mount the logical volume mylvm at \/mylvm<br \/>\n6. Use lvdisplay to view information about the logical volume.<br \/>\n7. Grow the logical volume and corresponding filesystem to 350 MB.<\/p>\n<p><strong>Solution 23.1<\/strong><br \/>\n1. Execute:<br \/>\n$ sudo fdisk \/dev\/sda<br \/>\nusing whatever hard disk is appropriate, and create the two partitions. While in fdisk, typing t will let you set the partition type to 8e. While it doesn\u2019t matter if you don\u2019t set the type, it is a good idea to lessen confusion. Use w to rewrite the partition table and exit, and then<br \/>\n$ sudo partprobe -s<br \/>\nor reboot to make sure the new partitions take effect.<br \/>\n2. Assuming the new partitions are \/dev\/sdaX and \/dev\/sdaY:<br \/>\n$ sudo pvcreate \/dev\/sdaX<br \/>\n$ sudo pvcreate \/dev\/sdaY<br \/>\n$ sudo pvdisplay<br \/>\n3. $ sudo vgcreate myvg \/dev\/sdaX \/dev\/sdaY<br \/>\n$ sudo vgdisplay<br \/>\n4. $ sudo lvcreate -L 300M -n mylvm myvg<br \/>\n$ sudo lvdisplay<br \/>\n5. $ sudo mkfs.ext4 \/dev\/myvg\/mylvm<br \/>\n$ mkdir \/mylvm<br \/>\n$ sudo mount \/dev\/myvg\/mylvm \/mylvm<br \/>\nIf you want the mount to be persistent, edit \/etc\/fstab to include the line:<br \/>\n\/dev\/myvg\/mylvm \/mylvm ext4 defaults 0 0<br \/>\n6. $ sudo lvdisplay<br \/>\n7. $ df -h<br \/>\n$ sudo lvresize -r -L 350M \/dev\/myvg\/mylvm<br \/>\n$ df -h<br \/>\nor<br \/>\n$ sudo lvresize -r -L +50M \/dev\/myvg\/mylvm<\/p>\n<h3 style=\"text-align: left;\"><strong>C &#8211; Creating a RAID Device<\/strong><\/h3>\n<p><strong>Exercise 24.1 Creating a RAID Device<\/strong><br \/>\nNormally when creating a RAID device we would use partitions on separate disks. However, for this exercise we probably don\u2019t have such hardware available. Thus we will need to have two partitions on the same disk.<br \/>\nThe process will be the same whether the partitions are on one drive or several (Although there is obviously little reason to actually create a RAID on a single device).<\/p>\n<p>1. Create two 200 MB partitions of type raid (fd) either on your hard disk using fdisk, or using LVM.<br \/>\n2. Create a RAID 1 device named \/dev\/md0 using the two partitions.<br \/>\n3. Format the RAID device as an ext4 filesystem. Then mount it at \/myraid and make the mount persistent.<br \/>\n4. Place the information about \/dev\/md0 in \/etc\/mdadm.conf file using mdadm. (Depending on your distribution, this file may not<br \/>\npreviously exist.)<br \/>\n5. Examine \/proc\/mdstat to see the status of your RAID device.<\/p>\n<p><strong>Solution 24.1<\/strong><br \/>\n1. If you need to create new partitions do:<br \/>\n$ sudo fdisk \/dev\/sda<br \/>\nand create the partitions as we have done before. For purposes of being definite, we will call them \/dev\/sdaX and<br \/>\n\/dev\/sdaY. You will need to run partprobe or kpartx or reboot after you are done to make sure the system is properly aware of the new partitions.<br \/>\n2. $ sudo mdadm -C \/dev\/md0 &#8211;level=1 &#8211;raid-disks=2 \/dev\/sdaX \/dev\/sdaY<br \/>\n3. $ sudo mkfs.ext4 \/dev\/md0<br \/>\n$ sudo mkdir \/myraid<br \/>\n$ sudo mount \/dev\/md0 \/myraid<br \/>\nand add to \/etc\/fstab<br \/>\n\/dev\/md0 \/myraid ext4 defaults 0 0<br \/>\n4. $ mdadm &#8211;detail &#8211;scan &gt;&gt; \/etc\/mdadm.conf<br \/>\n5. $ cat \/proc\/mdstat<br \/>\nPersonalities : [raid1]<br \/>\nmd0 : active raid1 dm-14[1] dm-13[0]<br \/>\n204736 blocks [2\/2] [UU]<br \/>\nunused devices: &lt;none&gt;<br \/>\nYou should probably verify that with a reboot, the RAID volume is mounted automatically. When you are done, you probably will want to clean up by removing the line from \/etc\/fstab, and then getting rid of the partitions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Logical Volumes (LVM), Disk Encryption, Creating a RAID Device in Linux ================ In this post I show you these three (3) advanced procedures for CentOS 7 Linux Server&#8230; I recommend try them in test VM Server and after in Production Server&#8230; A &#8211; Disk Encryption Exercise 22.1 Disk Encryption In this exercise, you will encrypt &hellip; <a href=\"https:\/\/www.leonidassavvides.com\/blog\/2018\/06\/logical-volumes-lvm-disk-encryption-creating-a-raid-device\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Logical Volumes (LVM), Disk Encryption, Creating a RAID Device&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,21,22,37,43],"tags":[],"class_list":["post-756","post","type-post","status-publish","format-standard","hentry","category-linux","category-mac-os-x","category-macos","category-security","category-tech"],"_links":{"self":[{"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/posts\/756","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/comments?post=756"}],"version-history":[{"count":0,"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/posts\/756\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/media?parent=756"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/categories?post=756"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.leonidassavvides.com\/blog\/wp-json\/wp\/v2\/tags?post=756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}