Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Expand disk in Linux</title>
<link rel="stylesheet" href="https://stackedit.io/res-min/themes/base.css" />
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
</head>
<body><div class="container"><h1 id="expand-disk-in-linux">Expand disk in Linux</h1>
<p>If we don’t have enogh space on our virtual machine, we can ask more. After the request, the administrator will extend your HDD, but you have to rescan and extend it manually on your machine. You will need root access to do it.</p>
<ol>
<li><p>Ask the administrator for more space. After they had given more, do the following steps. </p></li>
<li><p>You can check how much free space are left on your machine (on debian based distributions like ubuntu) with the <strong><code>df -h</code></strong> command. As you can see, here we need more space on <strong>/</strong> so we will extend the <strong>/dev/mapper/cloud–x–vg-root</strong>.</p>
<blockquote>
  <table>
<thead>
<tr>
  <th>Filesystem</th>
  <th>Size</th>
  <th>Used</th>
  <th>Avail</th>
  <th>Use%</th>
  <th>Mounted on</th>
</tr>
</thead>
<tbody><tr>
  <td><strong>/dev/mapper/cloud–x–vg-root</strong></td>
  <td>39G</td>
  <td>37G</td>
  <td>65M</td>
  <td>100%</td>
  <td><strong>/</strong></td>
</tr>
<tr>
  <td>none</td>
  <td>4.0K</td>
  <td>0</td>
  <td>4.0K</td>
  <td>0%</td>
  <td>/sys/fs/cgroup</td>
</tr>
<tr>
  <td>udev</td>
  <td>487M</td>
  <td>4.0K</td>
  <td>487M</td>
  <td>1%</td>
  <td>/dev</td>
</tr>
<tr>
  <td>tmpfs</td>
  <td>100M</td>
  <td>368K</td>
  <td>100M</td>
  <td>1%</td>
  <td>/run</td>
</tr>
<tr>
  <td>none</td>
  <td>5.0M</td>
  <td>0</td>
  <td>5.0M</td>
  <td>0%</td>
  <td>/run/lock</td>
</tr>
<tr>
  <td>none</td>
  <td>498M</td>
  <td>0</td>
  <td>498M</td>
  <td>0%</td>
  <td>/run/shm</td>
</tr>
<tr>
  <td>none</td>
  <td>100M</td>
  <td>0</td>
  <td>100M</td>
  <td>0%</td>
  <td>/run/user</td>
</tr>
<tr>
  <td>/dev/vda1</td>
  <td>236M</td>
  <td>37M</td>
  <td>187M</td>
  <td>17%</td>
  <td>/boot</td>
</tr>
</tbody></table>
</blockquote></li>
<li><p>List logical volumes and find the <strong>VG Name</strong> (volume group name) of the <strong>/dev/mapper/cloud–x–vg-root</strong>: <br>
<code>lvdisplay</code></p>
<blockquote>
  <p>— Logical volume — <br>
  <em>LV Path                /dev/cloud-x-vg/root</em> <br>
  LV Name                root <br>
  <strong>VG Name                cloud-x-vg</strong> <br>
  LV UUID                xlGizo-eVyj-aqRn-Us7d-BRzj-dsKW-U6kp0F <br>
  LV Write Access        read/write <br>
  LV Creation host, time cloud-x, 2014-07-31 13:17:53 +0200 <br>
  LV Status              available <br>
  <code>#</code> open                 1 <br>
  LV Size                38.76 GiB <br>
  Current LE             9923 <br>
  Segments               2 <br>
  Allocation             inherit <br>
  Read ahead sectors     auto <br>
  <code>-</code> currently set to     256 <br>
  Block device           252:0</p>
