How do you expand the root partition?

  • Platform information:
    • Hardware: Raspberry Pi 3
    • OS: OpenHABian V1.4 (Raspbian Stretch)
    • openHAB version: 2.2
  • Issue of the topic: Copied disk image from 8 Gb Sd card to 16 Gb SD card. How do you extend the root partition to take advantage of the extra space on the larger SD card?

This is easy to do with raspi-config but that’s unavailable in openHABian. openhabian-config doesn’t offer the partition expansion option. It performs the operation during the first installation.

I found lengthy instructions on stackexchange, using fdisk. It involves deleting the root and swap partitions and then creating a new, larger root partition being very careful to set its starting sector to precisely the same one used by the previous root partition. This (hopefully) preserves the contents of the old root partition (i.e. all of the OS and openHAB system).

Is this the recommended way of doing it?

Another suggestion is to use gparted and resize the SD card’s partitions visually. The problem is I don’t have a suitable Linux computer. I only have a Windows PC and the RPi itself.

Any suggestions on how I can expand the partition to take full advantage of the 16 Gb SD card?

1 Like

Mount it ? Set links ?
openHABian does not provide neither raspi-config nor any extension option simply because there is no need for this.
Feel free to install vanilla Raspbian plus openHABian as scripts if you disagree.

Correct me if I’m wrong but the openHAB installation process does perform a partition extension but does not expose this operation as a discrete menu option (whereas raspi-config does).

Normally this is fine because, after the initial installation (and partition extension), there’s no further need to expand the partition. However, as explained in my first post, I do have a need to expand it after copying the disk image from an 8 GB card to a 16 GB card.

It would appear that deleting and recreating the partition (and aligning with the original starting sector) is the solution. However, I’m leery of doing it manually with fdisk (plus resize2fs) so I used GParted Live from a bootable USB flash drive.

Here’s what I did. If I had an existing Linux PC, it would’ve eliminated the need for the first three steps!

  1. I downloaded the GParted Live ISO from here.
  2. I used Rufus to make a bootable USB flash drive and write the ISO.
  3. I directed my laptop to boot from the USB drive and (after responding to a few questions) it booted directly into a desktop running GParted.
  4. The rest was a matter of using GParted to select the correct device (the SD card), resize the partition with a mouse, and apply the change. GParted took care of checking the file system for errors, extending the partition, and expanding the file system. Done!

I inserted the SD card back into the RPi and used df -h to confirm the root partition now occupies the balance of the 16 GB card. All is well (again).

Strictly speaking no, neither openHAB nor openHABian do. The underlying Raspbian does.
Either way, partition extension is not meant to be exposed as a feature to openHABian users because you simply never ever need it, that’s why it isn’t exposed and likely never will be [doing so means WORK for testing, support etc. which is way better spent on other features] .
Note you still can do it, and to expand the root partition is just one of several methods to get what you want (what you want isn’t to extend the partition but to make use of all available storage). Alternatives are to mount the extra space as another partition like I suggested, to backup, reinstall and restore the card, or to simply not use those extra GB (again, strictly speaking, there’s no need for these because openHABian runs well on 8 GB or even less).

1 Like

If you are on a RPi, then go ahead and sudo apt-get install raspi-config and use that.

The big point is that openHABian IS Raspbian so you can install and use raspi-config to do those things there isn’t a menu for.

5 Likes

You’'ll note I said the “openHAB installation process” not “openHAB” nor “openHABian”. Somewhere buried inside that installation script are the OS commands to extend the partition.

I never asked for the partition-extension feature to be ‘exposed’ in openhabian-config only mentioned it wasn’t available. All I asked was for instructions on how to expand the root partition (see title). That’s it, that’s all.

I won’t comment on the content of your final paragraph other than you appear to be in an inexplicably argumentative mood.

Thank you, Rich! I know openHABian V1.4 is based on Raspbian Stretch yet it never dawned on me to just install the raspi-config package. Doh! That would’ve saved me some time for sure! Oh well, it was an interesting little diversion nonetheless.

1 Like

I know this is pretty old, but did you succeed?

I have changed my partition (2) using parted from 8GB to 32GB and it looks ok:

Number  Start   End     Size    Type     File system  Flags
[19:08:52] openhabian@homer:~$ sudo parted -l
Model: TS32GMSA 370 (scsi)
Disk /dev/sda: 32.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  273MB   268MB   primary  fat32        lba
 2      273MB   32.0GB  31.7GB  primary  ext4

However, when I check with df, I get the same result as before the expansion (78%):

[19:14:20] openhabian@homer:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.1G  5.2G  1.6G  78% /
devtmpfs        3.8G     0  3.8G   0% /dev
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           3.9G  1.7M  3.9G   1% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1       253M   54M  199M  22% /boot
tmpfs           793M     0  793M   0% /run/user/1000

So, I assume I did something wrong with parted!?

EDIT:
Never mind - raspi-config fixed it :slight_smile:

/Of course, it doesn’t help matters that Linux has 10M ways to accomplish the same task, some that work on some distros, but not others and vice versa. I also find that many people in forums assume that you know as much as they do and/or are just so arrogant that they just will not provide a noob with enough information to sort it out for themselves, or give you the “WTF are trying to do THAT way” attitude. Those are my main gripes with this Linux environment. It takes HOURS of searching to find answers to simple problems–if you can even find it. I am NOT a “Linux first, foremost, and WTF are you still using Windows?” kind of guy. My job requires me to use/develop in Windows, and I don’t need the agony of trying to figure out another OS from end-to-end. Really frustrating./

Then run openHAB on Windows. Problem solved, right?

1 Like

Just have to put my two cents in.

I setup openhab on an 32G SD card using the openhabian image. Configured everything and decided for reliability I would install an SSD. The smallest I could find was 120Gig. Even though someone stated that openhabian runs fine on an 8Gig filesystem when checking my 32Gig SD card there was about 20% free. That makes me thing that something grows to the filesystem size, or maybe shrinks to the available resources. Better said, it adapts, for some reason, to what’s available. I do not feel that they would expand to just use the space without any good reason. I do not know the reason and I have not heard anyone talk about their filesystem being too large and causing any issues.
Also on an SSD, I have read, the more free space the better due to wearing. So in my maybe flawed logic, having just the first 32Gig of a 120Gig drive used does not make much sense.
I could have setup more partitions but then I would have to figure out what to use them for and if I do a re-install do it all again, unless I installed from an openhabian image directly to the SSD?
What I did and it seems to work well was installed raspi-config and expanded the root partition and all seems well now.

sudo apt-get raspi-config
sudo raspi-config
sudo shutdown -r now