I'm having trouble automating the installation of OpenWrt on my computer

While I can do it just fine with the help of the tools: fdisk and fs2desk, automating it is kind of tricky.

IDK if it's necessarily the case, but It seems that I should align the second partition with the end of the first one when resizing it or else the OS just keeps rebooting in loops.

Since parted doesn't respect that type of alignment, I had to fdisk and type the end address of the 1st partition (/boot), I don't how to automate that without risking the whole instalation going wrong: old versions of tools print things differently, so grep is not going to cut it.

I'm a noob when it comes to Drives, please suggest some options to me.

Also, I wonder if it's possible to just chroot into OpenWrt and install all packages without having to boot into it? maybe I'll try to do that in the future.

Installation script

#!/bin/bash

driveName="/dev/sda";
partitionNumber=2
partitionName="${driveName}${partitionNumber}";

url="https://downloads.openwrt.org/releases/23.05.3/targets/x86/64/openwrt-23.05.3-x86-64-generic-ext4-combined.img.gz";
# url="https://downloads.openwrt.org/releases/22.03.6/targets/x86/64/openwrt-22.03.6-x86-64-generic-ext4-combined.img.gz";

wget -O openwrt.img.gz $url
gzip -d openwrt.img.gz

dd if=./openwrt.img of=/dev/sda bs=1MB

fdisk $driveName # manually resizing the `/` parition

## OpenWrt doesn't like this
# startSector=$(fdisk -l $driveName | grep $partitionName | awk '{print $2}');
# echo "start => ${startSector}s"
# parted $driveName rm $partitionNumber
# parted $driveName mkpart primary ext4 ${startSector}s 10GB
# fs.ext4 $partitionName

e2fsck -f $partitionName
resize2fs $partitionName

mkdir -p /media/data
mount $partitionName /media/data
cp $(dirname $0)/openwrt-post-installer.sh  /media/data
umount $partitionName /media/data

what are you trying to automate, the one command required to write a combined image onto a HDD/SSD/NVME ?

Yes, I guess.

While I can do it just fine with the help of the tools: fdisk and fs2desk, automating it is kind of tricky.

IDK if it's necessarily the case, but It seems that I should align the second partition with the end of the first one when resizing it or else the OS just keeps rebooting in loops.

Since parted doesn't respect that type of alignment, I had to fdisk and type the end address of the 1st partition (/boot), I don't how to automate that without risking the whole instalation going wrong: old versions of tools print things differently, so grep is not going to cut it.

I'm a noob when it comes to Drives, please suggest some options to me.

Also, I wonder if it's possible to just chroot into OpenWrt and install all packages without having to boot into it? maybe I'll try to do that in the future.

Installation script

#!/bin/bash

driveName="/dev/sda";
partitionNumber=2
partitionName="${driveName}${partitionNumber}";

url="https://downloads.openwrt.org/releases/23.05.3/targets/x86/64/openwrt-23.05.3-x86-64-generic-ext4-combined.img.gz";
# url="https://downloads.openwrt.org/releases/22.03.6/targets/x86/64/openwrt-22.03.6-x86-64-generic-ext4-combined.img.gz";

wget -O openwrt.img.gz $url
gzip -d openwrt.img.gz

dd if=./openwrt.img of=/dev/sda bs=1MB

fdisk $driveName # manually resizing the `/` parition

## OpenWrt doesn't like this
# startSector=$(fdisk -l $driveName | grep $partitionName | awk '{print $2}');
# echo "start => ${startSector}s"
# parted $driveName rm $partitionNumber
# parted $driveName mkpart primary ext4 ${startSector}s 10GB
# fs.ext4 $partitionName

e2fsck -f $partitionName
resize2fs $partitionName

mkdir -p /media/data
mount $partitionName /media/data
cp $(dirname $0)/openwrt-post-installer.sh  /media/data
umount $partitionName /media/data

Here's a one liner for the wget and dd

But I'd have had two Openwrt installs, one I never touch, for recovery, and the one I use, or even three, and alternate.

How does one close/remove a topic? [scratch this], this platform is confusing.

