Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RPi OS logic detection #152

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

martignoni
Copy link

@martignoni
Copy link
Author

Should work with Bookworm (and hopefully later Debian versions).

rpi-clone Outdated
if [ -f /etc/os-release ]
rpios=0
rpios_recent=0
if [ -f /etc/os-release ] && [ -f /proc/device-tree/model ]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I see this test should check whether it's a Raspberry HW. Are you sure /proc/device-tree/model is an unique idetifier for a Raspberry HW? /etc/rpi-issue exists on Raspberry OS Builds only.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm rather sure, but your proposition with /etc/rpi-issue is cleaner and easier to understand, I'll change.

rpi-clone Outdated
fi
if ((raspbian)) && [[ "$pretty" == *"buster"* ]]
if ((rpios)) && ((osversion >= 10))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this check for the osversion 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, normally, it should work with later versions of Debian.

- Credits to @framps
@gpongelli
Copy link

hi @martignoni , I was looking to your changes , I've tried them manually and osversion in my case is empty.

those are the result from my raspberry

pi@raspberrypi:~ $ cat /proc/device-tree/model
Raspberry Pi 4 Model B Rev 1.2
 
pi@raspberrypi:~ $ cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux bookworm/sid"
NAME="Raspbian GNU/Linux"
VERSION_CODENAME=bookworm
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

pi@raspberrypi:~ $ cat /etc/rpi-issue 
Raspberry Pi reference 2019-09-26
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 80d486687ea77d31fc3fc13cf3a2f8b464e129be, stage5

as you can see, the /etc/os-version misses the VERSION_ID field .

With the original code, at least the "raspbian" variable is set to 1.

@martignoni
Copy link
Author

Hi @gpongelli,

You'll see that in your case the rpios variable (which replaces variable raspbian) is correctly set to 1.

What you describe is not a problem, since osversion is only used to detect recent versions of RPiOS.

In your case, you've an older release, there's no VERSION_ID in your /etc/os-release, so osversion is empty; the comparison on line 38 evaluates to false, so rpios_recent=0 and your older release is adequately detected.

Recent versions of RPiOS all have a VERSION_ID in their /etc/os-release, so in this case the comparison on line 38 evaluates correctly to true.

@gpongelli
Copy link

Hi @martignoni , I’ve no idea what’s “recent” for you but, as you can see I’m on bookworm, that’s the actual testing release.

I’ve tried today to upgrade (again) over testing and the os-release had not changed.

@martignoni
Copy link
Author

There is a misunderstanding here: I'm speaking of recent releases of RPiOS images.

And my bad: I did not notice that your image was upgraded. For the record, upgrading an RPi image to a new OS version is not recommended and not supported. I assume rpi-clone too is not supported in these cases.

Side note: Debian testing versions never have a VERSION_ID defined.

@gpongelli
Copy link

There is a misunderstanding here: I'm speaking of recent releases of RPiOS images.

And my bad: I did not notice that your image was upgraded. For the record, upgrading an RPi image to a new OS version is not recommended and not supported. I assume rpi-clone too is not supported in these cases.

Even if it’s not recommended, it can be done (and it worked, waiting for official bookworm), so why rpi-clone shouldn’t also be supported ?

@martignoni
Copy link
Author

If you find a way to check for a version number in Debian testing release, I'd be glad to include it in this PR.

@framps
Copy link

framps commented Mar 6, 2023

Not sure what's the purpose of this check. Maybe it's worth to remove this check?

@martignoni
Copy link
Author

This is needed because as of RPiOS Buster (and later), the boot partition size has changed. See

rpi-clone/rpi-clone

Lines 1348 to 1356 in 07f536e

if ((raspbian_buster && p1_size_new == 0 && src_size_sectors[1] < 400000))
then
printf "%-22s : %s\n" "** WARNING **" \
"Your source /boot partition is smaller than the"
printf "%-22s : %s\n" "" \
" Raspbian Buster 256M standard. Consider using"
printf "%-22s : %s\n" "" \
" the '-p 256M' option to avoid /boot clone errors."
fi
and

rpi-clone/rpi-clone

Lines 1609 to 1624 in 07f536e

if ((raspbian_buster && dst_size_sectors[1] < 500000))
then
qprintf "%-22s : %s\n" "** WARNING **" \
"Your destination /boot partition is smaller than the"
qprintf "%-22s : %s\n" "" \
" Raspbian Buster 256M standard. Consider initializing"
if ((n_dst_parts <= 2))
then
qprintf "%-22s : %s\n" "" \
" with '-f' or '-f2' along with the '-p 256M' options."
else
qprintf "%-22s : %s\n" "" \
" destination disk (gparted) with new partition sizes."
fi
qprintf "%-23s:\n" "-----------------------"
fi
.

@gpongelli
Copy link

