ubuntu/Linux磁盘挂载
# fdisk -l #查看磁盘信息
Disk /dev/ram0: 8 MiB, 8388608 bytes, 16384 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
.......
Disk /dev/mmcblk1: 3.8 GiB, 4030726144 bytes, 7872512 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: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/mmcblk1p1 8192 7872511 7864320 3.8G b W95 FAT32
........
# fdisk /dev/mmcblk1p1 #进入磁盘/TF卡/SD卡
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): m #显示菜单
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Command (m for help): p #显示该磁盘下的当前分区信息
Disk /dev/mmcblk1p1: 3.8 GiB, 4026531840 bytes, 7864320 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: 0x00000000
Command (m for help): n #添加一个分区
Partition type
p primary (0 primary, 0 extended, 4 free) #输入p为创建逻辑分区
e extended (container for logical partitions) #输入e为创建扩展分区
Select (default p): p #输入p为创建逻辑分区
Partition number (1-4, default 1): 1 #划分逻辑分区
First sector (2048-7864319, default 2048): 7864319 #磁盘分区大小
Created a new partition 1 of type 'Linux' and of size 512 B.
Command (m for help): p #显示该磁盘下的当前分区信息
Disk /dev/mmcblk1p1: 3.8 GiB, 4026531840 bytes, 7864320 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: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/mmcblk1p1p1 7864319 7864319 1 512B 83 Linux
Command (m for help): w #保存退出
The partition table has been altered.
Failed to add partition 1 to system: Invalid argument
The kernel still uses the old partitions. The new table will be used at the next reboot.
Syncing disks.
# fdisk -l #再次查看
.......
Disk /dev/mmcblk1: 3.8 GiB, 4030726144 bytes, 7872512 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: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/mmcblk1p1 8192 7872511 7864320 3.8G b W95 FAT32
.........
# mkfs.ext4 /dev/mmcblk1p1 #格式化分区
mke2fs 1.44.1 (24-Mar-2018)
/dev/mmcblk1p1 contains a vfat file system
Proceed anyway? (y,N) y
/dev/mmcblk1p1 is mounted; will not make a filesystem here!
(echo /dev/vdb【磁盘分区】 /data【挂载目录】 ext4【文件格式】 defaults 0 0 >> /etc/fstab #写入新分区信息 开机自动挂载 )
# echo /dev/mmcblk1p1 /data ext4 defaults 0 0 >> /etc/fstab
# cat /etc/fstab
# /etc/fstab: static file system information.
#
# These are the filesystems that are always mounted on boot, you can
# override any of these by copying the appropriate line from this file into
# /etc/fstab and tweaking it as you see fit. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/root / ext4 defaults 0 1
/dev/mmcblk1p1 /data ext4 defaults 0 0
root@nvidia-desktop:/usr/local/lib/python3.8/site-packages# cd ~/
root@nvidia-desktop:~# ls
Desktop
root@nvidia-desktop:/# mkdir /data #挂载目录
root@nvidia-desktop:/# mount /dev/mmcblk1p1 /data #挂载磁盘
root@nvidia-desktop:/# df -h #查看磁盘信息
Filesystem Size Used Avail Use% Mounted on
/dev/mmcblk0p1 14G 13G 136M 99% /
none 1.8G 0 1.8G 0% /dev
tmpfs 2.0G 4.0K 2.0G 1% /dev/shm
tmpfs 2.0G 29M 2.0G 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
tmpfs 397M 12K 397M 1% /run/user/120
tmpfs 397M 24K 397M 1% /run/user/1000
/dev/mmcblk1p1 3.8G 192K 3.8G 1% /data