fdisk分区

在这里插入图片描述
1、Vmware上添加一个硬盘然后fdisk -l查看,可以看到有个sdb的硬盘还没分区。

[root@linux-node2 ~]# fdisk -l

磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000bb685

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris
/dev/sda3         4810752    41943039    18566144   83  Linux

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

2、在 console 上输入 fdisk /dev/sdb,可进入分割硬盘模式。

  1. 输入 m 显示所有命令列示。
  2. 输入 p 显示硬盘分割情形。
  3. 输入 a 设定硬盘启动区。
  4. 输入 n 设定新的硬盘分割区。
    4.1. 输入 e 硬盘为[延伸]分割区(extend)。
    4.2. 输入 p 硬盘为[主要]分割区(primary)。
  5. 输入 t 改变硬盘分割区属性。
  6. 输入 d 删除硬盘分割区属性。
  7. 输入 q 结束不存入硬盘分割区属性。
  8. 输入 w 结束并写入硬盘分割区属性

[root@linux-node2 ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x4e5fefab 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

3、输入n进行分区,p选择主分区,大小选择+1G

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):1
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):+1G
分区 1 已设置为 Linux 类型,大小设为 1 GiB

4、e选择创建一个扩展分区

命令(输入 m 获取帮助):n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e
已选择分区 4
起始 扇区 (6293504-41943039,默认为 6293504):
将使用默认值 6293504
Last 扇区, +扇区 or +size{K,M,G} (6293504-41943039,默认为 41943039):+7G
分区 4 已设置为 Extended 类型,大小设为 7 GiB

5、然后输入l可以创建逻辑分区

令(输入 m 获取帮助):n
Partition type:
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l
添加逻辑分区 5
起始 扇区 (6295552-20973567,默认为 6295552):
将使用默认值 6295552
Last 扇区, +扇区 or +size{K,M,G} (6295552-20973567,默认为 20973567):+1G
分区 5 已设置为 Linux 类型,大小设为 1 GiB

6、p查看分区情况,主分区+扩展分区最多=4,扩展分区最多为一个,这里我分了sdb1和sdb2两个主分区,sdb4一个扩展分区,在sdb4里面分了sdb5这个逻辑分区。


命令(输入 m 获取帮助):p

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x4e5fefab

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux
/dev/sdb2         2099200     4196351     1048576   83  Linux
/dev/sdb4         6293504    20973567     7340032    5  Extended
/dev/sdb5         6295552     8392703     1048576   83  Linux

7、w最后保存配置

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。

8、格式化磁盘,磁盘格式为ext3
mkfs -t ext3 /dev/sdb1

[root@linux-node2 ~]# mkfs -t ext3 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

9、创建一个目录,然后把分区挂载在目录下。
mount /dev/sdb1 /mnt/test

[root@linux-node2 ~]# mkdir /mnt/test
[root@linux-node2 ~]# mount /dev/sdb1 /mnt/test
[root@linux-node2 ~]# mount
/dev/sdb1 on /mnt/test type ext3 (rw,relatime,seclabel,data=ordered)

10、设置开机自动挂载

vim /etc/fstab
/dev/sdb1 /mnt/test ext3 default 0 0

猜你喜欢

转载自blog.csdn.net/qq_41475058/article/details/89456783