{"id":879,"date":"2019-05-06T15:27:05","date_gmt":"2019-05-06T20:27:05","guid":{"rendered":"https:\/\/www.snaservices.com\/?page_id=879"},"modified":"2023-06-09T09:42:59","modified_gmt":"2023-06-09T14:42:59","slug":"linux-disk-administration","status":"publish","type":"page","link":"https:\/\/www.snaservices.com\/index.php\/linux-disk-administration\/","title":{"rendered":"Linux Disk Administration"},"content":{"rendered":"\n<p>This page contains some of the tricks and experiences that I have came into with dealing with disks in Linux.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Expand Disks in Linux<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Create a New LVM Volume<\/h3>\n\n\n\n<p>The example below will create a new logical volume based on an existing volume group with free space available. Use vgdisplay -v to display the available volume groups. If you need to expand the volume group refer to the Expand Volume Group section. In the example below, datavg is returned. Use lvcreate -n lvname -L size [MB|GB] datavg.  If you want to use all the free space in the volume group use -l +100%FREE instead of the -L size parameter. After you create the logical volume you&#8217;ll need to create the file system using mkfs.ext3, mkfs.ext4, mkfs.xfs or whatever you want.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1. vgdisplay -v\n2a. lvcreate -n lvname -L 10GB datavg \n  OR\n2b. lvcreate -n lvname -l +100%FREE datavg\n3. mkfs.ext4 \/dev\/datavg\/lvname\nAdd the new lvname to the fstab if desired \n4. mount -a\n5. mount # verify new mount is there<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create a New LVM Swap Volume<\/h3>\n\n\n\n<p>The example below will create a new swap volume based on an existing volume group with free space available. Use vgdisplay -v to display the available volume groups. If you need to expand the volume group refer to the Expand Volume Group section. In the example below, lvswap is returned. Use lvcreate -n lvswap -L size [MB|GB] osvg.  If you want to use all the free space in the volume group use -l +100%FREE instead of the -L size parameter. After you create the logical volume you&#8217;ll need to create the swap file system using mkswap and  enable it. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1. vgdisplay -v\n2a. lvcreate -n lvswap -L 2GB osvg \n  OR\n2b. lvcreate -n lvswap -l +100%FREE osvg\n3. mkswap \/dev\/osvg\/lvswap\n4. Add the following line to \/etc\/fstab\n   \/dev\/osvg\/lvswap    swap    swap    defaults    0 0 \n4. swapon -a\n5. swapon -s <\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Expand LVM Volume<\/h3>\n\n\n\n<p> The example below will expand a logical volume based on an existing volume group with free space available. Use vgdisplay -v to display the available volume groups. If you need to expand the volume group refer to the Expand Volume Group section. In the example below, datavg is returned. Use lvextend -r -L size [MB|GB]  <br>lvname.  If you want to use all the free space in the volume group use -l +100%FREE instead of the -L size parameter.  The -r command does online resizing. If this option fails you may have to unmount the file system and run the resize2fs on the unmounted device to expand it. Then remount when the resize2fs completes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1. vgdisplay -v\n2. Find the VG that LV is part of (If you need to expand the VG, refer to the Expand Volume Group Section\n3. lvextend -r -L +10G \/dev\/datavg\/lvname\n4. df -h # to verify the new size<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Add a New Drive to a Existing LVM Volume Group<\/h3>\n\n\n\n<p>The example below will add a new drive to a LVM Volume Group. The first thing you need to do is scan for the new drive(s), if it&#8217;s a new VMWare, Hyper-V or SAN volume. The results of the scan can be found at the tail of dmesg output. The output should look something like \/dev\/sd? where ? is a new drive character. Using this drive character you can create the physical volume and then add it to the volume group. You can specify the letter that ? will be directly or you can use the ? wildcard which will add all new \/dev\/sd? found.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1. cd \/sys\/class\/scsi_host\n2. for i in *; do echo '- - -' &gt; $i\/scan; done\n3. dmesg | tail  # to find the new drive letter\n4. pvcreate \/dev\/sd?\n5. vgextend \/dev\/datavg \/dev\/sd?<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Add  a New Drive to a New LVM Volume Group<\/h3>\n\n\n\n<p>The example below will add a newly added disk to a Linux server. This disk could be added in a Hypervisor or Physical system. The process is the same. This process is similar to the process of Add a New Drive to an Existing LVM Volume Group except instead of extending an existing Volume Group you are creating one.   <\/p>\n\n\n\n<p>The first thing you need to do is scan for the new drive(s), if it&#8217;s a new VMWare, Hyper-V or SAN volume. The results of the scan can be found at the tail of dmesg output. The output should look something like \/dev\/sd? where ? is a new drive character. Using this drive character you can create the physical volume and then use it to create the volume group. You can specify the letter that ? will be directly or you can use the ? wildcard which will add all new \/dev\/sd? found. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1. cd \/sys\/class\/scsi_host\n2. for i in *; do echo '- - -' &gt; $i\/scan; done\n3. dmesg | tail  # to find the new drive letter\n4. pvcreate \/dev\/sd?\n5. vgcreate datavg \/dev\/sd? <\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Expand an Already Attached Disk in a Volume Group<\/h3>\n\n\n\n<p>In the example below we already have a disk attached to a volume group called <code>datavg<\/code>.  Here we will expand it in Hyper-V or VMware by 50G.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1. display existing physical volume size:\n[root@server1~]$ <strong>pvs\r<\/strong>\n  PV         VG       Fmt  Attr PSize   PFree\r\n  \/dev\/sda3  Volume00 lvm2 a--   35.30g &lt;11.04g\r\n  \/dev\/sdb   Volume01 lvm2 a--  &lt;<strong>50.00g      0<\/strong>\n\r\n2. You'll need to run pvresize twice on the disk\n[root@server1~]$ <strong>pvresize \/dev\/sdb<\/strong>\r\n  Physical volume \"\/dev\/sdb\" changed\r\n  1 physical volume(s) resized or updated \/ 0 physical volume(s) not resized\r\n[root@server1~]$ <strong>pvresize \/dev\/sdb<\/strong>\r\n  Physical volume \"\/dev\/sdb\" changed\r\n  1 physical volume(s) resized or updated \/ 0 physical volume(s) not resized\r\n\n3. Verify the resize happened with pvs again.\n[root@server1~]$ <strong>pvs\r<\/strong>\n  PV         VG       Fmt  Attr PSize    PFree\r\n  \/dev\/sda3  Volume00 lvm2 a--    35.30g &lt;11.04g\r\n  \/dev\/sdb   Volume01 lvm2 a--  &lt;<strong>100.00g  50.00g<\/strong><\/pre>\n\n\n\n<p>Now you can proceed with expanding the logical volume <code>lvextend <\/code>as listed above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This page contains some of the tricks and experiences that I have came into with dealing with disks in Linux. Expand Disks in Linux Create a New LVM Volume The example below will create a new logical volume based on an existing volume group with free space available. Use vgdisplay -v to display the available &hellip; <a href=\"https:\/\/www.snaservices.com\/index.php\/linux-disk-administration\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Linux Disk Administration<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"class_list":["post-879","page","type-page","status-publish","hentry"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.snaservices.com\/index.php\/wp-json\/wp\/v2\/pages\/879","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.snaservices.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.snaservices.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.snaservices.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.snaservices.com\/index.php\/wp-json\/wp\/v2\/comments?post=879"}],"version-history":[{"count":0,"href":"https:\/\/www.snaservices.com\/index.php\/wp-json\/wp\/v2\/pages\/879\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.snaservices.com\/index.php\/wp-json\/wp\/v2\/media?parent=879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}