Partition and Mount TF Card on Linux
Last updated on June 15, 2023 am
Partition and Mount TF Card on Linux
Simply plugging in a TF Card to the board may not work even with built-in drivers.
This blog takes an 16 GB micro SD card and a single board computer (SBC) Huashan-pi CV1812H as an example of how to do partitioning and mounting to let our Linux system recognize the card.
Basic Commands
df
Running the bash command df -h
allows you to see all mounted disk devices.
1 |
|
It is clear that our 16 GB micro SD card is not listed.
fdisk
Running teh command fdisk -l
shows all of hardware disk drives:
1 |
|
Line 11 is exactly what we are looking for. This 15 GB is the size of our TF card. There is always a discrepancy between the labeled size and the actual available size on OS, which can be quite annoying.
Our card is located at the path /dev/mmcblk1
Partitioning
The next step is going to partition the disk. This can be done by using the fdisk
command. For more details, you can refer to man fdisk
or tldr fdisk
.
1 |
|
This command will allow us to perform the partitioning.
1 |
|
press Enter
to use default values for the first and last sector.
These values represent disk location references that map to specific locations on the disk.
Mounting
The last step is to mount the drive to a directory path. If the path /mnt/sd
does not exist, create it using the mkdir
command.
1 |
|
Done
We are all set now. Running the command df -Th
will verify that our TF card is mounted with vfat
type, which corresponds to the FAT32
file system.
1 |
|
On Removal
Simply unmount the device so that the card can be removed safely.
- Do not use the resource inside the mounted device, e.g., reading from or writing to it, and remember navigate outside the directory
/mnt/sd
. - Run command
umount /mnt/sd
(unmount by mounted directory path) orumount /dev/mmcblk1p1
(unmount by device name), they are equivalent.
Next Time
Next time when you restart the board or plugged in the micro SD card again, running command mount /dev/mmcblk1p1 /mnt/sd
is needed, otherwise the system still do not have a path to access the file in the card.
Alternatively, you can put the following lines into shell script to automate the procedure.
1 |
|
References
- Extend Partition on SD Card or eMMC
- Linux下分区详解之–Fdisk_ITPUB博客
- 4.1. 华山派-CV181系列开发板基本介绍 · sophgo/sophpi-huashan Wiki
- 4. Partitioning requirements
- 5. Partitioning with fdisk - 5.3. Mixed primary and logical partitions
- Why does my USB drive show less capacity than stated on my PC or MAC | Integral Memory