当前位置:科技 > 正文
世界今头条!在优盘上新建文件系统-(u盘如何新建文件夹)
2022-11-26 05:57:44 来源: 华南科技网


(相关资料图)

在优盘上新建文件系统(u盘如何新建文件夹)

本文基于Ubuntu 18.04系统,在U盘中制作ext4文件系统。在嵌入式调试中,可以从U盘中挂载文件系统。

# 1、查看U盘设备目录root@ubuntu:/home/run/code# ls /dev/sdsda sda1 sdb sdb1 (U盘)# 2、卸载root@ubuntu:/home/run/code# umount /dev/sdb1# 3、格式化为ext4文件系统,并添加卷标‘rootfs’root@ubuntu:/home/run/code# mkfs.ext4 -L rootfs /dev/sdb1mke2fs 1.44.1 (24-Mar-2018)Creating filesystem with 7864059 4k blocks and 1966080 inodesFilesystem UUID: d20aee9e-3ada-4f3e-b806-9bbad7209362Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000Allocating group tables: doneWriting inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information:doneroot@ubuntu:/home/run/code## 4、重新拔插U盘# 5、拷贝已有文件系统映像ubuntu_rootfs.imgroot@ubuntu:/home/run/code# file ubuntu_rootfs.imgubuntu_rootfs.img: Linux rev 1.0 ext4 filesystem data, UUID=faf10ee9-7e64-4826-98cc-239708736642, volume name "rootfs" (extents) (64bit) (large files) (huge files)root@ubuntu:/home/run/code# mkdir testimgroot@ubuntu:/home/run/code# mount ubuntu_rootfs.img testimg/root@ubuntu:/home/run/code# cd testimg/root@ubuntu:/home/run/code/testimg# lsbin boot dev etc home lib lost+found media 电脑 opt proc root run sbin srv sys system tmp usr var vendorroot@ubuntu:/home/run/code/testimg# mount /dev/sdb1 /tmp/root@ubuntu:/home/run/code/testimg# cp -rf * /tmp/# 6、卸载root@ubuntu:/home/run/code/testimg# umount /tmp

如果原有U盘有多个分区,可以使用fdisk命令删除或创建分区,流程如下:

root@ubuntu:/home/run/code# fdisk /dev/sdcWelcome 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 ## 1、帮助Help: 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 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 tableCommand (m for help): p ## 2、显示分区Disk /dev/sdc: 30 GiB, 32212254720 bytes, 62914560 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: gptDisk identifier: 23000000-0000-4C4A-8000-699000005ABBDevice Start End Sectors Size Type/dev/sdc1 16384 24575 8192 4M unknown/dev/sdc2 24576 32767 8192 4M unknown/dev/sdc3 32768 98303 65536 32M unknown/dev/sdc4 98304 163839 65536 32M unknown/dev/sdc5 163840 229375 65536 32M unknown/dev/sdc6 229376 4323327 4093952 2G unknown/dev/sdc7 4323328 62914495 58591168 28G unknownCommand (m for help): d ## 3、删除分区7-1Partition number (1-7, default 7): 7Partition 7 has been deleted.Command (m for help): dPartition number (1-6, default 6):Partition 6 has been deleted.Command (m for help): dPartition number (1-5, default 5):Partition 5 has been deleted.Command (m for help): dPartition number (1-4, default 4):Partition 4 has been deleted.Command (m for help): dPartition number (1-3, default 3):Partition 3 has been deleted.Command (m for help): dPartition number (1,2, default 2): dValue out of range.Partition number (1,2, default 2):Partition 2 has been deleted.Command (m for help): dSelected partition 1Partition 1 has been deleted.Command (m for help): p ## 4、显示分区Disk /dev/sdc: 30 GiB, 32212254720 bytes, 62914560 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: gptDisk identifier: 23000000-0000-4C4A-8000-699000005ABBCommand (m for help): n ## 5、新建分区1Partition number (1-128, default 1):First sector (34-62914526, default 2048):Last sector, +sectors or +size{K,M,G,T,P} (2048-62914526, default 62914526):Created a new partition 1 of type "Linux filesystem" and of size 30 GiB.Partition #1 contains a ext4 signature.Do you want to remove the signature? [Y]es/[N]o: yThe signature will be removed by a write command.Command (m for help): pDisk /dev/sdc: 30 GiB, 32212254720 bytes, 62914560 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: gptDisk identifier: 23000000-0000-4C4A-8000-699000005ABBDevice Start End Sectors Size Type/dev/sdc1 2048 62914526 62912479 30G Linux filesystemFilesystem/RAID signature on partition 1 will be wiped.Command (m for help): w ## 6、保存退出The partition table has been altered.Calling ioctl() to re-read partition table.Syncing disks.root@ubuntu:/home/run/code#

标签: 文件系统 新建文件 新建文件夹

责任编辑: jkl2