本文介绍了SD卡读卡器通过usb连接到树莓派的挂载和卸载的操作,以及SD卡的格式化以及查看SD卡容量的命令行操作。mount umount mkfs.vfat df
当SD卡插入到树莓派板子上的时候/dev目录下会出现sda1的设备节点,有时候会出现sdb1或者sdc1设备节点。有的Linux系统上是mmcblk*的设备节点,可能和操作系统有关,也有可能是笔者连接SD卡的方式是通过一个USB hub的tf读卡器的原因。
sudo fdisk -l
值得注意的是:在系统一直运行中的时候,第一次插上SD卡,显示的是sda1,然后插拔SD卡后变成sdb1,再次插拔SD卡后变成sdc1,继续插拔SD卡,就一直是sdc1了。这可能和树莓派的系统有关,就是只能识别3个SD卡接入。reboot系统后,发现,不管SD卡热插拔多少次显示的设备节点都是sda1,在没有插SD卡时/dev目录只有sda设备节点。所以上面出现的sdb1和sdc1 可能是随机的。
SD卡的挂载:
sudo mkdir /mnt/sdcard
sudo mount -t vfat /dev/sda1 /mnt/sdcard/
因为是Windows分区,所以是vfat文件系统格式
mount -t vfat -o iocharset=utf8 /dev/sdb1 /mnt/usb/
指定中文编码格式为UTF-8
(经过上的挂载操作后发现:挂载成功后,将SD卡拔出,sudo fdisk -l下面没有sda1了,但是dev目录下仍然有sda1,查看/mnt/sdcard目录,文件仍然存在)
SD卡的卸载:
umount -v /mnt/sdcard/
SD卡的格式化操作:
1.从Linux中卸载SD卡
sudo umount -v /mnt/sdcard/
如果没有这一步操作:在格式化的时候就会出现如下错误:
pi@raspberrypi:/mnt/sdcard $ sudo mkfs.vfat /dev/sda1
mkfs.fat 4.1 (2017-01-24)
mkfs.vfat: /dev/sda1 contains a mounted filesystem.
pi@raspberrypi:/mnt/sdcard $
2.格式化SD卡
sudo mkfs.vfat /dev/sda1
3.重新挂载SD卡
sudo mount -t vfat /dev/sda1 /mnt/sdcard/
查看SD卡的总的容量和已使用过的容量以及剩余可以使用的容量
df -h /dev/sda1
pi@raspberrypi:~ $ mount -h
Usage:
mount [-lhV]
mount -a [options]
mount [options] [--source] <source> | [--target] <directory>
mount [options] <source> <directory>
mount <operation> <mountpoint> [<target>]
Mount a filesystem.
Options:
-a, --all mount all filesystems mentioned in fstab
-c, --no-canonicalize don't canonicalize paths
-f, --fake dry run; skip the mount(2) syscall
-F, --fork fork off for each device (use with -a)
-T, --fstab <path> alternative file to /etc/fstab
-i, --internal-only don't call the mount.<type> helpers
-l, --show-labels show also filesystem labels
-n, --no-mtab don't write to /etc/mtab
--options-mode <mode>
what to do with options loaded from fstab
--options-source <source>
mount options source
--options-source-force
force use of options from fstab/mtab
-o, --options <list> comma-separated list of mount options
-O, --test-opts <list> limit the set of filesystems (use with -a)
-r, --read-only mount the filesystem read-only (same as -o ro)
-t, --types <list> limit the set of filesystem types
--source <src> explicitly specifies source (path, label, uuid)
--target <target> explicitly specifies mountpoint
-v, --verbose say what is being done
-w, --rw, --read-write mount the filesystem read-write (default)
-N, --namespace <ns> perform mount in another namespace
-h, --help display this help
-V, --version display version
Source:
-L, --label <label> synonym for LABEL=<label>
-U, --uuid <uuid> synonym for UUID=<uuid>
LABEL=<label> specifies device by filesystem label
UUID=<uuid> specifies device by filesystem UUID
PARTLABEL=<label> specifies device by partition label
PARTUUID=<uuid> specifies device by partition UUID
<device> specifies device by path
<directory> mountpoint for bind mounts (see --bind/rbind)
<file> regular file for loopdev setup
Operations:
-B, --bind mount a subtree somewhere else (same as -o bind)
-M, --move move a subtree to some other place
-R, --rbind mount a subtree and all submounts somewhere else
--make-shared mark a subtree as shared
--make-slave mark a subtree as slave
--make-private mark a subtree as private
--make-unbindable mark a subtree as unbindable
--make-rshared recursively mark a whole subtree as shared
--make-rslave recursively mark a whole subtree as slave
--make-rprivate recursively mark a whole subtree as private
--make-runbindable recursively mark a whole subtree as unbindable
For more details see mount(8).
pi@raspberrypi:~ $ umount -h
Usage:
umount [-hV]
umount -a [options]
umount [options] <source> | <directory>
Unmount filesystems.
Options:
-a, --all unmount all filesystems
-A, --all-targets unmount all mountpoints for the given device in the
current namespace
-c, --no-canonicalize don't canonicalize paths
-d, --detach-loop if mounted loop device, also free this loop device
--fake dry run; skip the umount(2) syscall
-f, --force force unmount (in case of an unreachable NFS system)
-i, --internal-only don't call the umount.<type> helpers
-n, --no-mtab don't write to /etc/mtab
-l, --lazy detach the filesystem now, clean up things later
-O, --test-opts <list> limit the set of filesystems (use with -a)
-R, --recursive recursively unmount a target with all its children
-r, --read-only in case unmounting fails, try to remount read-only
-t, --types <list> limit the set of filesystem types
-v, --verbose say what is being done
-q, --quiet suppress 'not mounted' error messages
-N, --namespace <ns> perform umount in another namespace
-h, --help display this help
-V, --version display version
For more details see umount(8).