From 51ec4ca7199ccf70f9afbe89e312c0d432f10262 Mon Sep 17 00:00:00 2001 From: "Lance R. Vick" Date: Thu, 27 Jun 2024 00:14:34 -0700 Subject: [PATCH] feat: working sd card automounting with via udev --- Containerfile | 2 +- Makefile | 4 ++++ .../usr/lib/udev/rules.d/sdcard-autorun.rules | 22 ++++++++++--------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Containerfile b/Containerfile index 3f5b9e0..2e336ee 100644 --- a/Containerfile +++ b/Containerfile @@ -169,7 +169,7 @@ COPY sdcard sdcard RUN <<-EOF set -eux dd if=/dev/zero of=sdcard.img bs=1M count=32 - mformat -i sdcard.img :: + mformat -v external -i sdcard.img :: mcopy -i sdcard.img -s sdcard/* :: EOF diff --git a/Makefile b/Makefile index 1ca64f8..87ddc17 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,9 @@ vm-bios: out/airgap.iso -usb \ -device sdhci-pci \ -device sd-card,drive=external \ + -usbdevice tablet \ -drive id=external,if=none,format=raw,file=out/sdcard.img \ + -display gtk,show-menubar=off,zoom-to-fit=on \ -cdrom "out/airgap.iso" .PHONY: vm-efi @@ -34,7 +36,9 @@ vm-efi: out/airgap.iso -usb \ -device sdhci-pci \ -device sd-card,drive=external \ + -usbdevice tablet \ -drive id=external,if=none,format=raw,file=out/sdcard.img \ + -display gtk,show-menubar=off,zoom-to-fit=on \ -cdrom "out/airgap.iso" out/airgap.iso: Containerfile $(shell git ls-files rootfs) diff --git a/rootfs/usr/lib/udev/rules.d/sdcard-autorun.rules b/rootfs/usr/lib/udev/rules.d/sdcard-autorun.rules index 2b0f41d..d435450 100644 --- a/rootfs/usr/lib/udev/rules.d/sdcard-autorun.rules +++ b/rootfs/usr/lib/udev/rules.d/sdcard-autorun.rules @@ -1,13 +1,15 @@ -#KERNEL!="sd[a-z][0-9]", GOTO="sd_cards_auto_mount_end" -KERNEL!="mmcblk[0-9]p[0-9]|sd[a-z][0-9]", GOTO="sd_cards_auto_mount_end" +KERNEL!="mmcblk[0-9]p[0-9]|sd[a-z][0-9]", GOTO="automount_end" +ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="automount_end" +IMPORT{program}="/sbin/blkid -o udev -p %N" -# Global mount options -ACTION=="add", ENV{mount_options}="relatime" +ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}" +ENV{ID_FS_LABEL}=="", ENV{dir_name}="%k" -# Filesystem specific options ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N" -ACTION=="add", ENV{ID_FS_TYPE}=="vfat", ENV{mount_options}="$env{mount_options},utf8,flush,user,umask=0000" -ACTION=="add", RUN+="/bin/mkdir -p /media/sd-%k", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/sd-%k" -ACTION=="add", RUN+="/usr/local/bin/autorun /media/sd-%k" -ACTION=="remove", RUN+="/bin/umount -l /media/sd-%k", RUN+="/bin/rmdir /media/sd-%k" -LABEL="sd_cards_auto_mount_end" +ACTION=="add", ENV{ID_FS_TYPE}=="vfat", ENV{mount_options}="relatime,utf8,flush,user,umask=0000" +ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}" +ACTION=="add", RUN+="/usr/local/bin/autorun /media/%E{dir_name}" + +ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}" + +LABEL="automount_end"