磁盘管理
常见的总线: IDE,SATA,SCSI,SAS,USB
hd*: IDE(ATA)
sd*: SATA,SCSI(small computer system interface),SAS,USB
主分区(最多有4个,剩余空间不可用)
(想划分超过4个分区,需要借助扩展分区和逻辑分区)
0磁道0扇区是MBR(Master Boot Record)
大小为512字节
(BootLoader+PartitionTable+Magic Number)
446 |64 |2
每个主分区占16字节 64/16=4
扩展分区
扩展分区与主分区一样占用16字节空间
一个磁盘只能有个扩展分区
扩展分区不能直接使用
需要在扩展分区内创建逻辑分区
逻辑分区
IDE: 主+扩展+逻辑=63
SATA: 主+扩展+逻辑=15
#fdisk -l
d(删除) n(新建) p(看分区表)
q(不保存退出) w(保存退出)
在fdisk命令环境中使用ctrl+c等同于q
01 查看sdb的分区表
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x01ed3354
Device Boot Start End Blocks Id System
02 创建第一个分区
Command (m for help): n //新建分区
Command action
e extended
p primary partition (1-4)
p //主分区
Partition number (1-4): 1 //分区ID
First cylinder (1-2610, default 1): //按回车使用默认的1
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G //让系统划分一个2G的分区
Command (m for help): p //打印分区表
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x01ed3354
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
03 保存退出
Command (m for help): w //保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
04 重读分区表
---rhel5---
#partprobe /dev/sdb
---rhel6---
#partx -a /dev/sdb
****************
重读分区表的操作
如果硬盘没有分区,那么不需要做
如果已经存在分区,那么再划分分区时必须重读分区表
****************
05 给分区做文件系统ext4
#mkfs.ext4 /dev/sdb1
06 将新的分区挂载到目录上使用
#mkdir /mnt/newp1
#mount /dev/sdb1 /mnt/newp1
#df -h
自动挂载分区
有两种挂载方式
01 /etc/fstab (建议使用)
02 /etc/rc.local
#vi /etc/fstab
-----------------------------------------
/dev/sdb1 /mnt/newp1 ext4 defaults 0 0
-----------------------------------------