Linux磁盘管理入门教程

我们看看在Linux系统中磁盘是如何分区的
磁盘分区:
fdisk:是Linux的一个操作磁盘分区表的常用工具:
    常用的格式:fdisk -l列出使用的磁盘设备

[root@linux ~]# fdisk -l
 
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00029f42
 
  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *        2048    1026047      512000  83  Linux
/dev/sda2        1026048    84912127    41943040  83  Linux
/dev/sda3        84912128  126855167    20971520  83  Linux
/dev/sda4      126855168  419430399  146287616    5  Extended
/dev/sda5      126859264  131055615    2098176  82  Linux swap / Solaris

下面我们根据实验一点点讲解Linux磁盘的管理操作
0.创建主分区(MBR):
a)  Fdisk /dev/sda进入磁盘分区环境
[root@bogon ~]# fdisk /dev/sda
 
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').
 
Command (m for help):

当然,执行在这的时候,你可以使用m便会列出命令选项:
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
  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)
 
Command (m for help):

b)  n 添加一个新的磁盘
Command (m for help): n
Command action
  e  extended
  p  primary partition (1-4)

e:表示扩展分区,p:表示主分区(1-4)
[延伸]我们之后主分区的数量是由分区表限制的,64的分区表最多只能分为4个主分区,或者三个主分区一个扩展分区或者其他,常见的window中的就是一个主分区一个扩展分区(明白了吗)
Command action
  e  extended
  p  primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (7859-15665, default 7859):

c)  回车选择默认的起始扇区
123 Partition number (1-4): 3
First cylinder (7859-15665, default 7859): 
Using default value 7859

这里我们直接回车表示使用的是起始的柱面(在系统版本的不同,有的是根据柱面,有的是扇区,不过呢,也没啥大碍)

d)  输入格式为”+[M,G]”磁盘空间大小
1 Last cylinder, +cylinders or +size{K,M,G} (7859-15665, default 15665): +10G

根据我们自己个人定制,使用括号里面的单位,或者你也可以选择使用柱面表示,但是前面有一个加号

e)  w保存退出
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
 
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

这一切的操作其实都是在内存中完成,只有使用w才是保存下来,下面我们来验证一下

f)  ls /dev/sda*或者cat /proc/partitions查看是否有新创建的分区
[root@bogon ~]# ls /dev/sda*
/dev/sda  /dev/sda1  /dev/sda2
[root@bogon ~]# cat /proc/partitions 
major minor  #blocks  name
 
  8        0  125829120 sda
  8        1    204800 sda1
  8        2  62914560 sda2
 253        0  20971520 dm-0
 253        1    2097152 dm-1
 253        2  10485760 dm-2
 253        3  20971520 dm-3
[root@bogon ~]#

奇怪,这是怎么回事呢?难道没有成功?不是的,这是因为没有同步到内核罢了

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/15417.html