硬盘接口决定着硬盘与计算机之间的连接速度,所以硬盘是一个很重要的属性。
从整体上,硬盘接口类型可分为IDE、SATA、SCSI 、SAS和光纤通道五种,IDE接口硬盘多用于家用产品中,也有部分应用于服务器,SCSI接口的硬盘则主要应用于服务器市场,而光纤通道只在高端服务器上,价格昂贵。SATA是种新生的硬盘接口类型,在家用市场中有着广泛的前景。
IDE ——> SATA I/II/III 个人pc机
SCSI ——> SAS 服务器上
OS | IDE(并口) | SATA(串口) | SCSI |
---|---|---|---|
RHEL5 | /dev/hda | /dev/sda | /dev/sda |
RHEL6 | /dev/sda | /dev/sda | /dev/sda |
RHEL7 | /dev/sda | /dev/sda | /dev/sda |
/dev/sda2
s=硬件接口类型(sata/scsi)
d=disk(硬盘)
a=第1块硬盘(b,第二块),2=第几个分区
/dev/hd h=IDE硬盘 /dev/hdd3
/dev/vd v=虚拟硬盘 /dev/vdf7
HP服务器硬盘
/dev/cciss/c0d0
/dev/cciss/c0d0p1 c0第一个控制器, d0第一块磁盘, p1分区1
/dev/cciss/c0d0p2 c0第一个控制器, d0第一块磁盘, p2分区2
MBR <2TB fdisk
4个主分区或者3个主分区+1个扩展分区(N个逻辑分区)
MBR(Master Boot Record)的缩写,由三部分组成,即:
GPT >2TB gdisk(parted) 128个主分区
注意:从MBR转到GPT,或从GPT转换到MBR会导致数据全部丢失!
之前我们安装了虚拟机,现在需要进行磁盘与分区的实验,现在需要进行克隆。
复制之后可以使用192.168.47.10进行连接(这个时候模板机器不要打开)
修改IP地址
[root@template-host ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
IPADDR=192.168.47.11
[root@template-host ~]# grep IPADDR /etc/sysconfig/network-scripts/ifcfg-ens33
IPADDR=192.168.47.11
[root@template-host ~]# systemctl restart network
后面就使用47.11进行连接
修改主机名
[root@template-host ~]# hostnamectl set-hostname cpgl
[root@template-host ~]# bash
[root@cpgl ~]#
这里就可以看见的磁盘类型,就是上面说明的接口类型,在做一些需要磁盘直连的时候需要选择SATA,一般选择的就是SCSI,现在我们选择SCSI。
完成之后需要重启一下虚拟机
fdisk命令
# lsblk
# df -h 查看正在挂载的设备情况
# fdisk -l 查看当前系统的所有设备分区情况
# fdisk /dev/sdb
#普通机械磁盘一般容量是 硬盘容量 = 柱面数(cylinders)× 盘面数(磁头数)(heads) × 扇区数(sectors) × 扇区大小(一般为512字节)(Sector size)
由于我们这个是固态磁盘所以 硬盘容量 10G = n * 1024 * 1024 * 1024
[root@cpgl ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000e203e
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors #磁盘空间 # 这里是我们新加入的磁盘
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
#扇区大小(逻辑/物理) 都是512字节。
I/O size (minimum/optimal): 512 bytes / 512 bytes
#I/O 大小(最小/最大) 都是512字节。
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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
规划硬盘中的分区
总结:
本例将这个10G的硬盘分区,分区计划:分一个主分区 ,大小3G,文件格式ext4.三个逻辑分区,大小分别为2G,2G,3G。实际分区个数和大小可论情况所定。
[root@cpgl ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000e203e
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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 /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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
#输入 fdisk /dev/sdb 然后回车,给硬盘进行分区。
[root@cpgl ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x5d800ccc.
#输入n回车新建分区
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
#再输入p回车新建主分区
Select (default p): p
#选择分区号在1-4间,输入1回车
Partition number (1-4, default 1): 1
#这里是设置分区起始的序列号,直接回车选择默认即可
First sector (2048-20971519, default 2048):
Using default value 2048
#设置分区大小为3G,输入+3G后回车
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +3G
Partition 1 of type Linux and of size 3 GiB is set
#划分扩展分区,按n回车
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
#输入e,表示创建扩展分区,输入e回车
Select (default p): e
Partition number (2-4, default 2):
First sector (6293504-20971519, default 6293504):
Using default value 6293504
#直接回车选择默认,表示将划分第一个主分区后的磁盘全部划分个这个逻辑分区
Last sector, +sectors or +size{K,M,G} (6293504-20971519, default 20971519):
Using default value 20971519
Partition 2 of type Extended and of size 7 GiB is set
#输入命令p查看当前分区状态
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x5d800ccc
Device Boot Start End Blocks Id System
/dev/sdb1 2048 6293503 3145728 83 Linux
/dev/sdb2 6293504 20971519 7339008 5 Extended
#划分扩展分区sdb2下的逻辑分区
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
#输入l表示选择创建逻辑分区
Select (default p): l
Adding logical partition 5
First sector (6295552-20971519, default 6295552):
Using default value 6295552
#输入+2G,表示划分分区大小为2G
Last sector, +sectors or +size{K,M,G} (6295552-20971519, default 20971519): +2G
Partition 5 of type Linux and of size 2 GiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (10491904-20971519, default 10491904):
Using default value 10491904
#输入+2G,表示划分分区大小为2G
Last sector, +sectors or +size{K,M,G} (10491904-20971519, default 20971519): +2G
Partition 6 of type Linux and of size 2 GiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 7
First sector (14688256-20971519, default 14688256):
Using default value 14688256
#默认,表示划分分区大小为剩余的大小
Last sector, +sectors or +size{K,M,G} (14688256-20971519, default 20971519):
Using default value 20971519
Partition 7 of type Linux and of size 3 GiB is set
#输入p查看当前分区状态
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x5d800ccc
Device Boot Start End Blocks Id System
/dev/sdb1 2048 6293503 3145728 83 Linux
/dev/sdb2 6293504 20971519 7339008 5 Extended
/dev/sdb5 6295552 10489855 2097152 83 Linux
/dev/sdb6 10491904 14686207 2097152 83 Linux
/dev/sdb7 14688256 20971519 3141632 83 Linux
#划分的空间与我们计划划分相同,最后输入w回车,进行保存退出。
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@cpgl ~]#
[root@cpgl ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000e203e
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x5d800ccc
Device Boot Start End Blocks Id System
/dev/sdb1 2048 6293503 3145728 83 Linux
/dev/sdb2 6293504 20971519 7339008 5 Extended
/dev/sdb5 6295552 10489855 2097152 83 Linux
/dev/sdb6 10491904 14686207 2097152 83 Linux
/dev/sdb7 14688256 20971519 3141632 83 Linux
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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
文件系统 mkfs.ext4 /dev/sdb1
#mkfs.ext4 /dev/sdb1
#mkfs.ext4 /dev/sdb5
#mkfs.ext4 /dev/sdb6
#mkfs.ext4 /dev/sdb7
[root@cpgl ~]# mkfs.ext4 /dev/sdb1
mkfs.ext4 /dev/sdb5
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
39321 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): mkfs.ext4 /dev/sdb6
mkfs.ext4 /dev/sdb7done
Writing superblocks and filesystem accounting information: done
[root@cpgl ~]# mkfs.ext4 /dev/sdb5
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@cpgl ~]# mkfs.ext4 /dev/sdb6
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@cpgl ~]# mkfs.ext4 /dev/sdb7
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 785408 blocks
39270 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
分别对磁盘进行格式化处理,格式化为ext4文件类型
mount【开机自动挂载|autofs自动挂载】
mkdir /data1/
mkdir /data5/
mkdir /data6/
mkdir /data7/
mount /dev/sdb1 /data1/
mount /dev/sdb5 /data5/
mount /dev/sdb6 /data6/
mount /dev/sdb7 /data7/
查看挂载情况
[root@cpgl ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.6G 16G 10% /
/dev/sda1 1014M 137M 878M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 2.9G 9.0M 2.8G 1% /data1
/dev/sdb5 2.0G 6.0M 1.8G 1% /data5
/dev/sdb6 2.0G 6.0M 1.8G 1% /data6
/dev/sdb7 2.9G 9.0M 2.8G 1% /data7
配置/etc/fstab
[root@cpgl ~]# vi /etc/fstab
/dev/sdb1 ext4 /data1/
/dev/sdb5 ext4 /data5/
/dev/sdb6 ext4 /data6/
/dev/sdb7 ext4 /data7/
[root@localhost ~]# mkswap /dev/sdb5 //格式化交换分区
Setting up swapspace version 1, size = 2006929 kB
[root@localhost ~]# swapon /dev/sdb5 //启用交换分区
[root@localhost ~]# free | grep -i swap
Swap: 3008456 0 3008456
[root@localhost ~]# swapoff /dev/sdb5 //停用交换分区
[root@localhost ~]# free | grep -i swap //查看交换空间
Swap: 1048568 0 1048568
SWAP的优先级设定
实现磁盘限额的条件
Linux磁盘限额的特点
启用文件系统的配额支持
[root@localhost ~]# vi /etc/fstab
/dev/sdb1 /mailbox ext3 default,usrquota,grpquota 0 0
[root@localhost ~]# mount /mailbox
[root@localhost ~]# mount | tail -1
/dev/sdb1 on /mailbox type ext3 (rw,usrquota,grpquota)
[root@localhost ~]# quotacheck -ugcv /dev/sdb1
quotacheck: Scanning /dev/sdb1 [/mailbox]
……
done
[root@localhost ~]# ls -l /mailbox/aquota.*
-rw------- 1 root root 6144 09-14 12:04 /mailbox/aquota.group
-rw------- 1 root root 6144 09-14 12:04 /mailbox/aquota.user
[root@localhost ~]# edquota -u zhangsan
Disk quotas for user zhangsan (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 80000 100000 0 40 50
第3列:磁盘容量软限制 第6列:文件个数软限制
第4列:磁盘容量硬限制 第7列:文件个数硬限制
[root@localhost ~]# edquota -g users
Disk quotas for group users (gid 100):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 252 0 1024000 39 0 0
[root@localhost ~]# quotaon -ugv /mailbox
/dev/sdb1 [/mailbox]: group quotas turned on
/dev/sdb1 [/mailbox]: user quotas turned on
[root@localhost ~]# quotaoff -ugv /mailbox
/dev/sdb1 [/mailbox]: group quotas turned off
/dev/sdb1 [/mailbox]: user quotas turned off
[zhangsan@mail ~]$ cd /mailbox
[zhangsan@mail mailbox]$ dd if=/dev/zero of=myfile bs=1M count=120
sdb1: warning, user block quota exceeded.
sdb1: write failed, user block limit reached.
dd: 写入 “myfile”: 超出磁盘限额
……
[root@localhost ~]# quota -u zhangsan
Disk quotas for user zhangsan (uid 515):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 100000* 80000 100000 1 40 50
[root@localhost ~]# quota -g users
Disk quotas for group users (gid 10): none
[root@localhost ~]# repquota -v /mailbox
*** Report for user quotas on device /dev/sdb1
Block grace time: 3days; Inode grace time: 3days
Block limits File limits
User used soft hard grace used soft hard grace