Perhaps I'll just install openwrt + openwrt + debian, and copy (dd) the clean one on top of the bad one. Debian for the grub.

But automation is my 1st-class citizen.

While I can do it just fine with the help of the tools: fdisk and fs2desk, automating it is kind of tricky.

IDK if it's necessarily the case, but It seems that I should align the second partition with the end of the first one when resizing it or else the OS just keeps rebooting in loops.

Since parted doesn't respect that type of alignment, I had to fdisk and type the end address of the 1st partition (/boot), I don't how to automate that without risking the whole instalation going wrong: old versions of tools print things differently, so grep is not going to cut it.

I'm a noob when it comes to Drives, please suggest some options to me.

Also, I wonder if it's possible to just chroot into OpenWrt and install all packages without having to boot into it? maybe I'll try to do that in the future.

Installation script

#!/bin/bash

driveName="/dev/sda";
partitionNumber=2
partitionName="${driveName}${partitionNumber}";

url="https://downloads.openwrt.org/releases/23.05.3/targets/x86/64/openwrt-23.05.3-x86-64-generic-ext4-combined.img.gz";
# url="https://downloads.openwrt.org/releases/22.03.6/targets/x86/64/openwrt-22.03.6-x86-64-generic-ext4-combined.img.gz";

wget -O openwrt.img.gz $url
gzip -d openwrt.img.gz

dd if=./openwrt.img of=/dev/sda bs=1MB

fdisk $driveName # manually resizing the `/` parition

## OpenWrt doesn't like this
# startSector=$(fdisk -l $driveName | grep $partitionName | awk '{print $2}');
# echo "start => ${startSector}s"
# parted $driveName rm $partitionNumber
# parted $driveName mkpart primary ext4 ${startSector}s 10GB
# fs.ext4 $partitionName

e2fsck -f $partitionName
resize2fs $partitionName

mkdir -p /media/data
mount $partitionName /media/data
cp $(dirname $0)/openwrt-post-installer.sh  /media/data
umount $partitionName /media/data

Why dont you just resize disk image, then resize partition with same parted?

Not sure if it helps wasting time automating one time tasks.

I have no idea how to do it and I'm not sure what difference would that make.

It would be a one-time task if OpenWrt was backed by some giant company. Quircks are all over the place, I'm yet to make a backup script after automating the installation.

You do first install manually then write script for memories? Like how automation works if you dont trust your own crystal ball.

It will not change filesystem guid?

Sure, OpenWrt is a bit of a different animal than other OS's... but, given the way you have been approaching OpenWrt, I suspect that most of the 'quirks' are actually user errors. These are typically the result of one or more of the following:

  • not reading the documentation
  • lack of understanding of how OpenWrt works
  • lack of understanding of how and why OpenWrt is different than other Linux distros
  • Faulty configuration elements due to the above and/or incomplete understanding of the network stack
  • Incorrect assumptions and/or expectations about what the OS does.

I would recommend that you go back to first principles and make targeted changes one at a time, testing as you go. Do this only after you read the documentation and search the forum for similar topics. If you don't understand something, or you'd like input about how to achieve something, ask us before going neck deep in something that you don't fully understand. And critically, ensure that you have a complete understanding of your goals in such a way as you can concisely explain them to us.

Don't tell me you don't have scripts for automating tasks or at least aliases in your shell config!

Sure, I don't see how that prevents automation from being useful! unless you want me to read about every existing scenario before doing anything.

Maybe you can describe to us what you are trying to do with OpenWrt and what automation tools you need and why.

Automation depends very much on what tasks you need to... given that most of what you've asked about thus far can be done with a one-line command, automating it would be as simple as putting that in a script. But again, it's not really clear at any scale what you really want to achieve here.

I dont think H Ford built assembly lines pointlessly then understand Aw, snap, lets put cheap motor coaches on it.

For Installation

  • copying the img to disk
  • resizing the / partition (I had problem automating the alignment)
  • chroot into it and do firther setup
  • copying the installation to an img as a backup

(maybe the backup is more important than the installation)

I don't think I'm stupid, this is so useful and not as simple as a one-liner.