{"id":7137,"date":"2024-11-12T14:24:54","date_gmt":"2024-11-12T19:24:54","guid":{"rendered":"https:\/\/carleton.ca\/scs\/?p=7137"},"modified":"2024-11-12T14:24:54","modified_gmt":"2024-11-12T19:24:54","slug":"extend-disk-space","status":"publish","type":"post","link":"https:\/\/carleton.ca\/scs\/2024\/extend-disk-space\/","title":{"rendered":"Extend Linux Disk (disk space)"},"content":{"rendered":"<p><a href=\"#why\">Why extend a disk?<\/a><br \/>\n<a href=\"#what\">What is LVM Partition<\/a><br \/>\n<a href=\"#check-existing-space\">Check Existing Space<\/a><br \/>\n<a href=\"#extend-disk-script\">Extend Partition using the Script<\/a><br \/>\n<a href=\"#extend-disk-manual\">Extend Partition Manually<\/a><\/p>\n<h2 id=\"why\">Why extend a disk?<\/h2>\n<p>Many of our images (primarily on openstack) do not grow their <em>partition\/file system<\/em> size automatically if you choose a <strong>flavor<\/strong> (openstack resource definition) that allocates more disk space to your instance than was available in the original image.  It is possible to use tools such as <em>cloud-init<\/em> to do this automatically.  However, in our public images, which we use on multiple environments (openstack, virtualbox, vmware, etc), we find cloud-init can sometimes cause issues.  Instead, we have scripts designed to resize the partitions for the user.<\/p>\n<h2 id=\"what\">What is LVM Partition<\/h2>\n<p>Historically, many of our standard images for <strong>Openstack<\/strong> and <strong>VirtualBox virtual machines<\/strong> use <strong>LVM (Linux Logical Volume Manager)<\/strong> to provide the disk volume for the operating system, as well as additional storage volumes (if applicable). LVM makes it easy to resize and re-purpose space within Linux, usually without even requiring a reboot.<\/p>\n<p>You can learn more about LVM here: <a title=\"LVM-Ubuntu\" href=\"https:\/\/wiki.ubuntu.com\/Lvm\">LVM &#8211; Ubuntu<\/a> &#8211; <em>LVM is available for most L<\/em><em>inux distros.<\/em><\/p>\n<h2 id=\"check-existing-space\">Check Existing Space<\/h2>\n<p>Before you can enlarge the disk, first you have to check to see if it is possible:<\/p>\n<p><strong>Check physical disk size versus the partition or LVM size (using <em>fdisk<\/em>):<\/strong><\/p>\n<ul>\n<li>Run fdisk, to see if there is more space available that could be added to the LVM:<br \/>\n<code>sudo fdisk -l<\/code><\/li>\n<li>In most of our basic images, this should show just a single physical device, such as:<br \/>\n<code>Disk \/dev\/vda: 32 GiB, 34359738368 bytes, 67108864 sectors<\/code> &#8211; <em>32 GB physical disk<\/em><\/li>\n<li>It will also show the main partition, typically the <em>LAST<\/em> partition (which could be used by LVM):<br \/>\n<strong>Regular partition example:<\/strong><br \/>\n<code>Device     Start      End  Sectors Size Type<br \/>\n\/dev\/vda1   2048     4095     2048   1M BIOS boot<br \/>\n\/dev\/vda2   4096 16777182 16773087   8G Linux filesystem<\/code><br \/>\nIn this case it is an 8 GB partition (<code>\/dev\/vda2<\/code>)<br \/>\n<strong>LVM Example:<\/strong><br \/>\n<code>Device     Boot Start      End  Sectors Size Id Type<br \/>\n\/dev\/vda1        2048 16777215 16775168   8G 8e Linux LVM <\/code><br \/>\nIn this case it is an 8 GB partition (<code>\/dev\/vda1<\/code>)<\/li>\n<li>And finally it will also show the LVM itself if LVM is being used:<br \/>\n<code>Disk \/dev\/mapper\/COMPbase--vg-root: 8 GiB, 8585740288 bytes, 16769024 sectors<\/code><\/li>\n<\/ul>\n<div class=\"slideme\"><dl class=\"slideme__list\"><dt class=\"slideme__term\"><a href=\"#slideme-see-the-full-fdisk-output-lvm-example\" aria-expanded=\"false\" aria-controls=\"slideme-see-the-full-fdisk-output-lvm-example\" class=\"slideme__heading slideme__trigger\">See the full fdisk output (LVM example)<\/a><\/dt><dd class=\"slideme__description\" id=\"slideme-see-the-full-fdisk-output-lvm-example\" aria-hidden=\"true\"><p><br \/>\n<code>Disk \/dev\/vda: 32 GiB, 34359738368 bytes, 67108864 sectors<br \/>\nUnits: sectors of 1 * 512 = 512 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<br \/>\nDisklabel type: dos<br \/>\nDisk identifier: 0xb5f8dcc1<\/code><\/p>\n<p><code>Device     Boot Start      End  Sectors Size Id Type<br \/>\n\/dev\/vda1        2048 16777215 16775168   8G 8e Linux LVM<\/code><\/p>\n<p><code>Disk \/dev\/mapper\/COMPbase--vg-root: 8 GiB, 8585740288 bytes, 16769024 sectors<br \/>\nUnits: sectors of 1 * 512 = 512 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<\/code><br \/>\n<\/p><\/dd><dl><\/div>\n<p>So, in this case, the Physical disk is <strong>32 GB<\/strong>, but only <strong>8 GB<\/strong> are currently allocated to the LVM, and no other partitions are using the rest of the space for anything else. So we can extend it!<\/p>\n<h2 id=\"extend-disk-script\">Extend Partition using the Script<\/h2>\n<p>If you are using one of our standard SCS images, either for <strong>OpenStack<\/strong> or for <strong>VirtualBox virtual machines<\/strong>, it usually comes with a small script called <strong>extend-disk.sh<\/strong>. The script is found in the home directory of the <strong>student<\/strong> user under the <strong>extend-disk<\/strong> folder. <em><strong>NOTE:<\/strong>Older images may have the script called <strong>extend-lvm.sh<\/strong>, found in the <strong>extend-lvm<\/strong> folder in the student home directory<\/em><\/p>\n<p><strong>To run the script: <\/strong><\/p>\n<ul>\n<li>Open a terminal<\/li>\n<li>Go to the directory with the script, usually: <code>cd ~student\/extend-disk\/<\/code><\/li>\n<li>Enter: <code>sudo .\/extend-disk.sh \/dev\/vda<\/code> &#8211; <em>NOTE: the \/dev\/vda may be different on your system. It is the device you found in <a href=\"#check-existing-space\">Check Existing Space<\/a> above<\/em><\/li>\n<\/ul>\n<p>That&#8217;s it! Now when you run <em>fdisk<\/em>, you should see the last partition is the full size of the physical disk: <code>sudo fdisk -l<\/code>.  <\/p>\n<p><strong>To update or download the script: <\/strong><\/p>\n<ul>\n<li>If you do not have the script, you can get it using <strong>git<\/strong>:<br \/>\n<code>git clone https:\/\/git.scs.carleton.ca\/git\/extend-disk.git<\/code><\/li>\n<li>If you have the script and it was pulled from the <strong>git repository<\/strong>, then you can pull updates:<br \/>\n<code>cd extend-disk<\/code> <em>go into the extend-disk git folder<\/em><br \/>\n<code>git pull<\/code> <em>to pull the updates<\/em><br \/>\nNOTE: If you are unsure if it was pulled from the <strong>git repository<\/strong>, then check if there is a <code>.git<\/code> hidden folder in the <strong>extend-disk<\/strong> folder (check for hidden folders with <code>ls -la<\/code>); If not, then you need to clone the repository using the <code>git clone<\/code> command above.<\/li>\n<\/ul>\n<h2 id=\"extend-disk-manual\">Extend Partition Manually<\/h2>\n<p>Here are the steps to manually extend the partition and the filesystem, including for the LVM case.<\/p>\n<p><em>NOTE: We assume the same setup as the above <a href=\"#check-existing-space\">Check Existing Space<\/a><\/em><\/p>\n<ul>\n<li><strong>Extend the physical drive partition:<\/strong>\n<ul>\n<li><code>sudo fdisk \/dev\/vda<\/code> &#8211; <em>Enter the fdisk tool to modify \/dev\/vda<\/em><br \/>\nNOTE: End each one letter command by pressing [Enter]; if the instructions do not specify a specific response to a question, just press [Enter] to accept the default<\/li>\n<li><code>p<\/code> &#8211; <em><strong>p<\/strong> command prints the disk info, same as running <code>fdisk -l \/dev\/vda<\/code><\/em><\/li>\n<li><code>d<\/code> &#8211; <em><strong>d<\/strong> command delete the last partition (usually \/dev\/vda1 or \/dev\/vda2 on our images)<\/em><\/li>\n<li><code>n<\/code> <code>e<\/code> <em><strong>n<\/strong> command creates a new partition; <strong>e<\/strong> makes that an extended partition<\/em><\/li>\n<li>Optional: <code>t<\/code> &#8211; <em><strong>t<\/strong> changes the type of partition<\/em>. NOTE: This should not be required as fdisk should use the same type as was removed. You can also enter <code>L<\/code> when prompted to find the list of codes for the types.  Make sure to use the same type as was listed by fdisk for the partition you removed in the earlier <strong>d<\/strong> step.\n<li><code>w<\/code> &#8211; <em><strong>w<\/strong> writes the changes to disk and exits fdisk<\/em><\/li>\n<\/ul>\n<\/li>\n<li><strong>IF using LVM: Modify (extend) the LVM:<\/strong>\n<ul>\n<li>Tell LVM the physical partition size has changed: <code>sudo pvresize \/dev\/vda1<\/code><\/li>\n<li>Find the actual path of the LVM logical volume: <code>sudo lvdisplay<\/code> &#8211; <em>The <strong>LV Path<\/strong> is the value needed<\/em><\/li>\n<li>Tell LVM to extend the logical volume to use all of the new partition size: <code>sudo lvextend -l +100%FREE \/dev\/COMPbase-vg\/root<\/code> &#8211; <em> Using the <strong>LV Path<\/strong> from above<\/em><\/li>\n<\/ul>\n<\/li>\n<li><strong>Resize the file system:<\/strong><br \/>\n<code>sudo resize2fs \/dev\/vda2<\/code> or for lvm: <code>sudo resize2fs \/dev\/COMPbase-vg\/root<\/code><\/li>\n<\/ul>\n<p>That&#8217;s it! Now, when you run <code>sudo fdisk -l<\/code>, it will show that the LVM is using all of the space on the physical disk!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why extend a disk? What is LVM Partition Check Existing Space Extend Partition using the Script Extend Partition Manually Why extend a disk? Many of our images (primarily on openstack) do not grow their partition\/file system size automatically if you choose a flavor (openstack resource definition) that allocates more disk space to your instance than [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","_mi_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[61,58,57,59],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Extend Linux Disk (disk space) - School of Computer Science<\/title>\n<meta name=\"description\" content=\"Why extend a disk? What is LVM Partition Check Existing Space Extend Partition using the Script Extend Partition Manually Why extend a disk? Many of our\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/carleton.ca\/scs\/2024\/extend-disk-space\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"andrewpullin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/carleton.ca\/scs\/2024\/extend-disk-space\/\",\"url\":\"https:\/\/carleton.ca\/scs\/2024\/extend-disk-space\/\",\"name\":\"Extend Linux Disk (disk space) - School of Computer Science\",\"isPartOf\":{\"@id\":\"https:\/\/carleton.ca\/scs\/#website\"},\"datePublished\":\"2024-11-12T19:24:54+00:00\",\"dateModified\":\"2024-11-12T19:24:54+00:00\",\"author\":{\"@id\":\"https:\/\/carleton.ca\/scs\/#\/schema\/person\/165b37967ff02be20bc30ba4ef56e96d\"},\"description\":\"Why extend a disk? What is LVM Partition Check Existing Space Extend Partition using the Script Extend Partition Manually Why extend a disk? Many of our\",\"breadcrumb\":{\"@id\":\"https:\/\/carleton.ca\/scs\/2024\/extend-disk-space\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/carleton.ca\/scs\/2024\/extend-disk-space\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/carleton.ca\/scs\/2024\/extend-disk-space\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/carleton.ca\/scs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Technical Support\",\"item\":\"https:\/\/carleton.ca\/scs\/category\/technicalsupport\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Openstack\",\"item\":\"https:\/\/carleton.ca\/scs\/category\/technicalsupport\/openstack-support\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Extend Linux Disk (disk space)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/carleton.ca\/scs\/#website\",\"url\":\"https:\/\/carleton.ca\/scs\/\",\"name\":\"School of Computer Science\",\"description\":\"Carleton University\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/carleton.ca\/scs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/carleton.ca\/scs\/#\/schema\/person\/165b37967ff02be20bc30ba4ef56e96d\",\"name\":\"andrewpullin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/carleton.ca\/scs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f7e292566dc80625455ee84f24686363?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f7e292566dc80625455ee84f24686363?s=96&d=mm&r=g\",\"caption\":\"andrewpullin\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Extend Linux Disk (disk space) - School of Computer Science","description":"Why extend a disk? What is LVM Partition Check Existing Space Extend Partition using the Script Extend Partition Manually Why extend a disk? Many of our","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/carleton.ca\/scs\/2024\/extend-disk-space\/","twitter_misc":{"Written by":"andrewpullin","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/carleton.ca\/scs\/2024\/extend-disk-space\/","url":"https:\/\/carleton.ca\/scs\/2024\/extend-disk-space\/","name":"Extend Linux Disk (disk space) - School of Computer Science","isPartOf":{"@id":"https:\/\/carleton.ca\/scs\/#website"},"datePublished":"2024-11-12T19:24:54+00:00","dateModified":"2024-11-12T19:24:54+00:00","author":{"@id":"https:\/\/carleton.ca\/scs\/#\/schema\/person\/165b37967ff02be20bc30ba4ef56e96d"},"description":"Why extend a disk? What is LVM Partition Check Existing Space Extend Partition using the Script Extend Partition Manually Why extend a disk? Many of our","breadcrumb":{"@id":"https:\/\/carleton.ca\/scs\/2024\/extend-disk-space\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/carleton.ca\/scs\/2024\/extend-disk-space\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/carleton.ca\/scs\/2024\/extend-disk-space\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/carleton.ca\/scs\/"},{"@type":"ListItem","position":2,"name":"Technical Support","item":"https:\/\/carleton.ca\/scs\/category\/technicalsupport\/"},{"@type":"ListItem","position":3,"name":"Openstack","item":"https:\/\/carleton.ca\/scs\/category\/technicalsupport\/openstack-support\/"},{"@type":"ListItem","position":4,"name":"Extend Linux Disk (disk space)"}]},{"@type":"WebSite","@id":"https:\/\/carleton.ca\/scs\/#website","url":"https:\/\/carleton.ca\/scs\/","name":"School of Computer Science","description":"Carleton University","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/carleton.ca\/scs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/carleton.ca\/scs\/#\/schema\/person\/165b37967ff02be20bc30ba4ef56e96d","name":"andrewpullin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/carleton.ca\/scs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f7e292566dc80625455ee84f24686363?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f7e292566dc80625455ee84f24686363?s=96&d=mm&r=g","caption":"andrewpullin"}}]}},"acf":{"Post Thumbnail Icon":"","Post Thumbnail":false},"_links":{"self":[{"href":"https:\/\/carleton.ca\/scs\/wp-json\/wp\/v2\/posts\/7137"}],"collection":[{"href":"https:\/\/carleton.ca\/scs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/carleton.ca\/scs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/carleton.ca\/scs\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/carleton.ca\/scs\/wp-json\/wp\/v2\/comments?post=7137"}],"version-history":[{"count":4,"href":"https:\/\/carleton.ca\/scs\/wp-json\/wp\/v2\/posts\/7137\/revisions"}],"predecessor-version":[{"id":17815,"href":"https:\/\/carleton.ca\/scs\/wp-json\/wp\/v2\/posts\/7137\/revisions\/17815"}],"wp:attachment":[{"href":"https:\/\/carleton.ca\/scs\/wp-json\/wp\/v2\/media?parent=7137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/carleton.ca\/scs\/wp-json\/wp\/v2\/categories?post=7137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/carleton.ca\/scs\/wp-json\/wp\/v2\/tags?post=7137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}