设为首页 收藏本站
查看: 698|回复: 0

[经验分享] linux fdisk命令使用

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-11-11 09:52:28 | 显示全部楼层 |阅读模式
使用fdisk对新添加的硬盘进行格式化和挂载.
实验环境:
  虚拟机 centos 6.x
1、首先通过虚拟机添加一块scsi硬盘
2、启动服务器通过fdisk -l可以查看到新添加的磁盘,Disk /dev/sdb 10G是我新加的磁盘,且没有分区
[iyunv@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的文件系统

[iyunv@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  为新添加的磁盘分区
[iyunv@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
[iyunv@model ~]#  mount /dev/sdb1 /mnt/sdb1 ---如果没有对分区进行格式化,挂载失败
mount: you must specify the filesystem type
[iyunv@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.
[iyunv@model ~]# mkdir  /mnt/sdb1   ---创建磁盘挂载点
[iyunv@model ~]#  mount /dev/sdb1 /mnt/sdb1    --- 成功挂载磁盘

这样我们就能进入 /mnt/sda6目录,然后存取文件了。



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-298770-1-1.html 上篇帖子: varnish缓存实现动静分离 下篇帖子: ubuntu apt-get安装软件时资源被锁的处理方法 linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表