{"id":486,"date":"2016-05-01T16:57:00","date_gmt":"2016-05-01T08:57:00","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=486"},"modified":"2018-09-05T23:24:27","modified_gmt":"2018-09-05T15:24:27","slug":"how-i-resized-the-file-system-of-my-ubuntu-server-15-10-3-image-to-utilize-the-entire-microsd-card-space-on-my-raspberry-pi-3","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/how-i-resized-the-file-system-of-my-ubuntu-server-15-10-3-image-to-utilize-the-entire-microsd-card-space-on-my-raspberry-pi-3\/","title":{"rendered":"How I resized the file system of my Ubuntu Server 15.10.3 image to utilize the entire microSD card space on my Raspberry Pi 3"},"content":{"rendered":"<p>After <a href=\"http:\/\/www.techcoil.com\/blog\/setting-up-a-lemp-web-server-on-raspberry-pi-3-with-an-ubuntu-server-15-10-3-image-to-host-a-wordpress-website\/\" title=\"Setting up a LEMP web server on Raspberry Pi 3 with an Ubuntu Server 15.10.3 image to host a WordPress website\" target=\"_blank\">setting up a LEMP web server on Raspberry Pi 3 with an Ubuntu Server 15.10.3 image to host my new WordPress website<\/a>, I decided to create some swap space to complement the 1GB ram on my Raspberry Pi 3 in running more services. <\/p>\n<p>When I tried to create a 4GB swap file, the fallocate command complained that there was no space left on my Raspberry Pi 3:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo fallocate -l 4G \/swapfile\r\nfallocate: fallocate failed: No space left on device\r\n<\/pre>\n<p>To ensure that I wouldn't crash my Raspbery Pi 3, I quickly remove <code>\/swapfile<\/code>. <\/p>\n<p>To understand why there was no space to create a 4GB swap file on a Raspberry Pi 3 with a 32GB microSD card, I ran:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndf -h\r\n<\/pre>\n<p>and got the following output: <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nFilesystem      Size  Used Avail Use% Mounted on\r\n\/dev\/root       3.5G  1.5G  2.0G  43% \/\r\ndevtmpfs        459M     0  459M   0% \/dev\r\ntmpfs           463M     0  463M   0% \/dev\/shm\r\ntmpfs           463M  6.2M  457M   2% \/run\r\ntmpfs           5.0M     0  5.0M   0% \/run\/lock\r\ntmpfs           463M     0  463M   0% \/sys\/fs\/cgroup\r\n\/dev\/mmcblk0p1   64M   20M   45M  32% \/boot\r\n<\/pre>\n<p>This told me that my Ubuntu Server 15.10.3 image did not utilize the entire microSD card space from the <a href=\"http:\/\/www.amazon.com\/gp\/product\/B010Q57T02?ie=UTF8&camp=1789&creativeASIN=B010Q57T02&linkCode=xm2&tag=clivsperswebs-20\" title=\"Amazon page for SanDisk Ultra 32GB microSDHC UHS-I Card with Adapter \" target=\"_blank\">SanDisk Ultra 32GB microSDHC card<\/a> on my <a href=\"http:\/\/www.amazon.com\/gp\/product\/B01CD5VC92?ie=UTF8&camp=1789&creativeASIN=B01CD5VC92&linkCode=xm2&tag=clivsperswebs-20\" title=\"Amazon page for Rasberry Pi 3 Model B Mother board\" target=\"_blank\">Raspberry Pi 3 motherboard<\/a>.<\/p>\n<h3>Using GNU parted to resize the file system of my Ubuntu Server 15.10.3 image to utilize the entire microSD card space<\/h3>\n<p>It wouldn't make economical sense when my Raspberry Pi 3 was not using the whole of my 32GB microSD card. Since my Ubuntu Server 15.10.3 image had GNU parted installed, I turned to GNU parted to resize the file system of my Ubuntu Server 15.10.3 image to utilize the entire microSD card space:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo parted\r\n<\/pre>\n<p>Executing the command presented me the following environment, which allowed me to interact with GNU parted.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nGNU Parted 3.2\r\nUsing \/dev\/mmcblk0\r\nWelcome to GNU Parted! Type 'help' to view a list of commands.\r\n(parted) help                                                             \r\n  align-check TYPE N                        check partition N for TYPE(min|opt)\r\n        alignment\r\n  help &#x5B;COMMAND]                           print general help, or help on\r\n        COMMAND\r\n  mklabel,mktable LABEL-TYPE               create a new disklabel (partition\r\n        table)\r\n  mkpart PART-TYPE &#x5B;FS-TYPE] START END     make a partition\r\n  name NUMBER NAME                         name partition NUMBER as NAME\r\n  print &#x5B;devices|free|list,all|NUMBER]     display the partition table,\r\n        available devices, free space, all found partitions, or a particular\r\n        partition\r\n  quit                                     exit program\r\n  rescue START END                         rescue a lost partition near START\r\n        and END\r\n  resizepart NUMBER END                    resize partition NUMBER\r\n  rm NUMBER                                delete partition NUMBER\r\n  select DEVICE                            choose the device to edit\r\n  disk_set FLAG STATE                      change the FLAG on selected device\r\n  disk_toggle &#x5B;FLAG]                       toggle the state of FLAG on selected\r\n        device\r\n  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER\r\n  toggle &#x5B;NUMBER &#x5B;FLAG]]                   toggle the state of FLAG on partition\r\n        NUMBER\r\n  unit UNIT                                set the default unit to UNIT\r\n  version                                  display the version number and\r\n        copyright information of GNU Parted\r\n<\/pre>\n<h3>Viewing the partition table on my microSD card<\/h3>\n<p>I first checked the entries inside the partition table on my microSD card:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n(parted) print   \r\n<\/pre>\n<p>Through the 'print' command, I was presented with the following output:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nModel: SD SL32G (sd\/mmc)\r\nDisk \/dev\/mmcblk0: 31.1GB\r\nSector size (logical\/physical): 512B\/512B\r\nPartition Table: msdos\r\nDisk Flags: \r\n\r\nNumber  Start   End     Size    Type     File system  Flags\r\n 1      1049kB  68.2MB  67.1MB  primary  fat16        boot, lba\r\n 2      68.2MB  3932MB  3864MB  primary  ext4\r\n<\/pre>\n<p>This output told me that I was only utilizing 3864MB of my microSD card for my Ubuntu Server 15.10.3. <\/p>\n<h3>Resizing the ext4 partition<\/h3>\n<p>Since the ext4 partition contains the Ubuntu Server 15.10.3 image, resizing that partition will allow my Ubuntu Server 15.10.3 to utilize the entire microSD card disk space.<\/p>\n<p>To do so, I supplied the following input:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n(parted) resizepart 2                                                     \r\nEnd?  &#x5B;3932MB]? 31.1GB\r\n<\/pre>\n<p>I first supplied the command 'resizepart 2' to tell GNU parted that I wished to resize the ext4 partition. It then replied me with 'End?  [3932MB]?' which I followed up with the string '31.1GB' to indicate that I want it to use the rest of the unallocated space on my microSD card.<\/p>\n<h3>Verifying that my Ubuntu Server 15.10.3 was able to utilize the rest of the unallocated space on my microSD card<\/h3>\n<p>To verify that the ext4 partition had successfully resized, I ran the 'print' command again:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n(parted) print\r\n<\/pre>\n<p>which gave me the following output: <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nModel: SD SL32G (sd\/mmc)\r\nDisk \/dev\/mmcblk0: 31.1GB\r\nSector size (logical\/physical): 512B\/512B\r\nPartition Table: msdos\r\nDisk Flags: \r\n\r\nNumber  Start   End     Size    Type     File system  Flags\r\n 1      1049kB  68.2MB  67.1MB  primary  fat16        boot, lba\r\n 2      68.2MB  31.1GB  31.0GB  primary  ext4\r\n<\/pre>\n<p>Once I saw that the partition had taken more space, I exited the interaction screen with the parted program by typing 'quit'.<\/p>\n<h3>Getting the Ubuntu Server 15.10.3 file system to recognize the partition resize<\/h3>\n<p>Once I am out of the parted interaction screen, I ran the following to see if my root directory contains more space:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndf -h\r\n<\/pre>\n<p>To my dismay, I still saw the same output as before:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nFilesystem      Size  Used Avail Use% Mounted on\r\n\/dev\/root       3.5G  1.5G  2.0G  43% \/\r\ndevtmpfs        459M     0  459M   0% \/dev\r\ntmpfs           463M     0  463M   0% \/dev\/shm\r\ntmpfs           463M  6.2M  457M   2% \/run\r\ntmpfs           5.0M     0  5.0M   0% \/run\/lock\r\ntmpfs           463M     0  463M   0% \/sys\/fs\/cgroup\r\n\/dev\/mmcblk0p1   64M   20M   45M  32% \/boot\r\n<\/pre>\n<p>This told me that GNU parted had not resized the file system to take the additional partition space that had been created. <\/p>\n<p>To get the file system to take the additional partition space that had been created, I ran the following:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo resize2fs \/dev\/mmcblk0p2\r\n<\/pre>\n<p>After the command had completed, I ran <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndf -h\r\n<\/pre>\n<p>and got the following output:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nFilesystem      Size  Used Avail Use% Mounted on\r\n\/dev\/root        29G  1.5G   27G   6% \/\r\ndevtmpfs        459M     0  459M   0% \/dev\r\ntmpfs           463M     0  463M   0% \/dev\/shm\r\ntmpfs           463M  6.2M  457M   2% \/run\r\ntmpfs           5.0M     0  5.0M   0% \/run\/lock\r\ntmpfs           463M     0  463M   0% \/sys\/fs\/cgroup\r\n\/dev\/mmcblk0p1   64M   20M   45M  32% \/boot\r\n<\/pre>\n<p>With that, I was able to continue with the creation of the swapfile to complement the 1GB ram on my Raspberry Pi 3.<\/p>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-7Q\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-7Q&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-7Q&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F486&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>After setting up a LEMP web server on Raspberry Pi 3 with an Ubuntu Server 15.10.3 image to host my new WordPress website, I decided to create some swap space to complement the 1GB ram on my Raspberry Pi 3 in running more services.<\/p>\n<p>When I tried to create a 4GB swap file, the fallocate command complained that there was no space left on my Raspberry Pi 3:<\/p>\n","protected":false},"author":1,"featured_media":1282,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[4],"tags":[387,388,240,308,261,423,195,260],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Ubuntu-Logo.gif","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-7Q","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/486"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=486"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/486\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1282"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}