使用 `parted` 命令分区

在一些fdisk不支持的硬盘上,可以使用这个命令我的 minimal的系统没有这个命令,需要单独安装
使用help可以查看帮助,就不解释含义了,不支持某些格式文件系统(例如ext3和ext4)的格式化,可以在这里分区,再退出用其他的命令格式化分区

[root@jin ~]# parted /dev/sdb
GNU Parted 2.1
使用 /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
# 分区,执行即生效
(parted) mkpart primary ext4 16.5MB 32.5MB
警告: WARNING: the kernel failed to re-read the partition table on /dev/sdb (设备或资源忙).  As a result, it may not reflect all
of your changes until after reboot.
# 查看分区
(parted) p                                                                
Model: Msft Virtual Disk (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos

Number  Start   End     Size    Type     File system  标志
 1      32.3kB  16.4MB  16.4MB  primary  ext4
 2      16.8MB  32.5MB  15.7MB  primary
创建设备文件

分区之后,如果没有创建设备文件,则需要手动创建

# 查看创建设备文件需要的参数
[root@jin ~]# ls -al /dev/sdb*
brw-rw---- 1 root disk 8, 16 11月 18 09:28 /dev/sdb
brw-rw---- 1 root disk 8, 17 11月 17 15:56 /dev/sdb1
brw-rw---- 1 root disk 8, 18 11月 17 16:14 /dev/sdb2
# 创建设备文件,参数分别为: 设备文件名, 设备类型(对应上面查看的文件的类型,第一个字母就代表文件类型),装置代码(要和上面的一致),(次要装置代码,和上面的要不一样),参考下面是如何设置的
[root@jin ~]# mknod /dev/sdb3 b 8 19

上面的执行完之后确实创建了一个设备文件,修改文件权限和文件所数用户和所属数组之后,不能对文件进行格式化

查看

[root@jin ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x0008d235

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1           2       16032+  83  Linux
Partition 1 does not end on cylinder boundary.
Partition 1 does not start on physical sector boundary.
/dev/sdb2               3           4       15360   83  Linux
Partition 2 does not end on cylinder boundary.
/dev/sdb3               4           6       15360   83  Linux
Partition 3 does not end on cylinder boundary.

获得使用start_udev命令自动创建,(我执行这个命令无效)

格式化

上面的步骤执行完毕失败的话,再运行了partprobe,如果还是无效,就重启在格式化吧,格式化就用正常的格式化命令就行

mkfs.ext4 /dev/sdb2 

标签: linux

添加新评论