使用fdisk给硬盘分区

考题:
给机器添加一块1G的硬盘,用fdisk进行分区
分成2P+E的方式,其中P1=200M P2=200M E=600,并且有2个逻辑分区,大小各为300M

解答:
Disk /dev/sdb: 1073 MB

#进入交互模式
[root@NFS-Server ~]# fdisk /dev/sdb
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
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)

结果:
Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 52 208845 83 Linux
/dev/sdb4 53 130 626535 5 Extended
/dev/sdb5 53 91 313236 83 Linux
/dev/sdb6 92 130 313236 83 Linux

w

[root@NFS-Server ~]# partprobe #使分区马上生效,即临时生效
partprobe命令的作用是在不重启服务器的情况下识别创建的分区,Centos 默认下是没有安装这个命令的需要的话可以运行如下命令进行安装

yum install parted

#要使用分区,就要格式化

[root@NFS-Server ~]# mkfs.ext4 /dev/sdb1

#查看block大小
[root@NFS-Server ~]# dumpe2fs /dev/sdb1 |grep -i “block size”
dumpe2fs 1.41.12 (17-May-2010)
Block size: 1024

#挂载硬盘

[root@NFS-Server ~]# mkdir -p /a
[root@NFS-Server ~]# mount /dev/sdb1 /a
[root@NFS-Server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
19G 1.7G 16G 10% /
tmpfs 236M 0 236M 0% /dev/shm
/dev/sda1 485M 32M 429M 7% /boot
/dev/sdb1 198M 17M 172M 9% /a

#开机自动挂载

[root@NFS-Server ~]# tail -1 /etc/fstab
/dev/sdb1 /a ext4 defaults 0 0

使用fdisk给硬盘分区
Scroll to top