How to resize /dev/sda2 without data lost on x86?

I googled and still a bit confused.

All manuals recommend to use fdisk to delete and repartition /dev/sda2
but as far as I know there are data in there - configuration files, packages, etc. So, may be I must use other, non-destructive tools?

I have a 160Gb HDD and just want 10Gb for OpenWRT and packages and 150Gb for file storage.

Also I still struggle to understand where all packages are installed - in root? Or in sda2?
If in root then what is the point of /sda2?

3 Likes

Many thanks! Another stupid question, if I may, sorry:
Do I understand correctly that if I have two partitions,like

Device     Boot Start    End Sectors  Size Id Type
/dev/sda1  *      512  33279   32768   16M 83 Linux
/dev/sda2       33792 246783  212992  104M 83 Linux

It mean that /dev/sda1 contains only bootloader and kernel and mounted as / (root)
while /dev/sda2 contains packages, settings and all user stuff and mounted as /overlay, yet in system I see it mounted to /etc, /tmp and other catalogs?

P.S. And if I want more space for packages I must increase size of /dev/sda2 instead of /dev/sda1?

Can you provide some details about your OpenWrt installation and what issue(s) you're attempting to solve?

1 Like

Sure!
I have OpenWRT deployed on x86 platform, which is ASUS P5QPL-AM (with Integrated Atheros AR813x/AR815x/AR816x (L1E)) for which I had to download kmod-atl1e driver and discrete PCI-Ex1 D-Link Network Card which works just fine out-of the box and requires no further attention.
I have also some outdated like 20 y.o. Intel CPU which model I do not remember exactly and 4Gb DDR2.

I also have 250Gb Samsung SATA HDD to which I've deployed OpenWRT standard image openwrt-23.05.5-x86-64-generic-ext4-combined.img simply by writing it on disk by imageUSB programm (which can recognize disks connected to PC via SATA-to-USB adapter as big USB drives).

Now I am afraid that current partitons will be too small and I just want to setup it like:
01. 10Gb partition for OpenWRT (so that there were always free space for more packages)
02. 240Gb for all other stuff, like files, movies, etc. (I was going to share it via nfs or samba).

The problem is that now I do not undertstand which partirion of OpenWRT to resize - /dev/sda1 with help of this manual [OpenWrt Wiki] Expanding root partition and filesystem or /dev/sda2 where all configs and packages are supposed to be stored, if I am not mistaken.

UPD: Since /dev/sda1 is bootable partition and contains bootable staff, I believe that my choice is to expand /dev/sda2, so that it would looks like:

Device     Boot Start    End Sectors  Size Id Type
/dev/sda1  *      512  33279   32768   16M 83 Linux
/dev/sda2       33792 10Gb  idk  10Gb 83 Linux

If the addition data isn't OpenWRT related, create a sda3 ?

2 Likes

This is what I was going to do. To create sda3 then mount it to /mnt/storage for example and use for movies, files ,etc. But first I want to provide more than enough free space for /dev/sda1 and /dev/sda2 so that my OpenWRT installation would never face lack of free space. I just not sure how to do it properly. Must I increase size of /dev/sda1 (for it seems all packages installed in there) or I must increase /dev/sda2 (for it seems some storage for settings and some packages also).

Is there some reason you believe the default size won't be more than enough?

For example, are you planning to install an extremely large amount of packages?

Also, others may discuss with you the headaches of upgrading after altering the HDD partitions, etc.

I do not plan to install something enormous mostly mc, nfs, v2raya, samba, motion, lighttpd, python3 (and other staff to set up Telegram - bot) and I just want to be sure that I will not run out of space. Because on default setup I once saw in LuCi that 90% of space is occupy. I had to resize root partition by script to avoid lack of free space.
May be I can create partitions in advance, say, on Ubuntu-LiveUSB or Parted-LiveUSB and then deploy grub and other OpenWRT files accordingly to necessary partitions?

P.S. I do not plan any upgrades, because I will not change hardware. This OpenWRT device is planned to work as home-router

OK, cool.

Since you never plan to upgrade the software on your router, you'll have no issues with upgrading.

Your security is another concern. FYI, OpenWrt usually upgrades a full version every ~12-14 months- usually with major security updates.

If you have to copy the OpenWrt image, why the headache of creating the partitions first?

But sure, you can create and copy data to the partitions in any manner you desire. It's an x86_64 machine.

Ummmm...what did you install to cause your space to fill?

Edit:

BTW, you can use https://firmware-selector.openwrt.org to make an image with those packages pre-installed.

1 Like

OK, I understand you. I should not change default partitioning, for it will cause trouble sooner or later.
I do not remember what I installed, but nothing special. it was Midnight Commander and Motion for sure. May be motion video files caused it, but I am not sure. May be some log-files

At least can I give more free space to "Storage" according to this picture


which is occuped for 18%? I believe Temp Space is some kind of SWAP file?

UPD: OpenWrt Firmware Selector

OMG! This is just amazing!!!!

P.S. It would be godlike system if I could not only select packages, but also configure them. For example, I need ffmpeg with H.265 decoding support (so that I can use IP-Camera with H.265) in Motion with support of ffmpeg. I just check some checkboxes and I got it. I hope in future it will be so.

/tmp is RAM.

2 Likes

Thank you. As far as I understand OpenWRT upgrade wipes all storage device and repartition it anew?
In this case maybe I should use for movies, files, etc., separated disk, say, another hard drive for 250Gb?

If the partition layout isn't touched, you should be able to simply recreate the sda3 partition and have the content intact.

A 2nd drive is always safer, from a content point of view.

1 Like

You can.

1 Like

I have 32GB emmc with my R5S. What I did is, I expanded my second partition from original ~100MB to about ~2GB to install extra packages etc. Then used from 5GB to 25GB as an ext4 file system and mounted at /opt. Note that I didn't create any partition for the /opt file system as a re-install would overwrite the partition table. You need to replace /dev/mmcblk1 with correct drive. I am sure there are ways to programmatically figure out the actual drive...

  1. Put this in /etc/init.d/mount_opt
  2. chmod +x /etc/init.d/mount_opt
  3. /etc/init.d/mount_opt enable
  4. /etc/init.d/mount_opt start
#!/bin/sh /etc/rc.common
START=99

start() {
    mkdir -p /opt
    FS_OFFSET=$((5 * 1024 * 1024 * 1024))
    FS_SIZE=$((20 * 1024 * 1024 * 1024))
    losetup -o $FS_OFFSET --sizelimit $FS_SIZE /dev/loop9 /dev/mmcblk1
    mount /dev/loop9 /opt
}
1 Like

Thank you. I think I wrote wrong sentence. I mean not configuring, but recompiling with necessary settings. For example I want to recompile ffmpeg with support of H.265 Codec and also recompile Motion package with support of ffmpeg. I think your link about a bit different things.

I also found this [OpenWrt Wiki] Using the SDK does it mean that I can recompile motion and ffmpeg on my current working OpenWRT without recompiling whole system? It would be great!

You can cross compile on an x86_64. I know that's the platform you're using, but I want to clarify that OpenWrt isn't self hosting, so you cannot use the OpenWrt OS to do so.

1 Like

Thank you. How do I later use theese cross-compiled packages on my OpenWRT? I just copy-paste binaries?

You'd install the package(s) you created.

1 Like