樹莓派系統(Linux)SD卡存儲設備的命令行使用

本文介紹了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).

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章