jhanarato
Posts: 4
Joined: Fri Apr 07, 2017 1:40 am

resize /dev/root

Fri Apr 07, 2017 1:59 am

Hello friends,

Starting with a NOOBS installation on a 8GB sdcard I installed Raspian (Jessie). I don't have much in the way of media, but I still managed to fill it up via apt-get. A friend purchased a new 32GB sdcard and I did the following:
  • Created an img file from the 8GB card with Win32DiskImager
  • Wrote the img file to the 32GB card with Etcher
  • Inserted the 32GB card into my RaspberryPi Model B v3
  • Booted the Pi
  • Logged in via PuTTy - Success!
Then I checked the disk partitions:

Code: Select all

[email protected]:~ $ df -BM
Filesystem     1M-blocks  Used Available Use% Mounted on
/dev/root          6034M 5413M      293M  95% /
devtmpfs            459M    0M      459M   0% /dev
tmpfs               463M    0M      463M   0% /dev/shm
tmpfs               463M    7M      457M   2% /run
tmpfs                 5M    1M        5M   1% /run/lock
tmpfs               463M    0M      463M   0% /sys/fs/cgroup
/dev/mmcblk0p6       66M   21M       46M  31% /boot
tmpfs                93M    0M       93M   0% /run/user/1000
The next step is to expand /dev/root. The usual method is to use sudo raspi-config to utilise the whole disk, but this technique does not work on the newly flashed 32GB disk. fdisk would be the usual route, but it doesn't look like you can resize /dev/root while raspbian is running. I do not have another linux PC, so any options would have to be applicable to a running pi or a windows 7 machine.

Thanks! :-)

ghans
Posts: 7871
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: resize /dev/root

Fri Apr 07, 2017 5:00 am

Download and burn GParted to a CD-ROM. Or to a pendrive. Boot from the pendrive/disk and resize
the second partition.

GParted is very useful for this , but it simply doesn't work under Windows directly.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

User avatar
rpdom
Posts: 14985
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: resize /dev/root

Fri Apr 07, 2017 5:07 am

apt-get leaves behind the files it downloads when you install or upgrade packages. After the process is complete these files aren't needed. You can clear them with "sudo apt-get clean", that should clear out a fair bit of space.

jhanarato
Posts: 4
Joined: Fri Apr 07, 2017 1:40 am

Re: resize /dev/root

Wed Apr 12, 2017 2:00 am

I have downloaded the iso for gparted and installed it on a pendrive. It boots happily into GParted and finds my SD card (/dev/sdd2), no problem. I have a 6.11GiB root partition (/dev/sdd7) and 22.32GiB unallocated space. However, when I try to resize the root partition, it gives me only from min 5639MiB to 6261MiB.

jhanarato
Posts: 4
Joined: Fri Apr 07, 2017 1:40 am

Re: resize /dev/root

Thu Apr 13, 2017 1:20 am

OK, I'll get onto the forums over here:

http://gparted.org/help.php

:-)

salexson
Posts: 4
Joined: Thu Apr 13, 2017 5:44 pm

Re: resize /dev/root

Fri Apr 14, 2017 2:03 am

You can actually resize /dev/root while the Pi is running. I have done it...recently in fact. As with any filesystem resize (except with LVMs) there is some risk, so backup anything important.

For this, I will use the following disk configuration as an example:

Code: Select all

$ df -h
Filesystem                     Size  Used Avail Use% Mounted on
/dev/root                        4G  2.3G  1.7G  58% /
devtmpfs                       483M     0  483M   0% /dev
tmpfs                          487M     0  487M   0% /dev/shm
tmpfs                          487M  7.0M  480M   2% /run
tmpfs                          5.0M     0  5.0M   0% /run/lock
tmpfs                          487M     0  487M   0% /sys/fs/cgroup
/dev/mmcblk0p1                  56M   21M   35M  38% /boot
/dev/mmcblk0p3                  10G     0   10G   0% /extra
With fdisk (targetting your SD card),

Code: Select all

$ fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.25.2).
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/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 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: dos
Disk identifier: 0x000b5098

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1        8192   122879   114688   56M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      122880 19332192 1090209333 4G 83 Linux
/dev/mmcblk0p3      19332193 31116287 20309923 10G Linux
The number above are fabricated for the example, but they are good enough to illustrate the process.

It looks like your /boot partition is not the first partition, so you may need to massage the process a bit, but you should still be able to grow /dev/root as long as there is available space between its partition and the /boot partition

Once the Pi is rebooted, run fdisk against your SD card again. Printing the partition table, you should only see the remaining 2 partitions

Code: Select all

Command (m for help): p
Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 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: dos
Disk identifier: 0x000b5098

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1        8192   122879   114688   56M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      122880 19332192 1090209333 4G 83 Linux
Now, record the start sector of the second partition. In my example, it is '122880'. Once you have recorded it, delete that partition. Once it is deleted, create a new primary partition. Give it partition number 2. Enter the number you recorded for the value of the First sector. Again, in my example, it is '122880'. For the Last sector, the default should be the last sector of the disk (or the last available sector before the next partition). In my example, it is '31116287'. If the default is correct, just hit enter, otherwise enter the value you for the last sector you want to use. Now, write the partition table and exit fdisk.

The OS may cache the partition table, so for good measure, reboot the Pi again. When it reboots, your /dev/root should reflect the additional space on the SD drive.

Code: Select all

$ df -h
Filesystem                     Size  Used Avail Use% Mounted on
/dev/root                       14G  2.3G 11.7G  16% /
devtmpfs                       483M     0  483M   0% /dev
tmpfs                          487M     0  487M   0% /dev/shm
tmpfs                          487M  7.0M  480M   2% /run
tmpfs                          5.0M     0  5.0M   0% /run/lock
tmpfs                          487M     0  487M   0% /sys/fs/cgroup
/dev/mmcblk0p1                  56M   21M   35M  38% /boot
Your data should still be intact. Because you created the "new" partition at the same start sector as the original, it should have left the filesystem untouched. Like I said, though, backup before doing this in case something goes wrong. I will say it has worked for me without issue.

User avatar
rpdom
Posts: 14985
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: resize /dev/root

Fri Apr 14, 2017 7:21 am

salexson wrote:You can actually resize /dev/root while the Pi is running. I have done it...recently in fact. As with any filesystem resize (except with LVMs) there is some risk, so backup anything important.
Which is all well and good (and what raspi-config does for you), but it isn't that simple on a NOOBS installation with multiple partitions and root being on a Logical Partition. It can be done, but it is a lot more involved that your example.

jhanarato
Posts: 4
Joined: Fri Apr 07, 2017 1:40 am

Re: resize /dev/root

Tue Apr 18, 2017 12:45 am

Well I figured it out in the end. Using the gparted live distro I struggled for a little while until I realised that the /dev/root partition was within another partition. Resizing the latter, then the former, everything works. I just gave the /dev/root partition everything remaining on the disk, the other partitions I left at their original sizes.

Thanks again. :-)

J.R.

Return to “Troubleshooting”