2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

新品のMicroSD等をLinuxでマウントする際の手順メモ

Last updated at Posted at 2021-07-11

前書き

新品のMicroSDカードをLinuxでマウントした際の手順メモ

新品のMicroSD等を挿入した時のデバイス名を確認

実行コマンド&ログ
/home/user/source# dmesg
[ 4387.255594] vccio_sd: unsupportable voltage range: 3300000-3000000uV
[ 4387.290541] mmc_host mmc0: Bus speed (slot 0) = 400000Hz (slot req 400000Hz, actual 400000HZ div = 0)
[ 4388.085171] mmc_host mmc0: Bus speed (slot 0) = 50000000Hz (slot req 50000000Hz, actual 50000000HZ div = 0)
[ 4388.095117] mmc0: new high speed SDHC card at address 1234
[ 4388.105045] mmcblk0: mmc0:1234 SA08G 7.43 GiB
[ 4388.113590]  mmcblk0:

挿入したMicroSDをmmcblk0として認識している

パーティション分割

実行コマンド&ログ
/home/user/source# fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n  ######新規パーティションを作成######
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p ######プライマリパーティションを指定######
Partition number (1-4, default 1): 1  ######パーティションは全領域を使うので1つ######
First sector (2048-15572991, default 2048): 2048  ######デフォルト指定######
Last sector, +sectors or +size{K,M,G,T,P} (2048-15572991, default 15572991): 15572991  ######デフォルト指定######

Created a new partition 1 of type 'Linux' and of size 7.4 GiB.

Command (m for help): t ######システムIDを指定する######
Selected partition 1 ######パーティション1を指定######
Partition type (type L to list all types): L ######パーティションの一覧を確認したい場合は、Lで確認######

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden or  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi ea  Rufus alignment
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         eb  BeOS fs
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ee  GPT
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f1  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f4  SpeedStor
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      f2  DOS secondary
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fb  VMware VMFS
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fc  VMware VMKCORE
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fd  Linux raid auto
1c  Hidden W95 FAT3 75  PC/IX           bc  Acronis FAT32 L fe  LANstep
1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot    ff  BBT
Partition type (type L to list all types): b ######約8GのMicroSDなのでFAT32(CHS)を指定######
Changed type of partition 'Linux' to 'W95 FAT32'.

Command (m for help): p ######設定内容を確認する######
Disk /dev/mmcblk0: 7.4 GiB, 7973371904 bytes, 15572992 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xaec7a37e

Device         Boot Start      End  Sectors  Size Id Type
/dev/mmcblk0p1       2048 15572991 15570944  7.4G  b W95 FAT32

Command (m for help): w  ######書き込んで終了######
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

先頭パーティション mmcblk0p1が/dev配下に出現

実行コマンド&ログ
/mnt# ll /dev/mmcblk
mmcblk0       mmcblk1       mmcblk1boot1  mmcblk1p10    mmcblk1p3     mmcblk1p5     mmcblk1p7     mmcblk1p9
mmcblk0p1     mmcblk1boot0  mmcblk1p1     mmcblk1p2     mmcblk1p4     mmcblk1p6     mmcblk1p8     mmcblk1rpmb

mkfs.vfatコマンドでフォーマット

