您的位置:首页 > 运维架构 > Linux

Linux(BBB Debian)下分区并自动挂载TF卡

2018-01-21 02:53 260 查看


1 检查

为了弥补BBB内部空间不足,需要采用tf卡对存储空间进行扩展。将tf卡插入BBB后,通过df命令查看不到,这是因为没有格式化并装载。

debian@beaglebone:~$ df

Filesystem     1K-blocks    Used Available Use% Mounted on

udev              221764       0    221764   0% /dev

tmpfs              49876    5080     44796  11% /run

/dev/mmcblk1p1   1809656 1632724     66956  97% /

tmpfs             249364       0    249364   0% /dev/shm

tmpfs               5120       4      5116   1% /run/lock

tmpfs             249364       0    249364   0% /sys/fs/cgroup

tmpfs              49872       0     49872   0% /run/user/1000


2 fdisk

在采用fdisk命令时可以看到未挂载的tf卡。

debian@beaglebone:~$ sudo fdisk -l

Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors #这个为16g 的tf卡位置

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mmcblk1: 1.8 GiB, 1920991232 bytes, 3751936 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: 0xab51b3cf

Device         Boot Start     End Sectors  Size Id Type

/dev/mmcblk1p1 *     8192 3751935 3743744  1.8G 83 Linux

Disk /dev/mmcblk1boot1: 1 MiB, 1048576 bytes, 2048 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

Disk /dev/mmcblk1boot0: 1 MiB, 1048576 bytes, 2048 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

debian@beaglebone:~$ sudo fdisk /dev/mmcblk0


3 分区

通过fdisk命令制定tf卡分区进行操作

debian@beaglebone:~$ sudo 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.

Device /dev/mmcblk0 already contains a ext4 signature.

The signature will be removed by a write command.

Device does not contain a recognized partition table.

Created a new DOS disklabel with disk identifier 0xd9c1e649.

Command (m for help):


在这里输入m会列出子命令列表。

4 fdisk详细命令

分区操作,这里由于tf卡只有16g,仅分了一个区,先输入d命令,删除可能存在的分区,再输入p查看分区,然后输入n新建分区,输入1新建1个分区,然后选择默认大小。分区完成后输入w保存并离开,使命令生效。如果输入过程有错误,可以仅输入q退出fdisk命令而不保存。

Command (m for help): p

Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 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: 0xd9c1e649

Command (m for help): d

No partition is defined yet!

Could not delete partition 30442297

Command (m for help): p

Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 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: 0xd9c1e649

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

First sector (2048-31116287, default 2048):

Last sector, +sectors or +size{K,M,G,T,P} (2048-31116287, default 31116287):

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

Command (m for help): w

The partition table has been altered.

Calling ioctl() to re-read partition table.

Syncing disks.


5 格式化

这里将新的分区格式化为linux下ext4类型的分区。

debian@beaglebone:~$ sudo mkfs.ext4 /dev/mmcblk0p1  #这是在mmcblk0上分好的分区1

mke2fs 1.43.4 (31-Jan-2017)

Discarding device blocks: done

Creating filesystem with 3889280 4k blocks and 972944 inodes

Filesystem UUID: 8addcae6-3f24-4c19-bb85-b1076beb7414

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done

Writing inode tables: done

Creating journal (16384 blocks): done

Writing superblocks and filesystem accounting information: done


6 挂载

在主目录下建立tf目录(这个可以随意)并将格式化好的分区挂载在下面。挂载完成后再用df命令就能看到挂载过的文件了。

““python

debian@beaglebone:~$ sudo mount /dev/mmcblk0p1 /home/debian/tf

debian@beaglebone:~$ df

Filesystem 1K-blocks Used Available Use% Mounted on

udev 221764 0 221764 0% /dev

tmpfs 49876 5080 44796 11% /run

/dev/mmcblk1p1 1809656 1632732 66948 97% /

tmpfs 249364 0 249364 0% /dev/shm

tmpfs 5120 4 5116 1% /run/lock

tmpfs 249364 0 249364 0% /sys/fs/cgroup

tmpfs 49872 0 49872 0% /run/user/1000

/dev/mmcblk0p1 15247276 40984 14412052 1% /home/debian/tf

## 7 自动挂载

为了避免每次开机都要手动挂载,可以将tf卡设置为开机自动挂载。

这需要编辑/etc/fstab文件并增加分区自动挂载内容。

```python

debian@beaglebone:~/tf$ sudo vim /etc/fstab\

<div class="se-preview-section-delimiter"></div>

#文件内容

<div class="se-preview-section-delimiter"></div>

# /etc/fstab: static file system information.

#

/dev/mmcblk1p1  /  ext4  noatime,errors=remount-ro  0  1

/dev/mmcblk0p1 /home/debian/tf ext4 defaults 0 1 #这一行为新加内容

debugfs  /sys/kernel/debug  debugfs  defaults  0  0


保存文件并重新启动系统,用df命令查看时可以看到分区已经自动挂载到了指定位置。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  BBB fdisk linux