在开始之前,先了解一些基础知识。
常见的文件系统 | 作用 |
---|---|
ext4 | 是 Red Hat Enterprise Linux 6 的标准文件系统。它非常强大可靠 , 具有多项可以提高现代工作量处理性能的功能。 |
ext3 | 最多只能支持32TB的文件系统和2TB的文件,实际只能容纳2TB的文件系统和16GB的文件 |
ext2 | 是常用于 Linux 中的较旧的文件系统。它简单可靠 ,非常适合小型存储设备,但是效率低。 |
vfat | 支持包括一系列相关文件系统 ( VFAT/FAT16/FAT32 ), 这些文件系统针对较旧版本的 Microsoft Windows 开发 , 在大量的系统和设备上受支持。 |
xfs | 在 Red Hat Enterprise Linux 7 的标准文件系统其具备数据完全、性能稳定、扩展性强 ( 8eb-1byte ) 、传输速率高 ( 7G/s ) |
我们先来了解一些如何查看本地存储设备呢?
命令 | 含义 |
---|---|
fdisk -l | 列出磁盘分区信息,系统中真实存在的硬盘,但是不一定能够识别 |
cat /proc/partitions | 系统可以识别的,但是不一定能用 |
blkid | 列出系统中可以使用的设备id,系统能够识别,也能够使用的 |
df | 查看系统中正在使用的设备信息,系统正在挂载的设备 |
fdisk -l 列出磁盘分区信息,系统中真实存在的硬盘,但是不一定能够识别
图
cat /proc/partitions 系统可以识别的,但是不一定能用
blkid 列出系统中可以使用的设备id,系统能够识别,也能够使用的
df 查看系统中正在使用的设备信息,系统正在挂载的设备
/dev/xdx
##/dev/hd0 /dev/hd1 (并口硬盘)/dev/sda /dev/sdb (串口硬盘SATA)/dev/vda /dev/vdb 系统中的虚拟硬盘
/dev/mapper/* ##虚拟设备
/sda ##系统第一块串口硬盘,a代表第一块
/cdrom,/dev/sr0 ##代表光驱
mount 设备 挂载点 #挂载
umount /mnt #卸载挂载到/mnt下,可能会挂载到别的目录下
umount /dev/sdb1 #卸载/dev/sdb1s上的挂载
mount -o ro /dev/sdb1 /mnt/ #只读挂载
mount -o remount,rw /dev/sdb1 或者 /mnt/ #重新读写挂载
mount #查看挂载信息
fuser -kvm /mnt
umount /mnt
方法2:
lsof /mnt/ 查看/mnt上使用的情况
kill -9 进程号
umount /mnt
512 = 446 +64 +2 字节
mbr dpt 55AA
mbr 硬盘主引导程序
dpt 硬盘分区表(DPT)
55AA 两个字节(55 AA)属于分区结束标志
主分区:用主分区表记录的分区
扩展分区:主分区表记录的容器,不能直接使用
逻辑分区:容器中的分区,我们后面会提到的LVM
fdisk -l
[root@localhost Desktop]# fdisk -l
Disk /dev/vda: 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: 0x00013f3e
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 20970332 10484142+ 83 Linux
Disk /dev/vdb: 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
fdisk /dev/vdb
进入相关分区界面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 ##删除
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types ##查询分区id
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 ##修改分区id
u change display/entry units
v verify the partition table
w write table to disk and exit ##保存分区标信息到硬盘
x extra functionality (experts only)
[root@localhost Desktop]# fdisk /dev/vdb
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 0x312c67f3.
Command (m for help): n ##新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free) ##主分区
e extended ##扩展分区
Select (default p):
Using default response p ##选择默认
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M ##100M大小
Partition 1 of type Linux and of size 100 MiB is set
Command (m for help): p ##查看分区
Disk /dev/vdb: 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: 0x312c67f3
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
Command (m for help): wq ##保存并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
mkfs.xfs /dev/vdb1
我们需要对分区格式化成想要的文件系统才可以进行文件的操作。[root@localhost Desktop]# mkfs.xfs /dev/vdb1
meta-data=/dev/vdb1 isize=256 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
查看是否成功,就是查看可用设备blkid
,此时/dev/vdb1为可用设备
[root@localhost Desktop]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/vdb1: UUID="0168a321-bdd9-4ef5-b476-83de5ecd8b63" TYPE="xfs"
[root@localhost Desktop]# mount /dev/vdb1 /mnt/
[root@localhost Desktop]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3165192 7308708 31% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 140 484792 1% /dev/shm
tmpfs 484932 12736 472196 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/vdb1 98988 5280 93708 6% /mnt
成功啦!
[root@localhost Desktop]# fdisk /dev/vdb
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.
Command (m for help): n ####继续添加分区
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (206848-20971519, default 206848):
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +100M
Partition 2 of type Linux and of size 100 MiB is set
Command (m for help): p
Disk /dev/vdb: 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: 0x312c67f3
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 411647 102400 83 Linux
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3):
First sector (411648-20971519, default 411648):
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-20971519, default 20971519): +100M
Partition 3 of type Linux and of size 100 MiB is set
Command (m for help): p
Disk /dev/vdb: 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: 0x312c67f3
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 411647 102400 83 Linux
/dev/vdb3 411648 616447 102400 83 Linux
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): ####当添加到第四个分区,默认分区为扩展分区e
Using default response e
Selected partition 4
First sector (616448-20971519, default 616448):
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-20971519, default 20971519): ##默认大小全部给扩展分区,否则剩下的就浪费了
Using default value 20971519
Partition 4 of type Extended and of size 9.7 GiB is set
Command (m for help): p
Disk /dev/vdb: 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: 0x312c67f3
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 411647 102400 83 Linux
/dev/vdb3 411648 616447 102400 83 Linux
/dev/vdb4 616448 20971519 10177536 5 Extended
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
当出现warning:
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.
我们需要手动同步分区表:
[root@localhost Desktop]# partprobe
[root@localhost Desktop]# cat /proc/partitions ##查看系统可以识别的分区,发现成功
major minor #blocks name
253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
253 17 102400 vdb1
253 18 102400 vdb2
253 19 102400 vdb3
253 20 1 vdb4
vim /etc/fatab 开机自动挂载策略文件
/dev/vdb5 /mnt xfs defaults 0 0
分区 挂载点 格式 挂载参数 是否备份 是否检测
[root@localhost Desktop]# swapon -s
[root@localhost Desktop]# fdisk /dev/vdb
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.
Command (m for help): p
Disk /dev/vdb: 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: 0x312c67f3
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 411647 102400 83 Linux
/dev/vdb3 411648 616447 102400 83 Linux
/dev/vdb4 616448 20971519 10177536 5 Extended
/dev/vdb5 618496 823295 102400 83 Linux
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (825344-20971519, default 825344):
Using default value 825344
Last sector, +sectors or +size{K,M,G} (825344-20971519, default 20971519): +100M
Partition 6 of type Linux and of size 100 MiB is set
Command (m for help): p
Disk /dev/vdb: 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: 0x312c67f3
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 411647 102400 83 Linux
/dev/vdb3 411648 616447 102400 83 Linux
/dev/vdb4 616448 20971519 10177536 5 Extended
/dev/vdb5 618496 823295 102400 83 Linux
/dev/vdb6 825344 1030143 102400 83 Linux
Command (m for help): t ####更改类型
Partition number (1-6, default 6): 6
Hex code (type L to list all codes): l
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 82 ##改换分区
Changed type of partition 'Linux' to 'Linux swap / Solaris'
Command (m for help): p
Disk /dev/vdb: 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: 0x312c67f3
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 411647 102400 83 Linux
/dev/vdb3 411648 616447 102400 83 Linux
/dev/vdb4 616448 20971519 10177536 5 Extended
/dev/vdb5 618496 823295 102400 83 Linux
/dev/vdb6 825344 1030143 102400 82 Linux swap / Solaris
Command (m for help): wq
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.
mkswap /dev/vdb6
[root@localhost Desktop]# swapon -a /dev/vdb6
[root@localhost Desktop]# swapon -s
Filename Type Size Used Priority
/dev/vdb6 partition 102396 0 -1
swapoff /dev/vdb6
[root@localhost Desktop]# fdisk /dev/vdb
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.
Command (m for help): d ##删除设备
Partition number (1-6, default 6): 6
Partition 6 is deleted
Command (m for help): p
Disk /dev/vdb: 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: 0x312c67f3
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 411647 102400 83 Linux
/dev/vdb3 411648 616447 102400 83 Linux
/dev/vdb4 616448 20971519 10177536 5 Extended
/dev/vdb5 618496 823295 102400 83 Linux
Command (m for help): wq
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.
partprobe
就是限制用户对磁盘空间的使用量。
原因:因为Linux是多用户多任务的操作系统,用户共用磁盘空间,为了合理的分配磁盘空间,于是就有了quota的出现。
quota的用途:显示磁盘使用情况和配额
quota的一般作用对象
(1)针对Web server
(2)针对mail server
(3)针对file server
quota的限制
(1)仅能针对整个文件系统
(2)需要kernel的支持
(3)只对一般用户有效
mount -o usrquota /dev/vdb5 /westos
chmod 777 /westos
filesystem blocks soft hard inodes soft hard
1 2 3 4 5 6 7
1:文件系统,说明该限制值时针对哪个文件系统
2:磁盘容量,这个值由quota计算,不要更改
3:磁盘容量的soft限制值
4:磁盘容量的hard限制值
5:文件数量,这个值由quota计算,不要改动
6:inode的soft值
7:inode的hard值
soft/hard为0时,表示没有限制,我们需要的是设置blocks的soft/hard值,inode的不要更改
/dev/vdb5 /pub xfs defauits,usrquota 0 0
此时,student用户就只有2M的磁盘配额空间,也就是不能放入超过2M的文件,否则就会报错。
umount /mac
cryptsetup close mac
umount /mac
cryptsetup close mac
mkfs.xfs /dev/vdb1 -f ##强制格式化设备