dfisk分区命令
fdisk分区工具用来建立msdos分区方案,其交互模式中的主要指令如下:
m:列出指令帮助
p:查看当前的分区表信息
n:新建分区
d:删除分区
t:更改分区标识
q:放弃分区更改并退出
w:保存对分区表所做的更改
1.3 步骤
df查看硬盘挂载点命令
[root@room4pc09 桌面]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda2 476254208 40285720 411752988 9% /
devtmpfs 1918956 0 1918956 0% /dev
tmpfs 1933460 144 1933316 1% /dev/shm
tmpfs 1933460 9188 1924272 1% /run
tmpfs 1933460 0 1933460 0% /sys/fs/cgroup
/dev/loop0 3751022 3751022 0 100% /zhuhaiyan
/dev/sda1 198174 133593 50041 73% /boot
tmpfs 386692 12 386680 1% /run/user/0
查看硬盘命令lsblk
[root@room4pc09 桌面]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 500G 0 disk
├─sda1 8:1 0 204M 0 part /boot
├─sda2 8:2 0 461.6G 0 part /
└─sda3 8:3 0 4G 0 part [SWAP]
sr0 11:0 1 1024M 0 rom
loop0 7:0 0 3.6G 0 loop /zhuhaiyan
步骤一:新建分区表
1.新建分区命令fdisk
[root@server0 ~]# fdisk /dev/db1 //分区的硬盘
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x9ac1bc10.
Command (m for help): //交互操作提示信息
Command (m for help): n //新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p //类型为p(主分区)
Partition number (1-4, default 1): 1 //分区编号1
First sector (2048-20971519, default 2048): //起始位置默认
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +200M
Partition 1 of type Linux and of size 200 MiB is set //结束位置+200MiB大小
Command (m for help): p //确认当前分区表
.. ..
Device Boot Start End Blocks Id System
/dev/vdb1 2048 411647 204800 83 Linux
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p //类型为p(主分区)
Partition number (2-4, default 2): 2 //分区编号2
First sector (411648-20971519, default 411648): //起始位置默认
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-20971519, default 20971519): +2000M
Partition 2 of type Linux and of size 2 GiB is set //结束位置+2000MiB大小
Command (m for help): p //确认当前分区表
.. ..
Device Boot Start End Blocks Id System
/dev/vdb1 2048 411647 204800 83 Linux
/dev/vdb2 411648 4507647 2048000 83 Linux
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (4507648-20971519, default 4507648):
Using default value 4507648
Last sector, +sectors or +size{K,M,G} (4507648-20971519, default 20971519): +1000M
Partition 3 of type Linux and of size 1000 MiB is set
Command (m for help): p //确认当前分区表
.. ..
Device Boot Start End Blocks Id System
/dev/vdb1 2048 411647 204800 83 Linux
/dev/vdb2 411648 4507647 2048000 83 Linux
/dev/vdb3 4507648 6555647 1024000 83 Linux
2.新建第3个分区/dev/vdb3
Command (m for help): t //修改分区类型标识
Partition number (1-3, default 3): 1 //指定第1个分区
Hex code (type L to list all codes): 8e //类型改为8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p //确认当前分区表
.. ..
Device Boot Start End Blocks Id System
/dev/vdb1 2048 411647 204800 8e Linux LVM
/dev/vdb2 411648 4507647 2048000 83 Linux
/dev/vdb3 4507648 6555647 1024000 83 Linux
3)调整分区类型标识(可选)
Command (m for help): t //修改分区类型标识
Partition number (1-3, default 3): 1 //指定第1个分区
Hex code (type L to list all codes): 8e //类型改为8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p //确认当前分区表
.. ..
Device Boot Start End Blocks Id System
/dev/vdb1 2048 411647 204800 8e Linux LVM
/dev/vdb2 411648 4507647 2048000 83 Linux
/dev/vdb3 4507648 6555647 1024000 83 Linux
4)保存分区更改,退出fdisk分区工具
Command (m for help): w //保存并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
5)刷新分区表
[root@server0 ~]# partprobe /dev/vdb //重新检测磁盘分区
//或者
[root@server0 ~]# reboot //对已使用中磁盘的分区调整,应该重启一次
.. .
步骤二:格式化及挂载分区
1)将分区/dev/vdb2格式化为EXT4文件系统
[root@server0 ~]# mkfs.ext4 /dev/vdb2
.. ..
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
2)配置开机自动挂载
[root@server0 ~]# vim /etc/fstab
.. ..
/dev/vdb2 /mnt/part2 ext4 defaults 0 0
3)创建挂载点,并验证挂载配置
[root@server0 ~]# mkdir /mnt/part2 //创建挂载点
[root@server0 ~]# mount -a //挂载fstab中的可用设备
[root@server0 ~]# df -hT /mnt/part2/ //检查文档所在的文件系统及设备
Filesystem Type Size Used Avail Use% Mounted on
/dev/vdb2 ext4 1.9G 5.9M 1.8G 1% /mnt/part2