Extending the Rollback Logic
Relevant source files
The following files were used as context for generating this wiki page:
The purpose of extending the rollback logic within the safe64switch project is to ensure system stability when transitioning a Raspberry Pi from a 32-bit to a 64-bit kernel. The current implementation focuses on preemptive safety by creating backups of critical configuration files before modifying the boot environment. This allows for manual or scripted restoration should the 64-bit environment fail to initialize or perform as expected.
The scope of this logic involves hardware verification, file system state preservation, and atomic configuration updates. By backing up /boot/config.txt, the system maintains a known-good state that can be restored to disable the arm_64bit flag and return the system to its original 32-bit operating mode.
System Verification and Safety Checks
Before any modification or backup occurs, the system performs environment validation to prevent execution on unsupported hardware, which serves as the first layer of the "safe" switch logic.
Hardware Validation
The script checks the /proc/device-tree/model to confirm the host is a Raspberry Pi. If this check fails, the process terminates immediately to prevent corrupting non-Pi configuration files.
The flow ensures that configuration changes are only applied to compatible systems.
Sources: safe64.sh:13-17
Configuration State Preservation
The core of the rollback capability lies in the preservation of the original boot configuration. This is handled by creating a copy of the configuration file before any append operations are performed.
Backup Mechanism
The project implements a simple but effective backup strategy by copying the production configuration to a backup file.
| Component | Path | Description |
|---|---|---|
| Source Configuration | /boot/config.txt | The active boot configuration for the Raspberry Pi. |
| Backup Destination | /boot/config.txt.bak | The recovery point created before 64-bit activation. |
Sources: safe64.sh:20-21
Incremental Logic
The script uses conditional checks (grep -q) to ensure that changes are not duplicated if the script is run multiple times. This prevents the configuration file from becoming cluttered, which simplifies the manual rollback process if a user needs to compare the current file against the .bak file.
Sources: safe64.sh:24-33
Transition Logic Flow
The following sequence diagram illustrates the interaction between the script and the system files during the 64-bit enablement process.
This diagram shows the sequence of checks and file operations performed during execution.
Sources: safe64.sh:10-37
Extension Points for Rollback Logic
While the current project provides a manual rollback path (restoring the .bak file), the architecture allows for several extensions:
- Automated Rollback Timer: As mentioned in the project description, a rollback timer can be integrated to automatically restore
/boot/config.txt.bakif the user does not confirm a successful boot within a specific window. - Validation Post-Reboot: A service could be implemented to check if the kernel is truly running in 64-bit mode using
uname -mand trigger a rollback if the system is stuck in a boot loop or reverted to 32-bit. - Checksum Verification: Before and after modifications, MD5 or SHA checksums can be stored to verify the integrity of the backup file.
Sources: README.md:2-10, safe64.sh:1-5
Summary
The rollback logic in safe64switch is grounded in hardware verification and file-based recovery points. By creating /boot/config.txt.bak before appending arm_64bit=1 and performance tweaks like gpu_mem=16, the project ensures that users can revert changes if the 64-bit kernel causes instability. The use of set -e in the shell script further guarantees that the process halts if any step in the safety chain fails.