
私は最新のArch Linux 5.12.5を使用しています。
SDカードは時々損傷する可能性があり、レンガでない場合はリセット/再フォーマットする必要があります。
私は次のようにこれを行います
# 1. unmount the card / make sure it's unmounted
umount /dev/mmcblk0
umount /dev/mmcblk0p1
# 2. wipe the card. After this the card cannot be mounted becasue
# there is no partition. There's nothing on it at all.
echo password | sudo -S dd bs=4M if=/dev/zero of=/dev/mmcblk0 oflag=sync
# 3. create a GPT partition table
# the "-s" defaults the go ahead answer to "yes" so that
# no user input is necessary rather confusingly the
# command is 'mklabel' for creating a partition table!
sudo parted -s /dev/mmcblk0 mklabel gpt
# 4. create a GPT file system
# HAVING THE "-E root_owner=$UID:$GID" IS ESSENTIAL,
# OTHERWISE THE PARTITION CAN ONLY BE WRITTEN TO AS ROOT
sudo mkfs.ext4 -F -O ^64bit -E root_owner=$UID:$GID -L 'SD_CARD' '/dev/mmcblk0'
以下の行を使用すると、つまり上記のようにUID:GIDを設定しないと、ファイルシステムの所有権はrootユーザーにのみ属し、root以外は誰もSDカードに書き込むことができません。
sudo mkfs.ext4 -F -O ^64bit -L 'SD_CARD' '/dev/mmcblk0
次の行を使用してUID:GIDをMy UID:GIDに設定すると、ファイルシステムの所有権は私にのみ属し、私以外は誰もSDカードに書き込むことができません。
sudo mkfs.ext4 -F -O ^64bit -E root_owner=$UID:$GID -L 'SD_CARD' '/dev/mmcblk0'
誰もがSDカードファイルシステムに書き込むためにUID:GIDをどのように設定しますか?
答え1
必要なのは、カードを消去してGPTパーティションテーブルを作成し、すぐにGPTパーティションテーブルをファイルシステムで上書きすることです。パーティションテーブルをまったく作成しないか、パーティションテーブル内にファイルシステム用のパーティションを作成します。 2番目は一般的に推奨される方法です。
# Create partition table with a single full-sized partition
parted -s /dev/mmcblk0 mklabel gpt
parted /dev/mmcblk0 unit MiB mkpart primary 1 100%
# Print it out (optional)
parted /dev/mmcblk0 unit MiB print
# Create filesystem on the partition we have just made
mkfs.ext4 -L SD_CARD /dev/mmcblk0p1
# Mount it
mkdir -p /mnt/dsk
mount /dev/mmcblk0p1 /mnt/dsk
# Allow anyone to write to it
chmod 777 /mnt/dsk
これにより、誰でも書き込むことができるファイルシステムが提供されます。 (UNIX / Linuxファイルシステムには所有者がいません。ファイルとディレクトリには所有者がいます。)しかし、ファイルまたはディレクトリを作成すると、これはあなたのものであり、他の人に書き込みを許可しないと書き込むことはできません。これは、ACLを使用して変更されない限り、標準のUNIX / Linux動作です(例:関連回答
答え2
将来SDカードを再生するときに使用するスクリプトです。
完全にこの答えに基づいています。 https://unix.stackexchange.com/a/422687/46470
# creates GPT partition table
# creates ext4 file system
# creates file system writable by anyone
# variables
disk_z="mmcblk0"
part_z="p1"
user_z="$USER"
password_z="password"
# issue sudo password so that password is not needed again
echo password_z | sudo -S clear
# make sure the device is not mounted
sudo umount /dev/$disk_z
sudo umount /dev/$disk_z$part_z
# Create partition table with a single full-sized partition
sudo parted -s /dev/$disk_z mklabel gpt
sudo parted /dev/$disk_z unit MiB mkpart primary 1 100%
# Create (1) "ext4" file system partition with (2) "64bit" filesystem
# and (3) name "p1" and (4) disk label "SD_CARD"
sudo mkfs.ext4 -F -O ^64bit -L 'SD_CARD' "/dev/$disk_z$part_z"
# tune2fs adjusts tunable filesystem parameters
# -o calls mount options
# acl enables Posix Access Control Lists to be stored
# in the filesystems metadata
# -o acl will enable the ACL to be set by "setfacl" once
# the partition is mounted and this will be
# stored in the filesystems metadata
sudo tune2fs -o acl "/dev/$disk_z$part_z"
# mount the file system
sudo mount "/dev/$disk_z$part_z" /mnt
# change ownership of the mounted file system
sudo chown "$user_z": /mnt
# chmod it to have rwx permissions for everyone
sudo chmod 777 /mnt
# SET File ACL (access list) permissions for users, groups and owner to rwx in each case
# and store this in the files systems metadata
sudo setfacl -m d:u::rwx,d:g::rwx,d:o::rwx /mnt
# unmount the disk
sudo umount /mnt