Compare commits

...

2 Commits

Author SHA1 Message Date
764554d7d0 add SD card mode instructions 2025-02-26 17:43:25 +08:00
cfb0f2827a mount SD read-only with overlay FS and add RW toggle script
Signed-off-by: Florian Agbuya <fa@m-labs.ph>
2025-02-26 17:30:14 +08:00
3 changed files with 85 additions and 14 deletions

View File

@ -56,5 +56,12 @@ ssh access is not required for linien client if linien-server is started. If not
| Set the linien-server service to start at bootup | `linien-server enable` |
| Set the linien-server service not to start at bootup | `linien-server disable` |
4. In the dev shell, run `linien` to launch the GUI. Add new device. Username is `root`.
5. Select the newly added device and click connect in the GUI to connect and start the GUI.
5. In the dev shell, run `linien` to launch the GUI. Add new device. Username is `root`.
6. Select the newly added device and click connect in the GUI to connect and start the GUI.
## SD Card Mode
By default, the SD card is mounted in read-only mode with RAM overlay to prevent data corruption when power is unexpectedly removed.
1. To toggle between read-only and read-write modes, run the command: `toggle-sd-mode`.
2. The system will automatically toggle between modes and reboot to apply changes.
3. When in read-write mode, always perform proper shutdown before removing power.

View File

@ -411,6 +411,22 @@
hardeningDisable = [ "fortify" ];
};
toggle-sd-mode = pkgs-armv7l.writeScriptBin "toggle-sd-mode" ''
#!/bin/sh
mkdir -p /boot
mount /dev/mmcblk0p1 /boot
if [ -f /boot/rw_mode ]; then
rm -f /boot/rw_mode
echo "System will boot in read-only mode after reboot."
else
touch /boot/rw_mode
echo "System will boot in read-write mode after reboot."
fi
umount /boot
echo "Rebooting..."
reboot
'';
board-package-set = { board }: let
not-os-configured = (import patched-not-os {
inherit nixpkgs;
@ -420,6 +436,7 @@
({ config, pkgs, lib, ... }: {
environment.systemPackages = [
(pkgs.python3.withPackages(ps: with ps; [ pyfastservo linien-server]))
toggle-sd-mode
];
boot.postBootCommands = lib.mkAfter ''

View File

@ -59,7 +59,7 @@ index d7b0bf3..70353a1 100644
'';
}
diff --git a/stage-1.nix b/stage-1.nix
index 331fecd..aa5148e 100644
index 331fecd..3b6b98b 100644
--- a/stage-1.nix
+++ b/stage-1.nix
@@ -117,11 +117,6 @@ let
@ -74,18 +74,63 @@ index 331fecd..aa5148e 100644
root=/dev/vda
realroot=tmpfs
for o in $(cat /proc/cmdline); do
@@ -164,7 +159,9 @@ let
@@ -163,20 +158,41 @@ let
chmod 755 /mnt/
mkdir -p /mnt/nix/store/
-
- ${if config.not-os.nix then ''
- # make the store writeable
- mkdir -p /mnt/nix/.ro-store /mnt/nix/.overlay-store /mnt/nix/store
- mount $root /mnt/nix/.ro-store -t squashfs
- if [ $realroot = $1 ]; then
- mount tmpfs -t tmpfs /mnt/nix/.overlay-store -o size=1G
- fi
- mkdir -pv /mnt/nix/.overlay-store/work /mnt/nix/.overlay-store/rw
- modprobe overlay
- mount -t overlay overlay -o lowerdir=/mnt/nix/.ro-store,upperdir=/mnt/nix/.overlay-store/rw,workdir=/mnt/nix/.overlay-store/work /mnt/nix/store
- '' else ''
- # readonly store
- mount $root /mnt/nix/store/ -t squashfs
+ ${if config.not-os.sd && config.not-os.nix then ''
+ mount $root /mnt
+ '' else if config.not-os.nix then ''
# make the store writeable
mkdir -p /mnt/nix/.ro-store /mnt/nix/.overlay-store /mnt/nix/store
mount $root /mnt/nix/.ro-store -t squashfs
@@ -190,6 +187,11 @@ let
+ USE_READONLY=1
+ if [ -e /dev/mmcblk0p1 ]; then
+ mkdir -p /boot
+ mount -t vfat -o ro /dev/mmcblk0p1 /boot
+ if [ -e /boot/rw_mode ]; then
+ echo "Found rw_mode flag, enabling read-write mode"
+ USE_READONLY=0
+ fi
+ umount /boot
+ fi
+ if [ "$USE_READONLY" = "1" ]; then
+ mkdir -p /mnt.ro /mnt.overlay
+ mount -o ro $root /mnt.ro
+ mount -t tmpfs -o size=1G tmpfs /mnt.overlay
+ mkdir -p /mnt.overlay/upper /mnt.overlay/work
+ mount -t overlay overlay -o lowerdir=/mnt.ro,upperdir=/mnt.overlay/upper,workdir=/mnt.overlay/work /mnt
+ else
+ mount $root /mnt
+ fi
+ ''
+ else if config.not-os.nix then ''
+ # make the store writeable
+ mkdir -p /mnt/nix/.ro-store /mnt/nix/.overlay-store /mnt/nix/store
+ mount $root /mnt/nix/.ro-store -t squashfs
+ if [ $realroot = $1 ]; then
+ mount tmpfs -t tmpfs /mnt/nix/.overlay-store -o size=1G
+ fi
+ mkdir -pv /mnt/nix/.overlay-store/work /mnt/nix/.overlay-store/rw
+ modprobe overlay
+ mount -t overlay overlay -o lowerdir=/mnt/nix/.ro-store,upperdir=/mnt/nix/.overlay-store/rw,workdir=/mnt/nix/.overlay-store/work /mnt/nix/store
+ ''
+ else ''
+ # readonly store
+ mount $root /mnt/nix/store/ -t squashfs
''}
${lib.optionalString enablePlymouth ''
@@ -190,6 +206,11 @@ let
initialRamdisk = pkgs.makeInitrd {
contents = [ { object = bootStage1; symlink = "/init"; } ];
};
@ -97,7 +142,7 @@ index 331fecd..aa5148e 100644
in
{
options = {
@@ -205,6 +207,7 @@ in
@@ -205,6 +226,7 @@ in
config = {
system.build.bootStage1 = bootStage1;
system.build.initialRamdisk = initialRamdisk;
@ -152,10 +197,10 @@ index c61f9d6..fbdf0fd 100644
};
}
diff --git a/zynq_image.nix b/zynq_image.nix
index 3fa23ab..069fe89 100644
index 3fa23ab..1790801 100644
--- a/zynq_image.nix
+++ b/zynq_image.nix
@@ -1,66 +1,89 @@
@@ -1,66 +1,91 @@
-{ config, pkgs, ... }:
+{ lib, config, pkgs, ... }:
@ -167,6 +212,8 @@ index 3fa23ab..069fe89 100644
+ customKernel = (pkgs.linux_6_6.override {
extraConfig = ''
OVERLAY_FS y
+ NLS_CODEPAGE_437 y
+ NLS_ISO8859_1 y
+ MEDIA_SUPPORT n
+ FB n
+ DRM n