序言

明天在公司node.js安装linux,给同学在debian8.8下低格U盘,没成功。

回去做个实验。还真是的,从来没有在linux下低格过U盘,难堪,自己没有过这需求啊:P

朋友是想做个linux下的U盘启动盘,说那台鬼机器,只认ext3文件格式的U盘。真的假的?

实验

先切到root用户,要不没有fdisk可用。

先将U盘切到虚拟机,用fdisk瞧瞧U盘的设备名称。


root@debian8:~# fdisk -l
Disk /dev/sda: 128 GiB, 137438953472 bytes, 268435456 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: 0xebd09e8b
Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1  *         2048 257478655 257476608 122.8G 83 Linux
/dev/sda2       257480702 268433407  10952706   5.2G  5 Extended
/dev/sda5       257480704 268433407  10952704   5.2G 82 Linux swap / Solaris
Disk /dev/sdb: 30.1 MiB, 31555584 bytes, 61632 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: 0x2dac66d5
Device     Boot Start   End Sectors  Size Id Type
/dev/sdb1        2048 61631   59584 29.1M 83 Linux

格式化u盘linux_格式化linux_linux格式化u盘命令

可以看见实验的U盘设备名称为/dev/sdb1

运行fdisk对U盘进行分区

root@debian8:~# fdisk /dev/sdb1
Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
/dev/sdb1: device contains a valid 'ext3' signature, it's strongly recommended to wipe the device by command wipefs(8) if this setup is unexpected to avoid possible collisions.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x4ae37f4f.
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
   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
  Misc
   m   print this menu

linux格式化u盘命令_格式化linux_格式化u盘linux

u change display/entry units x extra functionality (experts only) 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):

查看分区信息

Command (m for help): p
Disk /dev/sdb1: 29.1 MiB, 30507008 bytes, 59584 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: 0x4ae37f4f

可以看见分区类型是dos格式的,虽然不是的,这个U盘是我做bootloader实验用的,MBR被我换成实验用的MBR代码了。就是说,这个U盘现今没啥分区格式,是flat格式。

尝试删掉分区

Command (m for help): d
No partition is defined yet!
Could not delete partition 1

现今没有分区,是的,这正常的。

格式化u盘linux_linux格式化u盘命令_格式化linux

尝试构建新分区

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): 
First sector (2048-59583, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-59583, default 59583): 
Created a new partition 1 of type 'Linux' and of size 28.1 MiB.

查看分区是否构建


Command (m for help): p
Disk /dev/sdb1: 29.1 MiB, 30507008 bytes, 59584 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: 0x4ae37f4f
Device      Boot Start   End Sectors  Size Id Type
/dev/sdb1p1       2048 59583   57536 28.1M 83 Linux

可以见到多了一个linux分区.

尝试保存并退出

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 无效的参数

linux格式化u盘命令_格式化linux_格式化u盘linux

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

这个提示不是报错,只是说明要重新reboot后,新分区才生效

重启计算机

reboot

先复印分区信息linux格式化u盘64位linux,瞧瞧先前操作,分区表整完没有

Command (m for help): p
Disk /dev/sdb1: 29.1 MiB, 30507008 bytes, 59584 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: 0x4ae37f4f
Device      Boot Start   End Sectors  Size Id Type
/dev/sdb1p1       2048 59583   57536 28.1M 83 Linux

标记为启动盘

Command (m for help): a
Selected partition 1
The bootable flag on partition 1 is enabled now.

校准分区表

Command (m for help): v

没动静,就说明没错。

重新启动

reboot

低格c盘

root@debian8:~# mkfs --verbose -t ext3 /dev/sdb1
mkfs from util-linux 2.25.2
mkfs.ext3 /dev/sdb1 
mke2fs 1.42.12 (29-Aug-2014)
/dev/sdb1 contains a ext3 file system
        created on Wed Mar  6 18:12:36 2019
无论如何也要继续? (y,n) y
Creating filesystem with 29792 1k blocks and 7456 inodes
Filesystem UUID: e5365a41-e363-45a2-9d6a-029d2eba3f69
Superblock backups stored on blocks: 
        8193, 24577
Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (1024 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

由于没有加-c选项,低格的飞快。

拔插U盘

用vmware的联通设备切换到win10,win10不认得linux格式的U盘linux格式化u盘,说须要低格,这个正常。

再用vmware的联通设备切换到到debian8.8虚拟机,debian8.8手动将U盘挂载了,挂在路径为/media/lostspeed/e5365a41-e363-45a2-9d6a-029d2eba3f69

这说明,分区和低格的结果都正常。

构建一个文件试试

root@debian8:/media/lostspeed/e5365a41-e363-45a2-9d6a-029d2eba3f69# echo "hello, format udisk on debian8.8" > ./test.log
root@debian8:/media/lostspeed/e5365a41-e363-45a2-9d6a-029d2eba3f69# ls -alp
总用量 18
drwxr-xr-x  3 root root  1024 3月  12 23:24 ./
drwxr-x---+ 3 root root  4096 3月  12 23:20 ../
drwx------  2 root root 12288 3月  12 23:10 lost+found/
-rw-r--r--  1 root root    33 3月  12 23:24 test.log
root@debian8:/media/lostspeed/e5365a41-e363-45a2-9d6a-029d2eba3f69# cat ./test.log
hello, format udisk on debian8.8

在挂在后的设备中,构建显示文件都正常,说明低格U盘成功。

总结

在公司没低格成功,是没有仔细看报错提示和的man

本文原创地址://gulass.cn/zdxgshupsbjl.html编辑:刘遄,审核员:暂无