1. Hard disk interface
IDE: household products, in part, applied to the server
SATA: general use
SCSI: server market
SAS: high-end servers, expensive
2. HDD species
SATA hard disk:
SCSI hard disk:
SAS hard disk:
3. partition breaks awareness
MBR Overview: called the Master Boot Record, i.e. hard disk master boot record.
512 bytes
Three parts:
1. The master boot program accounts for 446 bytes
2.Partition table region (partition table), i.e. the DPT, accounting for 64 bytes
3.magic number, 2 bytes, 55AA
Partition: primary partition (No. 1-4) == "extended partition ==" logical partitions (No. 5)
Primary partition: mainly used to start the operating system, it is mainly put the operating system boot or boot program, / Boot partition preferably placed on the primary partition
Extended partition : You can not use it just as a container for logical partitions exist
note:
Primary partition + extended partition can only have 4
Extended partition can be 0 up to be a
Extended partition can not be used directly, you must first create an extended partition into logical partitions can use
Logical partitions can be 0 over 1
Check the hard disk:
[Root @ ken ~] # ls / dev / sd *
Named: / dev / SD [AZ] n-
Wherein: AZ represents the number of devices, such as hard disk sda represents a scsi, SDB is a second block ......
n represents the division of each disk partition number
4. File System and Data
Ext3
ext4
XFS
Cat /etc/fastab
5.fdisk management zones
parameter |
effect |
m |
See all available parameters |
n |
Add a new partition |
d |
Delete a partition information |
l |
List all available partition types |
t |
Change the type of a partition |
p |
View the partition table information |
w |
Save and Exit |
q |
Exit without saving |
Usage: fdisk [options] device
Common options: the -l to view the hard disk partition table
Case: In sdb build a partition on the disk, the size of 100M
1. Add a hard drive on a virtual machine
Step 1: Check Disk
[Root @ ken ~] # ls / dev / sd *
The second step: to sdb divide a 5G space
[root@ken ~]# fdisk /dev/sdb
Command (m for help): n # to create a new partition
Select (default p): # default primary partition, just press Enter
Partition number (1-4, default 1): # defaults to the first partition number, just press Enter
First sector (2048-41943039, default 2048): # default the first sector start position, just press Enter
A SECTOR Last, sectors or + size + {K, M, G} (2048-41943039, default 41,943,039): +. 5G # selected size, to use the plus sign in front of
Command (m for help): P #查看已经分好的磁盘
Command (m for help): w #w退出保存,q退出不保存
[root@ken ~]# ls /dev/sd*
如果执行完用ls /dev/sd*查看不到使用partprobe同步
E:拓展分区 l:逻辑分区
第三步:格式化
新的磁盘分区使用之前必须先格式化
[root@ken ~]# mkfs.xfs /dev/sdb1
第四步:挂载使用
[root@ken ~]# mkdir /wete
[root@ken ~]# mount /dev/sdb1 /wete 目录
[root@ken ~]# df -h 查看挂载点
卸载挂载点: umount /wete
扩展分区:
[root@ken ~]# fdisk /dev/sdb
Command (m for help): n
Command (m for help): e
Command (m for help):
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G
Command (m for help): p
Command (m for help): w
ls /dev/sdb*
[root@ken ~]# fdisk /dev/sdb
Command (m for help): n
Command (m for help): l
Command (m for help):
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +3G
Command (m for help): p
Command (m for help): w
mkfs.xfs /dev/sdb5
第五步:写入到配置文件中,开机自启
1.vim /etc/fstab
/dev/sdb1(磁盘分区)/part(挂载点) xfs(文件类型) defaults 0 0
[root@ken ~]# echo "/dev/sdb1 /part xfs defaults 0 0" >> /etc/fstab
/dev/sdb1 |
/sdb1 |
xfs |
defaults |
0 |
要挂载的分区设备 |
挂载点 |
文件系统类型 |
挂载选项 |
是否备份 |
全部挂载:mount -a
2.vim /etc/rc.local (永久挂载)
[root@ken ~]# mount /dev/sdb5 /ww
[root@ken ~]# chmod +x /etc/rc.d/rc.local(赋予权限)
6.添加交换分区
free -h 查看磁盘分区大小
Swap关闭
第一步:划分5G大小的磁盘
[root@ken ~]# fdisk /dev/sdb
Command (m for help): n
Select (default p):
Using default response p
Last sector, +sectors or +size{K,M,G} (206848-41943039, default 41943039): +5G
Command (m for help): P
Command (m for help): w
[root@ken ~]# partprobe
[root@ken ~]# ls /dev/sd*
第二步:格式化操作
[root@ken ~]# mkswap /dev/sdb2
第三步:
[root@ken ~]# free -h
[root@ken ~]# swapon /dev/sdb2挂载
[root@ken ~]# free -h
[root@ken ~]# swapoff /dev/sdb2
第四步:写入到配置文件中
[root@ken ~]# vim /etc/rc.local
第五步:停止swap(使用swapoff可以停止swap)
[root@ken ~]# free -h
[root@ken ~]# swapoff
[root@ken ~]# swapoff -a全部停止挂载
[root@ken ~]# free -h
7.LVM逻辑卷管理器
实战场景:对于生产环境下的服务器来说,如果存储数据的分区磁盘空间不够了怎么办?
8.LVM常用的术语
物理卷PV(physical volume) :硬盘本身;
卷组VG(Volume Group) :一个LVM卷组由一个或多个物理卷组成ll
逻辑卷LV(logical volume) :LV建立在VG之上,可以在LV之上建立文件系统
PE(physical extents) :PV物理卷中可以分配的最小存储单元,PE的大小是可以指定的,默认为4MB
LE(logical extent) : LV逻辑卷中可以分配的最小存储单元,在同一个卷组中,LE的大小和PE是相同的,并且一一对应
9.部署逻辑卷
常用的LVM部署命令
功能/命令 |
物理卷管理 |
卷组管理 |
逻辑卷管理 |
扫描 |
pvscan |
vgscan |
lvscan |
建立 |
pvcreate |
vgcreate |
lvcreate |
显示 |
pvdisplay |
vgdisplay |
lvdisplay |
删除 |
pvremove |
vgremove |
lvremove |
扩展 |
|
vgextend |
lvextend |
缩小 |
|
vgreduce |
lvreduce |
第一步:添加两块磁盘
第二步:让两块硬盘支持LVM技术
[root@ken ~]# pvcreate /dev/sd{b,c}
第三步:创建卷组
[root@ken ~]# vgcreate ww /dev/sdb /dev/sdc (卷组)
[root@ken ~]# vgdisplay
第四步:创建逻辑卷
[root@ken ~]# lvcreate -n qq -L 500M ww
Lvcreate 创建逻辑卷 -n qq (name逻辑卷名字) -L 100M 创建100m大小的逻辑卷 ww(卷组)
[root@ken ~]# Ls /dev/ww/qq
[root@ken ~]# vgdispay
第五步:把生成好的逻辑卷进行格式化
[root@ken ~]# mkfs.xfs /dev/ww/qq
第六步:挂载使用
[root@ken ~]# mkdir /ken
[root@ken ~]# mount /dev/ww/qq /ken
[root@ken ~]# df -h
第六步:开机自启
10.Linux扩容逻辑卷xfs格式
第一步:创建一个逻辑卷并格式化为xfs格式
[root@ken ~]# lvcreate -n 1 -L 300M ww
[root@ken ~]# mkfs.xfs /dev/ww/1
第二步:挂载使用
[root@ken ~]# mount /dev/ww/1 /wete
[root@ken ~]# df -h
第三步:在线扩至600M
[root@ken ~]# lvextend (-r) -L 600M /dev/ww/1
第四步:查看磁盘信息
发现xfs格式的逻辑卷已经扩容至600M
[root@ken ~]# df -h
[root@ken ~]# xfs_growfs /dev/ww/1 调节文件大小
[root@ken ~]# df -h
11.Linux删除逻辑卷
第一步:取消挂载
[root@ken ~]# umount /挂载点 wete/
第二步:删除逻辑卷设备
[root@ken ~]# lvremove /dev/ken/ken1
第三步:删除卷组
[root@ken ~]# vgremove ken
第四步:删除物理卷
[root@ken ~]# pvremove /dev/sdb /dev/sdc