码迷,mamicode.com
首页 > 其他好文 > 详细

fdisk 分区

时间:2018-04-12 23:58:10      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:fdisk 磁盘分区工具

1.1 fdisk 磁盘分区工具
受mbr分区表限制,只能给小于2T的磁盘划分分区,
语法:
[fdisk] [option] [device]
参数:
-l 显示所有磁盘分区的信息
1.1 交互式分区实践

  [root@lvs ~]# ls /dev/sd* 
[root@lvs ~]# fdisk /dev/sdb
Command (m for help): m
Command action
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to
         switch off the mode (command ‘c‘) and change display units to
         sectors (command ‘u‘).
     -c  提示使用-c关闭dos兼容模式
     -u 提示-u 参数使用扇区为单位分区
Command (m for help): m    m  是帮助 
Command action
   a   toggle a bootable flag       #设置引导分区
   b   edit bsd disklabel               #编辑bsd分区
   c   toggle the dos compatibility flag    #设置dos兼容扇区
   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   #创建一个新的dos分区表
   p   print the partition table                #打印分区表
   q   quit without saving changes         #退出不保存更改
   s   create a new empty Sun disklabel    #创建新的sun卷标
   t   change a partition‘s system id            #更改分区系统id
   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): n    #新建立一个分区
Command action
   e   extended    扩展分区
   p   primary partition (1-4)    创建主分区
p    创建一个主分区,需要人工输入p后回车
Partition number (1-4): 1  设置主分区编号1 
First cylinder (1-261083, default 1): 1G   设置柱起面,默认为1
Last cylinder, +cylinders or +size{K,M,G} (1-261083, default 261083): 100G    #设置结束柱面
Command (m for help): p  打印分过的分区表

Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes
255 heads, 63 sectors/track, 261083 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: 0xc4682775

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
Command (m for help): n  再建立一个分区表
Command action
   e   extended
   p   primary partition (1-4)
e   创建一个扩展分区
Partition number (1-4): 2   设置分区编号为2
First cylinder (101-261083, default 101):   
Using default value 101
Last cylinder, +cylinders or +size{K,M,G} (101-261083, default 261083): 
Using default value 261083
Command (m for help): p

Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes
255 heads, 63 sectors/track, 261083 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: 0xc4682775

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101      261083  2096345947+   5  Extended
Command (m for help): n  再建立一个分区
Command action   
   l   logical (5 or over)   分了扩展分区,这里自动变为逻辑分区
   p   primary partition (1-4)
p
Partition number (1-4): 3
No free sectors available   不能再创建主分区,没有磁盘空间了
Command (m for help): n   再新建一个分区
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l   新建立一个逻辑分区
First cylinder (101-261083, default 101): 
Using default value 101
Last cylinder, +cylinders or +size{K,M,G} (101-261083, default 261083): 400G

Command (m for help): p  打印分区表

Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes
255 heads, 63 sectors/track, 261083 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: 0xc4682775

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101      261083  2096345947+   5  Extended
/dev/sdb5             101         400     2409718+  83  Linux

Command (m for help): n  新建立一个分区
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l     新建立一个逻辑分区
First cylinder (401-261083, default 401): 401
Last cylinder, +cylinders or +size{K,M,G} (401-261083, default 261083): 
Using default value 261083

Command (m for help): p

Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes
255 heads, 63 sectors/track, 261083 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: 0xc4682775

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101      261083  2096345947+   5  Extended
/dev/sdb5             101         400     2409718+  83  Linux
/dev/sdb6             401      261083  2093936166   83  Linux

Command (m for help): w   将操作写入分区表生效并退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@lvs ~]# ls /dev/sd*  查看分区后的状态
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sdb  /dev/sdb1  /dev/sdb2  /dev/sdb5  /dev/sdb6  /dev/sdc
[root@lvs ~]# partprobe /dev/sdb  执行该命令通知内核分区表已经更改,此部是不重启让分区表生效的命令
[root@lvs ~]# 
  1.2格式化磁盘

[root@lvs ~]# mkfs.ext4 /dev/sdb1
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
50288 inodes, 200804 blocks
10040 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=209715200
7 block groups
32768 blocks per group, 32768 fragments per group
7184 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840

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

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.   执行这个命令可以避免磁盘挂自动检查磁盘。
  1.3挂载磁盘分区
[root@lvs ~]# df -h  显示磁盘使用的情况
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        79G  3.4G   71G   5% /
tmpfs           491M     0  491M   0% /dev/shm
/dev/sda1       194M   29M  155M  16% /boot
[root@lvs ~]# mount /dev/sdb1 /mnt磁盘只能挂了才能使用,将磁盘挂载到/mnt下

[root@lvs ~]# df -h 
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        79G  3.4G   71G   5% /
tmpfs           491M     0  491M   0% /dev/shm
/dev/sda1       194M   29M  155M  16% /boot
/dev/sdb1       773M   17M  717M   3% /mnt
[root@lvs ~]# vim /etc/fstab
/dev/sdb1               /mnt                    ext4    defaults        0 0 

在用交互指令d删除分区时要小心,看好分区的序号,如果删除了扩展分区,那么扩展分区之下的逻辑分区都会被删除,所在在操作时要小心,如果不小心删除错误,按q退出,这样之前的操作就会失效,如果输入(w保存指令)则会保存所有修改

fdisk 分区

标签:fdisk 磁盘分区工具

原文地址:http://blog.51cto.com/cainiaibage/2097639

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!