実行コマンド&ログ
/mnt# mkfs.vfat -v -c -F 32 /dev/mmcblk0p1
bash: mkfs.vfat: コマンドが見つかりません
/mnt# apt-get install mkfs
/mnt# mkfs.vfat -v -c -F 32 /dev/mmcblk0p1  ##### -v:詳細な進捗を表示、-c:不良ブロックの精査を行う、-F 32:FAT32形式でのフォーマットの指定。
mkfs.fat 4.1 (2017-01-24)
/dev/mmcblk0p1 has 4 heads and 16 sectors per track,
hidden sectors 0x0800;
logical sector size is 512,
using 0xf8 media descriptor, with 15570944 sectors;
drive number 0x80;
filesystem has 2 32-bit FATs and 8 sectors per cluster.
FAT size is 15184 sectors, and provides 1942568 clusters.
There are 32 reserved sectors.
Volume ID is 48a27e27, no volume label.
Searching for bad blocks 67296... 135904... 204384... 272480... 340576... 409312... 477920... 546400... 615136... 683872... 752608... 821344... 890080... 958816... 1027552... 1096416... 1165152... 1233888... 1302752... 1371488... 1440224... 1508960... 1577440... 1645920... 1714272... 1783136... 1851744... 1917920... 1982560... 2046944... 2111456... 2175712... 2240224... 2304608... 2368992... 2433120... 2497504... 2562016... 2626400... 2690912... 2755424... 2819936... 2884320... 2949088... 3013728... 3078240... 3142752... 3207264... 3271776... 3336288... 3400800... 3465184... 3529696... 3594080... 3658464... 3722848... 3787232... 3851744... 3916640... 3981280... 4046048... 4110688... 4175456... 4240096... 4304864... 4369632... 4434656... 4499808... 4564832... 4629856... 4694880... 4759904... 4824544... 4889440... 4954208... 5018848... 5083360... 5148000... 5212640... 5277152... 5341792... 5406560... 5471072... 5535712... 5600224... 5664864... 5729376... 5794016... 5858784... 5923296... 5987680... 6052320... 6116832... 6181344... 6245856... 6310368... 6374880... 6439008... 6503392... 6567904... 6632288... 6696672... 6760928... 6825056... 6889312... 6953568... 7017696... 7081952... 7146208... 7210592... 7274976... 7339232... 7403488... 7467744... 7532256... 7596640... 7660768... 7725024...
/mnt#

マウントする

実行コマンド&ログ
/mnt# mount -t vfat /dev/mmcblk0p1 /mnt/sd/
/mnt# ll /mnt/sd/
合計 8
drwxr-xr-x 2 root root 4096  1月  1  1970 .
drwxr-xr-x 3 root root 4096  6月 11 11:05 ..
/mnt#

自動マウントの設定

実行コマンド&ログ
/home/user/source# vim /etc/systemd/system/mnt-sd.mountunit
#####ファイル名は、mount point のパス名を -(ハイフン) でつなげた名前にする#####
mnt-sd.mountunit
[Unit]
Description=MicroSDCard

[Mount]
What=/dev/mmcblk0p1
Where=/mnt/sd
Type=vfat

[Install]
WantedBy=multi-user.target

起動時に自動で実行させるため、有効化

実行コマンド&ログ
/home/user# systemctl daemon-reload
/home/user# systemctl enable mnt-sd.mount

再起動して確認すると、/mnt/sd にマウントされていることが確認できる

実行コマンド&ログ
/home/user# systemctl status mnt-sd.mount
● mnt-sd.mount - MicroSDCard
   Loaded: loaded (/etc/systemd/system/mnt-sd.mount; enabled; vendor preset: enabled)
   Active: active (mounted) since Fri 2021-06-11 11:36:17 JST; 25s ago
    Where: /mnt/sd
     What: /dev/mmcblk0p1
  Process: 385 ExecMount=/bin/mount /dev/mmcblk0p1 /mnt/sd -t vfat (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 4915)
   Memory: 12.0K
      CPU: 23ms
   CGroup: /system.slice/mnt-sd.mount
/home/user# mount |grep /mnt
/dev/mmcblk0p1 on /mnt/sd type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=936,iocharset=utf8,shortname=mixed,errors=remount-ro)

おまけ:指定したサイズのファイルを作るコマンド

容量オーバーのテストしたい時とかに使用
サイズ確認を確認する

実行コマンド&ログ
/mnt/sd# df 
ファイルシス    1K-ブロック    使用  使用可 使用% マウント位置
/dev/root           8194488 3827600 3931080   50% /
devtmpfs            1003820       0 1003820    0% /dev
tmpfs               1004364       0 1004364    0% /dev/shm
tmpfs               1004364   17336  987028    2% /run
tmpfs                  5120       4    5116    1% /run/lock
tmpfs               1004364       0 1004364    0% /sys/fs/cgroup
/dev/mmcblk1p7        64229    6134   54819   11% /oem
/dev/mmcblk1p10     6707126    3855 6703271    1% /userdata
/dev/mmcblk0p1      7770272       4 7770268    1% /mnt/sd
tmpfs                200872       8  200864    1% /run/user/1000

7770267KByteのファイルを作成

実行コマンド&ログ
/mnt/sd# dd if=/dev/zero of=test bs=1K count=7770267 
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?