I'm using up to date Arch Linux 5.12.5.
SD cards from time to time become corrupted, and if not bricked have to be reset/ reformatted.
I do this as follows
# 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'
If I use the below line, ie miss out setting the UID:GID to me as above, then ownership of the file system is for root only and the SD card cannot be written to by anyone other than root
sudo mkfs.ext4 -F -O ^64bit -L 'SD_CARD' '/dev/mmcblk0
When I use the below line, which sets the UID:GID to my UID:GID, then ownership of the file system is for me only and the SD card cannot be written to by anyone other than me
sudo mkfs.ext4 -F -O ^64bit -E root_owner=$UID:$GID -L 'SD_CARD' '/dev/mmcblk0'
How do I set the UID:GID so that the SD card file system can be written to by anyone?
tunefs
andsetfacl
is superb. I also like the simplicity of the below answer which mounts the file system and sets the file permissions to777
withchown
is elegant. – Kes May 22 '21 at 15:15chmod 777
is that while the root directory of the card will indeed be fully accessible to everyone on any system the card is plugged into (as long as it supports the ext4 filesystem type), any files and sub-directories created into it will follow theumask
setting of the user creating them, resulting in them being most likely unmodifiable by other UIDs, and possibly completely un-accessible... unless the creator modifies theirumask
setting orchmod
s the files & dirs to world-writeable afterwards. – telcoM May 22 '21 at 15:24