</blockquote></li>
<li><p>List phisical volumes to get the <strong>PV Name</strong> (partition name) of the <strong>cloud-x-vg</strong> volume group: <br>
<code>pvdisplay</code></p>
<blockquote>
  <p>— Physical volume — <br>
  <strong>PV Name               /dev/vda5</strong> <br>
  <em>VG Name               cloud-x-vg</em> <br>
  PV Size               39.76 GiB / not usable 2.00 MiB <br>
  Allocatable           yes (but full) <br>
  PE Size               4.00 MiB <br>
  Total PE              10178 <br>
  Free PE               0 <br>
  Allocated PE          10178 <br>
  PV UUID               JDp5TP-PHjT-Cgwk-MN4h-iAnk-9dfT-lYoldd</p>
</blockquote></li>
<li><p>With using fdisk, list the partitions: <br>
<strong><code>fdisk /dev/vda</code></strong> and press <strong>p</strong>. This will show something similar: </p>
<blockquote>
  <table>
<thead>
<tr>
  <th>Device</th>
  <th>Boot</th>
  <th>Start</th>
  <th>End</th>
  <th>Blocks</th>
  <th>Id</th>
  <th>System</th>
</tr>
</thead>
<tbody><tr>
  <td>/dev/vda1</td>
  <td>*</td>
  <td>2048</td>
  <td>499711</td>
  <td>248832</td>
  <td>83</td>
  <td>Linux</td>
</tr>
<tr>
  <td>/dev/vda2</td>
  <td></td>
  <td>501758</td>
  <td>83884031</td>
  <td>41691137</td>
  <td>5</td>
  <td>Extended</td>
</tr>
<tr>
  <td>/dev/vda5</td>
  <td></td>
  <td>501760</td>
  <td>83884031</td>
  <td>41691136</td>
  <td>8e</td>
  <td>Linux LVM</td>
</tr>
</tbody></table>
</blockquote>
<p>You can see, the <strong>/dev/vda5</strong> is in the <strong>/dev/vda2</strong> Extended partition. To resize it, we have to recreate the Extended.</p></li>
<li><p>Delete the Extended partition:  <br>
Press <strong>d</strong> and the number of the partition. Here the extended partition is <strong>vda2</strong> so press <strong>2</strong>.</p></li>
<li><p>Create extended partition:  <br>
Press <strong>n</strong> to create new partition. Type <strong>e</strong> to choose extended type. Set partition number - the same as you deleted above: <strong>2</strong>. You can use the default starting and ending sector.</p></li>
<li><p>Create logical partition:  <br>
Press <strong>n</strong> to create new partition. Type <strong>l</strong> to choose logical type. Set partition number - the same as the Linux LVM (vda5) has above: <strong>5</strong>. You can use the default starting and ending sector.</p></li>
<li><p>Change the logical partition’s type:  <br>
Press <strong>t</strong> to change type. Set the logical partition’s number: <strong>5</strong> (vda5). Type <strong>8e</strong> to choose Linux LVM type. ( To show the full list, press L ).</p></li>
<li><p>Save and exit: Press <strong>w</strong>. <br>
If you list the partitions again, you will see the difference:</p>
<blockquote>
  <table>
<thead>
<tr>
  <th>Device</th>
  <th>Boot</th>
  <th>Start</th>
  <th>End</th>
  <th>Blocks</th>
  <th>Id</th>
  <th>System</th>
</tr>
</thead>
<tbody><tr>
  <td>/dev/vda1</td>
  <td>*</td>
  <td>2048</td>
  <td>499711</td>
  <td>248832</td>
  <td>83</td>
  <td>Linux</td>
</tr>
<tr>
  <td>/dev/vda2</td>
  <td></td>
  <td>499712</td>
  <td>89338673</td>
  <td><strong>44419481</strong></td>
  <td>5</td>
  <td>Extended</td>
</tr>
<tr>
  <td>/dev/vda5</td>
  <td></td>
  <td>501760</td>
  <td>89338673</td>
  <td><strong>44418457</strong></td>
  <td>8e</td>
  <td>Linux LVM</td>
</tr>
</tbody></table>
</blockquote></li>
<li><p>Reread partition table: <br>
<code>partprobe  -s /dev/vda</code></p>
<blockquote>
  <p>Physical volume “/dev/vda5” changed <br>
  1 physical volume(s) resized / 0 physical volume(s) not resized</p>
</blockquote></li>
<li><p>Resize logical partition <br>
<code>pvresize /dev/vda5</code></p>
<blockquote>
  <p>Physical volume “/dev/vda5” changed <br>
  1 physical volume(s) resized / 0 physical volume(s) not resized</p>
</blockquote></li>
<li><p>Check Free PE / Size: <br>
<code>vgdisplay</code><br> <br>
It shows:</p>
<blockquote>
  <p></p>
  
  <table>
<thead>
<tr>
  <th>Free  PE / Size</th>
  <th>666 / <strong>2.60 GiB</strong></th>
</tr>
</thead>
</table>
  
  <p></p>
</blockquote></li>
<li><p>Extend LVM:  <br>
<code>lvextend -L</code>+<strong>2.6G</strong><code>/dev/mapper/cloud--x--vg-root</code></p>
<blockquote>
  <p>Rounding size to boundary between physical extents: 2.60 GiB <br>
  Extending logical volume root to 41.36 GiB <br>
  Logical volume root successfully resized</p>
</blockquote></li>
<li><p>Finally, resize filesystem: <br>
<code>resize2fs /dev/mapper/cloud--x--vg-root</code></p>
<blockquote>
  <p>resize2fs 1.42.9 (4-Feb-2014) <br>
  Filesystem at /dev/mapper/cloud–x–vg-root is mounted on /; on-line resizing required <br>
  old_desc_blocks = 3, new_desc_blocks = 3 <br>
  The filesystem on /dev/mapper/cloud–x–vg-root is now 10843136 blocks long.</p>
</blockquote></li>
</ol>
<p>The <strong><code>df -h</code></strong> will show now some free space on your <strong>/</strong>:</p>
<blockquote>
  <table>
<thead>
<tr>
  <th>Filesystem</th>
  <th>Size</th>
  <th>Used</th>
  <th>Avail</th>
  <th>Use%</th>
  <th>Mounted on</th>
</tr>
</thead>
<tbody><tr>
  <td><strong>/dev/mapper/cloud–x–vg-root</strong></td>
  <td><strong>41G</strong></td>
  <td>37G</td>
  <td><strong>2.6G</strong></td>
  <td><strong>94%</strong></td>
  <td><strong>/</strong></td>
</tr>
<tr>
  <td>none</td>
  <td>4.0K</td>
  <td>0</td>
  <td>4.0K</td>
  <td>0%</td>
  <td>/sys/fs/cgroup</td>
</tr>
<tr>
  <td>udev</td>
  <td>487M</td>
  <td>4.0K</td>
  <td>487M</td>
  <td>1%</td>
  <td>/dev</td>
</tr>
<tr>
  <td>tmpfs</td>
  <td>100M</td>
  <td>368K</td>
  <td>100M</td>
  <td>1%</td>
  <td>/run</td>
</tr>
<tr>
  <td>none</td>
  <td>5.0M</td>
  <td>0</td>
  <td>5.0M</td>
  <td>0%</td>
  <td>/run/lock</td>
</tr>
<tr>
  <td>none</td>
  <td>498M</td>
  <td>0</td>
  <td>498M</td>
  <td>0%</td>
  <td>/run/shm</td>
</tr>
<tr>
  <td>none</td>
  <td>100M</td>
  <td>0</td>
  <td>100M</td>
  <td>0%</td>
  <td>/run/user</td>
</tr>
<tr>
  <td>/dev/vda1</td>
  <td>236M</td>
  <td>37M</td>
  <td>187M</td>
  <td>17%</td>
  <td>/boot</td>
</tr>
</tbody></table>
</blockquote></div></body>
</html>
Output 300px

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers