Solved - Resize Root Filesystem (Xenial)
#1
Information 
This is for those less familiar with Linux, or running Linux from an SD card.
When you flash Ubuntu Xenial onto an SD card, the root filesystem size is only big enough to fit the operating system.
This is intentional; to keep the size of the image file as small as possible, making it quicker to download and flash to any size SD card (within reason).
After flashing the sd card and booting up for the first time, log in and do the following to expand the root filesystem by following these instructions.
There's a lot of code below, but the whole process took me less than 2 minutes, and you should be able to safely accept the default response to all prompts.

1. Fix the partition table to reflect the size of the SD card:
Code:
[email protected]:~$ sudo parted -l
Warning: Not all of the space available to /dev/mmcblk1 appears to be used, you
can fix the GPT to use all of the space (an extra 60332032 blocks) or continue
with the current setting?
Fix/Ignore? F                                                            
Model: SD 5&DRP (sd/mmc)
Disk /dev/mmcblk1: 32.1GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name       Flags
1      32.8kB  4129kB  4096kB               loader1
2      4129kB  4194kB  65.5kB               reserved1
3      4194kB  8389kB  4194kB               reserved2
4      8389kB  12.6MB  4194kB               loader2
5      12.6MB  16.8MB  4194kB               atf
6      16.8MB  134MB   117MB   fat16        boot       legacy_boot, msftdata
7      134MB   1208MB  1074MB  ext4         root

2. Increase the root partition size:
Code:
[email protected]:~$ sudo fdisk /dev/mmcblk1

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/mmcblk1: 29.9 GiB, 32099008512 bytes, 62693376 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 062EE0ED-2FD5-4D89-B424-771CB4465BD4

Device          Start     End Sectors  Size Type
/dev/mmcblk1p1     64    8063    8000  3.9M Linux filesystem
/dev/mmcblk1p2   8064    8191     128   64K Linux filesystem
/dev/mmcblk1p3   8192   16383    8192    4M Linux filesystem
/dev/mmcblk1p4  16384   24575    8192    4M Linux filesystem
/dev/mmcblk1p5  24576   32767    8192    4M Linux filesystem
/dev/mmcblk1p6  32768  262143  229376  112M Microsoft basic data
/dev/mmcblk1p7 262144 2359295 2097152    1G Linux filesystem

Command (m for help): d
Partition number (1-7, default 7):

Partition 7 has been deleted.

Command (m for help): n
Partition number (7-128, default 7):
First sector (262144-62693342, default 262144):
Last sector, +sectors or +size{K,M,G,T,P} (262144-62693342, default 62693342):

Created a new partition 7 of type 'Linux filesystem' and of size 29.8 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

3. Tell the kernel the partition table has changed:
Code:
[email protected]:~$ sudo partprobe /dev/mmcblk1


4. Resize the root filesystem to fill the partition:
Code:
[email protected]:~$ sudo resize2fs /dev/mmcblk1p7
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mmcblk1p7 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/mmcblk1p7 is now 7803899 (4k) blocks long.

[email protected]:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            459M     0  459M   0% /dev
tmpfs            93M  3.9M   89M   5% /run
/dev/mmcblk1p7   30G  769M   28G   3% /
tmpfs           462M     0  462M   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           462M     0  462M   0% /sys/fs/cgroup
/dev/mmcblk1p6  100M   22M   79M  22% /boot/efi

Reboot and you're done!
...but don't forget to change the default password from rock64  Rolleyes
  Reply
#2
great idea, posting this.When I first started playing with the RPI3, I spent a couple of hours googling, untill I found this.

For those that like using a GUI ... I will list a alternative way to do this ......

First, from the terminal, type ...

sudo apt-get install gparted

I am using a Xenial Mate image, about a week old. When I first tried this I got a error message. If you get a error message when you try this, do the following ...

in the Welcome window that opens when you start Xenial up, click on the software button ( if you closed the welcome window, you can re-open it, in the system window ...

clciking on the software window opens the software boutique window. Across the top are a row of icons ...

click the last icon in the row, looks like a wrench, called fixes ...

scroll down to the last section, broken packages.

clcik both buttons, the configure interupted packages button first (clcik the show terminal commands box, to see what the system is doing ...

Once you do these fixes, now type ...

sudo apt-get install gparted

once this is done, gparted is installed ...

to run it, go to the system menu, and select administration .. there you will see gparted .. select it

once gparted opens, you will see all the partitions. .. the last one, in grey, is unallocated. just to the left of that, is the partition, you will want to expand, to use the unallocated space.

right click on the partition you want to expand (it should be just to the left of the unallocated space, should be the largest partition, except for the unallocated space, and should be yellow and white). when you right click, choose resize/move.

in the new window that opens, place your cursor at the end of the yellow/white partition ..where there is a black arrow pointing right. when you place your cursor there,, it changes to a left - right arrow cursor. clcik, and drag to the right, expanding the yellow/white partition, into the grey partition.

then, clcik the resize button.

one more step. you have told gparted what you want to do, but you now need to apply the changes, to do this click the check mark button, at the top(last button, in the top row of buttons).

Click apply, when it asks you if you are sure. depending on the size of the sd card, this could take a couple of minutes

When a dialog box comes up, and says "all operations succesfully completed" you are done.

Note both ways work, neither is better or worse then the other. Just two diffrent ways to accomplish the same task.

(I tried to write astep by step guide. If I missed a step, let me know, I will edit to fix .. thank you).

Jake
  Reply
#3
Can you just use: `resize_rootfs.sh` script? Smile
Homepage: https://ayufan.eu

Releases:
Rock/Pro 64/Pinebook Pro: LinuxChromium OS
So/Pine A64/Pinebook: LinuxAndroid 6.0Android 7.1

Buy me a Beer
  Reply
#4
(08-28-2017, 07:05 AM)ayufan Wrote: Can you just use: `resize_rootfs.sh` script? Smile

Umm, yes, now that you mention it.
I had no idea it existed, but now I see it lives under /usr/local/sbin/resize_rootfs.sh

This would be really helpful to know when starting out.
Perhaps it could be added to the Wiki somewhere? 

Thanks.
  Reply
#5
................................................................................................................................................................
can you make it run when it boots the first time?
I spent a lot of time to mount the unallocated space to /home.
  Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
Question HDD filesystem corruption at reboot / poweroff (DietPi) WrongWorld 1 157 02-11-2019, 04:00 PM
Last Post: WrongWorld
  Repair corrupt root filesystem on emmc David82 1 436 01-31-2019, 01:11 PM
Last Post: Tozzi
  [solved] Unable to start X Osiander 8 2,292 10-03-2018, 03:54 AM
Last Post: jovval
  Rock64: Debian root fs on software RAID1 of eMMC and microSD - is installing it the s jovval 2 305 08-03-2018, 12:33 PM
Last Post: jovval
  Display limited to 800x600 [SOLVED] Averell 15 1,468 07-28-2018, 05:45 AM
Last Post: ab1jx
  If you've messed up your eMMC Card - Solved gregb49 11 1,797 07-11-2018, 02:08 PM
Last Post: gregb49
  Xenial Mate + Emmc Guettt 2 414 05-31-2018, 02:49 AM
Last Post: pas059
  Any reason why ntp time is 6 minutes slow (Solved) Rocklobster 1 223 05-29-2018, 05:27 AM
Last Post: Rocklobster
  compiling meteor on xenial-minimal-rock64-0.5.15-136-armhf.img.xz maudy 0 306 05-02-2018, 05:35 PM
Last Post: maudy
  [Solved] Open VPN +Wi-Fi hotspot - Debian S3phi40T 1 500 05-01-2018, 05:51 AM
Last Post: S3phi40T

Forum Jump:


Users browsing this thread: 1 Guest(s)