通过插拔U盘,然后通过一下三种方法来查看U盘的文件为sda还是sdb,或者sdx等
tail -f /var/log/messages
dmesg | tail
lsblk
如:
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 4.2G 0 rom
[root@localhost ~]#
参考:
https://www.cnblogs.com/miaoxiong/p/10810348.html
要求:分三个区,1,2分256M,最后全部分给第三个区
[root@H3LINUX115 ~]# fdisk /dev/sdb /* --- 配置分区sdb U盘 进入fdisk交互界面 --- */
Welcome to fdisk (util-linux 2.29).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p /* --- 查看当前分区 --- */
Disk /dev/sdb: 57.8 GiB, 62058921984 bytes, 121208832 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: 0xc257cb52
Device Boot Start End Sectors Size Id Type
/dev/sdb1 109824 121208831 121099008 57.8G c W95 FAT32 (LBA)
Command (m for help): o /* --- 创建一个新的空的分区表,相当于删除其他分区 --- */
Created a new DOS disklabel with disk identifier 0xe8e21f80.
Command (m for help): p /* --- 显示现有分区 --- */
Disk /dev/sdb: 57.8 GiB, 62058921984 bytes, 121208832 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: 0xe8e21f80
Command (m for help): n /* --- 创建新分区 --- */
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p. p /* --- 显示现有分区 --- */
Partition number (1-4, default 1):
First sector (2048-121208831, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-121208831, default 121208831): 526335
Created a new partition 1 of type 'Linux' and of size 256 MiB.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (2-4, default 2):
First sector (526336-121208831, default 526336):
Last sector, +sectors or +size{K,M,G,T,P} (526336-121208831, default 121208831): 1050623
Created a new partition 2 of type 'Linux' and of size 256 MiB.
Command (m for help): n
Partition type
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (3,4, default 3):
First sector (1050624-121208831, default 1050624):
Last sector, +sectors or +size{K,M,G,T,P} (1050624-121208831, default 121208831):
Created a new partition 3 of type 'Linux' and of size 57.3 GiB.
Command (m for help): p
Disk /dev/sdb: 57.8 GiB, 62058921984 bytes, 121208832 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: 0xe8e21f80
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 526335 524288 256M 83 Linux
/dev/sdb2 526336 1050623 524288 256M 83 Linux
/dev/sdb3 1050624 121208831 120158208 57.3G 83 Linux
Command (m for help): w /* --- 保存:把分区写入硬盘并退出 --- */
The partition table has been altered.
Calling ioctl() to re-read parti[ 1023.350908] sdb: sdb1 sdb2 sdb3
tion table.
Syncing disks.
[ 1023.356996] sdb: sdb1 sdb2 sdb3
[root@H3LINUX115 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.29).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sdb: 57.8 GiB, 62058921984 bytes, 121208832 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: 0xe8e21f80
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 526335 524288 256M 83 Linux
/dev/sdb2 526336 1050623 524288 256M 83 Linux
/dev/sdb3 1050624 121208831 120158208 57.3G 83 Linux
Command (m for help):
ctrl+ c 退出 /* --- ctrl+c 退出 fdisk --- */
fdisk - Partition table manipulator for Linux Linux磁盘分区表操作工具
fdsik 能划分磁盘成为若干个区,同时也能为每个分区指定分区的文件系统,比如linux 、fat32、 linux 、linux swap 、fat16
sd代表的是SCSI,SATA接口硬盘
hd代表IDE接口的硬盘
sda和hda最后面的a都代表的是第一块硬盘
sda1和hda1则代表的是该硬盘的第一分区
如提供的 MBR文件名为mbr.bin,扩展段文件名为 ext.hd(这里名字是举例,需要已实际来)
第一步,dd if=mbr.bin of=/dev/sdb(这里假如硬盘是sda)
第二步,dd if=ext.hd of=/dev/sdb1
即可 (具体解释看下面)
MBR的全称是Master Boot Record(主引导记录)
MBR是位于磁盘最前边的一段引导代码。
它负责磁盘操作系统对磁盘进行读写时分区合法性的判别、分区引导信息的定位,它由磁盘操作系统在对硬盘进行初始化时产生的。
MBR包含了已安装的操作系统的启动加载器和驱动器的逻辑分区信息。
Linux dd 命令用于读取、转换并输出数据。
dd:用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换。
if=文件名 #输入文件名,缺省为标准输入。即指定源文件。< if=input file >
of=文件名 #输出文件名,缺省为标准输出。即指定目的文件。< of=output file >