Hi @martignoni , I've just tested rpi-clone on my rpi and it worked correctly.

The only changes I did had been this one here:

	if ((raspbian)) && [[ "$pretty" == *"buster"* ]]
	then
		raspbian_buster=1
	fi
+	if ((raspbian)) && [[ "$pretty" == *"bookworm"* ]]
+	then
+		raspbian_buster=1
+	fi

this because there's no way to get version 11 with any of following methods:

  • lsb_release -a
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux bookworm/sid
Release:	n/a
Codename:	bookworm
  • cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux bookworm/sid"
NAME="Raspbian GNU/Linux"
VERSION_CODENAME=bookworm
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
  • hostnamectl
 Static hostname: ...
       Icon name: computer
      Machine ID:....
         Boot ID: ....
Operating System: Raspbian GNU/Linux bookworm/sid 
          Kernel: Linux 5.15.84-v7l+
    Architecture: arm

@martignoni
Copy link
Author

Your "fix" would not fix the bug: the problem will occur again when Debian reaches its next version after Bookworm.

@framps
Copy link

framps commented Mar 12, 2023

Agree. Then every new Debian version requires a change in rpi-clone. Wouldn't it make sense to test backwards and not forwards?

@gpongelli
Copy link

gpongelli commented Mar 13, 2023

I know it is not future-proof, but it’s just to demonstrate that rpi-clone works also on upgraded rpi (even not so pure raspbian, because in the past I’ve mixed it with Debian due to more recent sw version needed).

agree with @framps about reversing the detection logic

edit:
To address future boot changes other than the one already in place (or any os changes that impacts rpi-clone), a more correct check could be done parsing history/release table in webpages like this one or this one through an external script.

@framps
Copy link

framps commented Mar 13, 2023

a more correct check could be done parsing history/release table in webpages

I agree. That's the more general approach. But this creates a dependency of rpi-clone on an existing network connection I don't like.

@martignoni
Copy link
Author

Wouldn't it make sense to test backwards and not forwards?

Not sure I understand, can you elaborate?

@framps
Copy link

framps commented Mar 13, 2023

As @gpongelli wrote here he added a new if statement to set raspibian_buster. This will have to be done for every new release. Why don't we just negate the test and assume raspbian_buster is 1 and reset it to zero for older releases. They will not change any more 😉

@martignoni
Copy link
Author

Here are the PRETTY_NAMEs for all Raspbian/RPiOS supported releases:

32bit

PRETTY_NAME="Raspbian GNU/Linux 7 (wheezy)"
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"

64bit

PRETTY_NAME="Debian GNU/Linux 10 (buster)"
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"

For (unsupported) testing/sid releases, the PRETTY_NAME does not have any number and no VERSION_ID, as already said before. A few examples (we cannot exclude that some adventurous rpi-clone user has updated their official RPiOS buster version to a testing bullseye one):

32bit

PRETTY_NAME="Raspbian GNU/Linux bookworm/sid"
PRETTY_NAME="Raspbian GNU/Linux bullseye/sid"

64bit

PRETTY_NAME="Debian GNU/Linux bullseye/sid"
PRETTY_NAME="Debian GNU/Linux bookworm/sid"

We can conclude that for the test to work also for unsupported versions, we've to test whether the PRETTY_NAME contains either "wheezy", "jessie" or "stretch", and conclude that in this case this is not a recent version.

This (not as elegant as actual PR) bit of code would work. Any comment welcome: bash is not my first language 😊

rpios=0
rpios_recent=0
if [ -f /etc/os-release ]
then
  osversion=`cat /etc/os-release | grep PRETTY | cut -d'"' -f2`
  osversion=${osversion##* } # Remove everything before last space
  osversion=`echo ${osversion} | cut -d"(" -f2 | cut -d")" -f1` # Remove parens if needed
  osversion=${osversion%/*} # Remove everything after last slash
  if [[ -e /etc/rpi-issue ]]; then
    rpios=1
  fi
  if ((rpios)) && !([[ "${osversion}" = "wheezy" ]] || [[ "${osversion}" = "jessie" ]] || [[ "${osversion}" = "stretch" ]] ); then
    rpios_recent=1
  fi
fi

@framps
Copy link

framps commented Mar 15, 2023

I like regex 😄

rpios=0
rpios_recent=0

if [[ -f /etc/os-release ]]; then
   if [[ -f /etc/rpi-issue ]]; then
      rpios=1
   fi
   pretty="$(grep PRETTY /etc/os-release)"
   if ((rpios)) && [[ ! "$pretty" =~ wheezy|jessie|stretch ]]; then
      rpios_recent=1
   fi
fi

- Works for unsupported RPiOS versions (i.e. RPiOS updated to testing/sid)
- Once again, credits to @framps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recent RPi OS version aren't correctly detected
3 participants