您的位置:首页 > 运维架构 > Linux

linux fdisk命令使用

2016-11-10 10:32 288 查看
使用fdisk对新添加的硬盘进行格式化和挂载.
实验环境:
虚拟机 centos 6.x
1、首先通过虚拟机添加一块scsi硬盘
2、启动服务器通过fdisk -l可以查看到新添加的磁盘,Disk /dev/sdb 10G是我新加的磁盘,且没有分区
[root@model ~]# fdisk -l
Disk /dev/sda: 26.8 GB, 26843545600 bytes

255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005eba6

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 128 512000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 128 3264 25189376 83 Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

3、LINUX系统如果要使用新的磁盘,我们还需要对磁盘进行分区和格式化成ext3或者ext4的文件系统

[root@model ~]# fdisk /dev/sdb -----/dev/sdb 需要分区的设备名称
Command (m for help): 在这里按 m ,就会输出帮助;
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 注:l是列出分区类型,以供我们设置相应分区的类型;
m print this menu 注:m 是列出帮助信息;
n add a new partition 注:添加一个分区;
o create a new empty DOS partition table
p print the partition table 注:p列出分区表;
q quit without saving changes 注:不保存退出;
s create a new empty Sun disklabel
t change a partition's system id 注:t 改变分区类型;
u change display/entry units
v verify the partition table
w write table to disk and exit 注:把分区表写入硬盘并退出;
x extra functionality (experts only) 注:扩展应用,专家功能;
Command (m for help): p ---打印分区情况 ,如果没有分区,则不会显示任何分区信息
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8c30c419

Device Boot Start End Blocks Id System

Command (m for help): n ----添加分区
Command action
e extended
p primary partition (1-4)
p ---输入P 创建主分区 ,主分区可以创建4个
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):
Using default value 1305

Command (m for help): w ----将分区写入磁盘
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
查看磁盘信息 ,/dev/sdb1 为新添加的磁盘分区
[root@model ~]# fdisk -l

Disk /dev/sdb: 10.7 GB, 10737418240 bytes ---添加的新磁盘
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8c30c419

Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 83 Linux
[root@model ~]# mount /dev/sdb1 /mnt/sdb1 ---如果没有对分区进行格式化,挂载失败
mount: you must specify the filesystem type
[root@model ~]# mkfs.ext3 /dev/sdb1 ----格式化磁盘系统为ext3
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2620595 blocks
131029 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@model ~]# mkdir /mnt/sdb1 ---创建磁盘挂载点
[root@model ~]# mount /dev/sdb1 /mnt/sdb1 --- 成功挂载磁盘

这样我们就能进入 /mnt/sda6目录,然后存取文件了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux