{"id":1361,"date":"2009-06-30T06:00:50","date_gmt":"2009-06-30T12:00:50","guid":{"rendered":"http:\/\/www.cyberward.net\/blog\/?p=1361"},"modified":"2009-06-29T20:35:19","modified_gmt":"2009-06-30T02:35:19","slug":"creating-lvm-virtual-drives","status":"publish","type":"post","link":"https:\/\/www.cyberward.net\/blog\/2009\/06\/creating-lvm-virtual-drives\/","title":{"rendered":"Creating LVM Virtual Drives"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1362\" data-permalink=\"https:\/\/www.cyberward.net\/blog\/2009\/06\/creating-lvm-virtual-drives\/driveicons\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.cyberward.net\/blog\/wp-content\/uploads\/driveicons.png?fit=430%2C112&amp;ssl=1\" data-orig-size=\"430,112\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"driveicons\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.cyberward.net\/blog\/wp-content\/uploads\/driveicons.png?fit=240%2C62&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.cyberward.net\/blog\/wp-content\/uploads\/driveicons.png?fit=430%2C112&amp;ssl=1\" class=\"size-full wp-image-1362 alignnone\" title=\"driveicons\" src=\"https:\/\/i0.wp.com\/www.cyberward.net\/blog\/wp-content\/uploads\/driveicons.png?resize=430%2C112\" alt=\"driveicons\" width=\"430\" height=\"112\" srcset=\"https:\/\/i0.wp.com\/www.cyberward.net\/blog\/wp-content\/uploads\/driveicons.png?w=430&amp;ssl=1 430w, https:\/\/i0.wp.com\/www.cyberward.net\/blog\/wp-content\/uploads\/driveicons.png?resize=300%2C78&amp;ssl=1 300w\" sizes=\"(max-width: 430px) 100vw, 430px\" data-recalc-dims=\"1\" \/><\/p>\n<p>Now that we have a raid array created, we are going to create some virtual drives. Why virtual drives? Well, we have one large terabyte drive right now, and if we just put folders in there, it can quickly get cumbersome. You have no control on size of those folders, and permissions can be more difficult. And if you try to share this drive, you can&#8217;t assign different drive letters in windows to different folders, just one to the drive. One other issue is file system. I am going to use just a basic file system here, but in the past I have created different file systems based on the type of use ie. large video files, small text files, etc. Making those decisions is beyond the scope of this tutorial, and I have decided that for my purposes now, it doesn&#8217;t matter that much. You can decided differently.<\/p>\n<p>What we will discuss is using LVM. This enables you to set up virtual drives that can contain different file systems, and that can be grown and shrunk (usually) to fit the space needs of the system. We will look at maintenance of these file systems at a later tutorial. Here we will create a backup, and a pictures virtual drive. We will not use the full terabyte of space, so that we can grow these as needed, or add another for say music at another time.<\/p>\n<p>I will once again be doing this on an ubuntu system, but the use of these tools is fairly standard across linux distributions.<br \/>\n<!--more--><br \/>\nFirst we will need to make sure that you have LVM installed.<\/p>\n<pre class=\"linux\">sudo apt-get install lvm2<\/pre>\n<p>We need to create what is called a physical volume. We need to tell LVM what actual physical drives are involved. Lets check what drives we have again.<\/p>\n<pre class=\"linux\">$ sudo fdisk -l\r\n\r\nDisk \/dev\/sda: 1000.2 GB, 1000204886016 bytes\r\n255 heads, 63 sectors\/track, 121601 cylinders\r\nUnits = cylinders of 16065 * 512 = 8225280 bytes\r\nDisk identifier: 0x00000000\r\n\r\n   Device Boot      Start         End      Blocks   Id  System\r\n\/dev\/sda1               1      121601   976760001   fd  Linux raid autodetect\r\n\r\nDisk \/dev\/sdb: 1000.2 GB, 1000204886016 bytes\r\n255 heads, 63 sectors\/track, 121601 cylinders\r\nUnits = cylinders of 16065 * 512 = 8225280 bytes\r\nDisk identifier: 0xfe76bc93\r\n\r\n   Device Boot      Start         End      Blocks   Id  System\r\n\/dev\/sdb1               1      121601   976760001   fd  Linux raid autodetect<\/pre>\n<p>This is just a partial list of the drives. See that the \/dev\/sda1 and \/dev\/sdb1 drives have a system type of fd. In the last part of teh tutorial we set up software raid. If you are NOT using raid, you will need to add these devices to your physical volume. For us, we are going to add \/dev\/md0 that we created last time. Lets just verify that the array is there.<\/p>\n<pre class=\"linux\">$ sudo mdadm --detail --scan\r\nARRAY \/dev\/md0 level=raid1 num-devices=2 metadata=00.90 UUID=****<\/pre>\n<p><em>Note: all UUID&#8217;s will be replaced with **** in this doc. They will be different on every machine anyway.<\/em><\/p>\n<p>As you can see, array \/dev\/md0 is ready to go. Lets create that physical volume finally.<\/p>\n<pre class=\"linux\">sudo pvcreate \/dev\/md0<\/pre>\n<p>You can verify that it is created with the pvdisplay command.<\/p>\n<pre class=\"linux\">$ sudo pvdisplay\r\n  \"\/dev\/md0\" is a new physical volume of \"931.51 GB\"\r\n  --- NEW Physical volume ---\r\n  PV Name               \/dev\/md0\r\n  VG Name\r\n  PV Size               931.51 GB\r\n  Allocatable           NO\r\n  PE Size (KByte)       0\r\n  Total PE              0\r\n  Free PE               0\r\n  Allocated PE          0\r\n  PV UUID               ****<\/pre>\n<p>Now we need to create our volume group. That last step identified what hardware LVM has available. This next step groups that hardware into volume groups. I will call my &#8220;nas&#8221;.<\/p>\n<pre class=\"linux\">sudo vgcreate nas \/dev\/md0<\/pre>\n<p>We can then verify our volume group.<\/p>\n<pre class=\"linux\">$ sudo vgdisplay\r\n  --- Volume group ---\r\n  VG Name               nas\r\n  System ID\r\n  Format                lvm2\r\n  Metadata Areas        1\r\n  Metadata Sequence No  1\r\n  VG Access             read\/write\r\n  VG Status             resizable\r\n  MAX LV                0\r\n  Cur LV                0\r\n  Open LV               0\r\n  Max PV                0\r\n  Cur PV                1\r\n  Act PV                1\r\n  VG Size               931.51 GB\r\n  PE Size               4.00 MB\r\n  Total PE              238466\r\n  Alloc PE \/ Size       0 \/ 0\r\n  Free  PE \/ Size       238466 \/ 931.51 GB\r\n  VG UUID               ****<\/pre>\n<p>Next, we can finally create our virtual drives. I am going to create a backup drive of 100 gig, and a pictures drive of 400 gig, both which are added to the &#8220;nas&#8221; volume group. You can create drives of what ever size you would like.<\/p>\n<pre class=\"linux\">sudo lvcreate --name backup --size 100G nas\r\nsudo lvcreate --name pictures --size 400G nas<\/pre>\n<p>You can see information about these virtual drives with another display command. Guess what it is.<\/p>\n<pre class=\"linux\">$ sudo lvdisplay\r\n  --- Logical volume ---\r\n  LV Name                \/dev\/nas\/backup\r\n  VG Name                nas\r\n  LV UUID                gqrIVE-YtS4-cBne-QyPK-oMO1-7V7V-UaBoUL\r\n  LV Write Access        read\/write\r\n  LV Status              available\r\n  # open                 0\r\n  LV Size                100.00 GB\r\n  Current LE             25600\r\n  Segments               1\r\n  Allocation             inherit\r\n  Read ahead sectors     auto\r\n  - currently set to     256\r\n  Block device           254:0\r\n\r\n  --- Logical volume ---\r\n  LV Name                \/dev\/nas\/pictures\r\n  VG Name                nas\r\n  LV UUID                oDxJJi-lxsG-9RHw-RBME-oJah-jOJJ-J8I4p3\r\n  LV Write Access        read\/write\r\n  LV Status              available\r\n  # open                 0\r\n  LV Size                400.00 GB\r\n  Current LE             102400\r\n  Segments               1\r\n  Allocation             inherit\r\n  Read ahead sectors     auto\r\n  - currently set to     256\r\n  Block device           254:1<\/pre>\n<p>Now that we have our virtual drives, can we start filling them up? Not quite. We need partitions on them. These drives are just like a bare drive from the factory. We can put whatever file system we want on them. I am just going to use ext3. This may not be the best file system out there, but it is proven, and works good enough for me.<\/p>\n<pre class=\"linux\">sudo mkfs.ext3 \/dev\/nas\/backup\r\nsudo mkfs.ext3 \/dev\/nas\/pictures<\/pre>\n<p>That takes a little bit of time, just as would without LVM. As far as your programs, and bash, and Gnome are concerned, \/dev\/nas\/backup is just another drive. It does not care, and does no know that underneath all this is a raid array and virtual drives.<\/p>\n<p>Now we need to get them mounted so that they are useable. First off, I create a couple of mount points. I like to keep them organized.<\/p>\n<pre class=\"linux\">sudo mkdir \/var\/nas\r\nsudo mkdir \/var\/nas\/backup \/var\/nas\/pictures\r\n\r\nsudo mount \/dev\/nas\/backup \/var\/nas\/backup\r\nsudo mount \/dev\/nas\/pictures \/var\/nas\/pictures<\/pre>\n<p>Now, do a &#8220;df&#8221; to see the drives on the system and the space used.<\/p>\n<pre class=\"linux\">$ df\r\nFilesystem           1K-blocks      Used Available Use% Mounted on\r\n\/dev\/sdd1            186693520   2469660 174740292   2% \/\r\n\/dev\/mapper\/nas-backup\r\n                     103212320    192248  97777192   1% \/var\/nas\/backup\r\n\/dev\/mapper\/nas-pictures\r\n                     412849328    203156 391674652   1% \/var\/nas\/pictures<\/pre>\n<p><em>Note: I removed other system file systems that we are not talking about here.<\/em><\/p>\n<p>You can see that our two drives are there. They are listed at \/var\/mapper\/nas-backup and \/var\/mapper\/nas-pictures, but they are the \/dev\/nas\/backup and \/dev\/nas\/pictures we have been setting up.<\/p>\n<p>Now you can copy your data into these drives.<\/p>\n<p>I am not the only one that uses these drives, and they will be shared on samba (later tutorial) so I like to change the permissions on these folders. I will create a &#8220;nas&#8221; group, add myself (insert your user id for *user*), and change the permissions.<\/p>\n<pre class=\"linux\">sudo groupadd nas\r\nsudo adduser *user* nas\r\nsudo chown -R *user*:nas \/var\/nas\/backup\r\nsudo chown -R *user*:nas \/var\/nas\/pictures<\/pre>\n<p>The file permissions are set up as writable by owner and readable by group and other. I will leave them this way for now.<\/p>\n<p>Things look good to go, and they would for awhile, until you reboot. Then your drives would disappear. We need to make them a little more permanent. We do this by putting some entries in the \/etc\/fstab file. This is the list of all mountable file systems that the OS uses to connect things up when booting.<\/p>\n<p>This file in Ubuntu is using UUID&#8217;s, so we will to. First thing you need to do is find out what yours are. So&#8230;<\/p>\n<pre class=\"linux\">\r\n$ sudo blkid\r\n\/dev\/sdc1: UUID=\"****1\" SEC_TYPE=\"ext2\" TYPE=\"ext3\" \r\n\/dev\/sdd1: UUID=\"****2\" TYPE=\"ext3\" \r\n\/dev\/sdd5: TYPE=\"swap\" UUID=\"****3\" \r\n\/dev\/sda1: UUID=\"****4\" TYPE=\"mdraid\" \r\n\/dev\/sdb1: UUID=\"****5\" TYPE=\"mdraid\" \r\n\/dev\/md0: UUID=\"****6\" TYPE=\"lvm2pv\" \r\n\/dev\/mapper\/nas-backup: UUID=\"****7\" TYPE=\"ext3\" \r\n\/dev\/mapper\/nas-pictures: UUID=\"****8\" TYPE=\"ext3\" \r\n<\/pre>\n<p>You can see the unique ID&#8217;s that are assigned to the drives in the array, the raid array its self, the LVM physical volume, and finally, the two logical volumes. Use these UUID&#8217;s that you get when you execute blkid. Now lets edit \/etc\/fstab<\/p>\n<pre class=\"linux\">\r\n$ sudo nano -w \/etc\/fstab\r\n# \/etc\/fstab: static file system information.\r\n#\r\n# <file system> <mount point>   <type>  <options>       <dump>  <pass>\r\nproc            \/proc           proc    defaults        0       0\r\n# \/dev\/sdd1\r\nUUID=****2 \/               ext3    relatime,errors=remount-ro 0  $\r\n# \/dev\/sdd5\r\nUUID=****3 none            swap    sw              0       0\r\n\/dev\/scd0       \/media\/cdrom0   udf,iso9660 user,noauto,exec,utf8 0       0\r\n\r\n#\/dev\/nas\/backup\r\nUUID=****7 \/var\/nas\/backup ext3    relatime,noexec 0 2\r\n\r\n#\/dev\/nas\/pictures\r\nUUID=****8 \/var\/nas\/pictures ext3  relatime,noexec 0 2\r\n<\/pre>\n<p>You shouldn&#8217;t have to change anything except add the lines at the bottom for the backup and pictures drives (or whatever you created) . Please use the UUID&#8217;s you found from blkid.<\/p>\n<p>Press ctrl-x to exit nano and save the file. <\/p>\n<p>Try a reboot and see how it works. Once you bring the system back up, open a terminal and type df. This will show you all mounted drives, and your new drives should be there.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now that we have a raid array created, we are going to create some virtual drives. Why virtual drives? Well, we have one large terabyte drive right now, and if we just put folders in there, it can quickly get &hellip; <a href=\"https:\/\/www.cyberward.net\/blog\/2009\/06\/creating-lvm-virtual-drives\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[27,103],"tags":[46,47,23,334],"series":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pffAy-lX","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/posts\/1361"}],"collection":[{"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/comments?post=1361"}],"version-history":[{"count":0,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/posts\/1361\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/media?parent=1361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/categories?post=1361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/tags?post=1361"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/series?post=1361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}