unit4~~管理系统中的简单分区和文件系统
2017-04-26 17:42
393 查看
1.查看分区信息
p:主分区E:扩展分区
l:逻辑分区
fdisk -l 显示系统中所有可以使用的设备信息
blkid 显示系统正在使用的设备 id
partprobe 将磁盘分区表的变化信息通知内核,请求系统重新加载分区表
2.创建磁盘分区
[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 0x92763b95. Command (m for help): n ##创建新分区 Partition type: p primary (0 primary, 0 extended, 4 free) ##主分区 e extended ##扩展分区 Select (default p): p ##显示分区结果 Partition number (1-4, default 1): ##默认分区编号为1 First sector (2048-20971519, default 2048): ##默认起始为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: 0x92763b95 Device Boot Start End Blocks Id System ##创建成功显示 /dev/vdb1 2048 206847 102400 83 Linux 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 ##列出系统可用的分区类型 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]# 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 253 21 102400 vdb5 [root@localhost Desktop]#
用脚本实现分区
编写如下脚本文件文件系统比较
• ext4 是 Red Hat Enterprise Linux 6 的标准文件系统。它非常强大可靠 , 具有多项可以提高现代工作量处理性能的功能
• ext2 是常用于 Linux 中的较旧的文件系统。它简单可靠 , 非
常适合小型存储设备 , 但是效率低于 ext4
• vfat 支持包括一系列相关文件系统 ( VFAT/FAT16 和
FAT32 ), 这些文件系统针对较旧版本的 Microsoft Windows
开发 , 在大量的系统和设备上受支持
• xfs 在 Red Hat Enterprise Linux 7 的标准文件系统
其具备数据完全性 、性能稳定、扩展性强( 18eb )、传输速
率高( 7G/s )
3.文件系统的创建
[root@localhost ~]# mkfs.xfs /dev/vdb5 ##格式化分区 meta-data=/dev/vdb5 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 You have mail in /var/spool/mail/root [root@localhost ~]# blkid ##查看可用分区 /dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" /dev/vdb5: UUID="52e56675-4da6-4012-8841-3af34d568a30" TYPE="xfs" [root@localhost ~]# mount /dev/vdb5 /mnt/ ##一次性挂载 [root@localhost ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 3298672 7175228 32% / devtmpfs 927072 0 927072 0% /dev tmpfs 942660 140 942520 1% /dev/shm tmpfs 942660 664 941996 1% /run tmpfs 942660 0 942660 0% /sys/fs/cgroup /dev/vdb5 98988 5280 93708 6% /mnt [root@localhost ~]# umount /mnt/ [root@localhost ~]# vim /etc/fstab ##编辑文件,开机自动挂载 [root@localhost ~]# mount -a ##重新加载上面的文件,使新增内容生效 [root@localhost ~]# df ##查看挂载情况 Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 3298468 7175432 32% / devtmpfs 927072 0 927072 0% /dev tmpfs 942660 140 942520 1% /dev/shm tmpfs 942660 664 941996 1% /run tmpfs 942660 0 942660 0% /sys/fs/cgroup /dev/vdb5 98988 5280 93708 6% /mnt [root@localhost ~]#
4.删除硬盘分区
[root@localhost ~]# umount /mnt/ ##文件卸载 [root@localhost ~]# vim /etc/fstab ##删除刚才编辑的内容 [root@localhost ~]# 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/v 4000 db: 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: 0x92763b95 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): d ##删除分区,默认为编号5 Partition number (1-5, default 5): Partition 5 is deleted Command (m for help): d ##删除分区,默认编号为4 Partition number (1-4, default 4): Partition 4 is deleted Command (m for help): d ##删除分区,默认编号为3 Partition number (1-3, default 3): Partition 3 is deleted Command (m for help): d ##删除分区,默认编号为2 Partition number (1,2, default 2): Partition 2 is deleted Command (m for help): d ##删除分区,默认编号为1 Selected partition 1 Partition 1 is deleted Command (m for help): Command (m for help): d No partition is defined yet! Command (m for help): wq The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]# partprobe [root@localhost ~]#
5.新建swap分区
• 换空间或交换区是磁盘驱动器上的空间 , 用作当前未使用部分内存的溢出。这样 , 系统
就能在主内存中留出空间用于储存当前正在
处理的数据 , 并在系统面临主内存空间不足
的风险时提供应急溢出
管理交换分区
• 使用 fdisk 创建新分区。此外 , 在用 fdisk 保存
更改之前 , 将分区类型更改为 “ 0x82 Linux
Swap”
• mkswap /dev/vdaN 会准备好将分区用作交换区
• blkid /dev/vdaN 将确定 UUID
• 将新交换空间添加到 /etc/fstab :
UUID=uuid swap swap defaults 0 0
• swapon -a 将激活新交换区
• swapon -s 将显示当前交换区的状态
• swapoff /dev/vdaN 将停用该特定交换区
[root@localhost ~]# 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 (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): +4G Partition 1 of type Linux and of size 4 GiB is set Command (m for help): t ##编辑分区类型 Selected partition 1 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 ##选择类型为swap分区 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: 0x92763b95 Device Boot Start End Blocks Id System /dev/vdb1 2048 8390655 4194304 82 Linux swap / Solaris Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (8390656-20971519, default 8390656): Using default value 8390656 Last sector, +sectors or +size{K,M,G} (8390656-20971519, default 20971519): +1G Partition 2 of type Linux and of size 1 GiB is set Command (m for help): t Partition number (1,2, default 2): Hex code (type L to list all codes): 82 Changed type of partition 'Linux' to 'Linux swap / Solaris' Command (m for help): wq The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]# partprobe ##更新分区信息表 [root@localhost ~]# cat /proc/partitions ##查看分区信息表 major minor #blocks name 253 0 10485760 vda 253 1 10484142 vda1 253 16 10485760 vdb 253 17 4194304 vdb1 253 18 1048576 vdb2 [root@localhost ~]# blkid /dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" [root@localhost ~]# mkswap /dev/vdb1 ##格式化swap分区 Setting up swapspace version 1, size = 4194300 KiB no label, UUID=a627428d-0bdf-4f32-86a8-0c2770dc63c4 [root@localhost ~]# blkid /dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" /dev/vdb1: UUID="a627428d-0bdf-4f32-86a8-0c2770dc63c4" TYPE="swap" [root@localhost ~]# mkswap /dev/vdb2 Setting up swapspace version 1, size = 1048572 KiB no label, UUID=55b9d429-7a48-4fa2-8ec0-d0954dd62edf [root@localhost ~]# blkid /dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" /dev/vdb1: UUID="a627428d-0bdf-4f32-86a8-0c2770dc63c4" TYPE="swap" /dev/vdb2: UUID="55b9d429-7a48-4fa2-8ec0-d0954dd62edf" TYPE="swap" [root@localhost ~]# swapon -a /dev/vdb1 ##将激活新交换区 [root@localhost ~]# swapon -s ##将显示当前交换区的状态 Filename Type Size Used Priority /dev/vdb1 partition 4194300 0 -1 [root@localhost ~]# swapon -a /dev/vdb2 [root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/vdb1 partition 4194300 0 -1 /dev/vdb2 partition 1048572 0 -2 [root@localhost ~]# swapoff /dev/vdb2 ##将停用该特定交换区 [root@localhost ~]# swapon -a /dev/vdb2 -p 1 ##将激活新交换区,并编写优先级为1 [root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/vdb1 partition 4194300 0 -1 /dev/vdb2 partition 1048572 0 1 [root@localhost ~]# vim /etc/fstab [root@localhost ~]# swapoff /dev/vdb{1,2} [root@localhost ~]# swapon /dev/vdb{1,2} [root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/vdb1 partition 4194300 0 -1 /dev/vdb2 partition 1048572 0 -2 [root@localhost ~]# swapoff /dev/vdb{1,2} [root@localhost ~]# swapon -s [root@localhost ~]# vim /etc/fstab [root@localhost ~]# swapon -a [root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/vdb1 partition 4194300 0 -1 /dev/vdb2 partition 1048572 0 2 [root@localhost ~]#
开机自动挂载编写如下内容:
6.磁盘的使用大小限制
[root@localhost ~]# mkfs.xfs /dev/vdb1 -f meta-data=/dev/vdb1 isize=256 agcount=4, agsize=65536 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@localhost ~]# mount -o usrquota,grpquota /dev/vdb1 /pub/ //挂载时加上用户配额和组配额 [root@localhost ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 3297908 7175992 32% / devtmpfs 927072 0 927072 0% /dev tmpfs 942660 140 942520 1% /dev/shm tmpfs 942660 652 942008 1% /run tmpfs 942660 0 942660 0% /sys/fs/cgroup /dev/vdb1 1038336 32936 1005400 4% /pub [root@localhost ~]# quotaon -ugv /dev/vdb1 ##生成配置文件 quotaon: Enforcing group quota already on /dev/vdb1 quotaon: Enforcing user quota already on /dev/vdb1 [root@localhost ~]# edquota -u student ##编辑用户student的配额 [root@localhost ~]# chmod 777 /pub/ ##编辑目录权限 [root@localhost ~]# su - student ##切换用户进行测试 Last login: Sat Apr 22 05:51:10 CST 2017 on pts/1 [student@localhost ~]$ dd if=/dev/zero of=/pub/file bs=1M count=201 dd: error writing ‘/pub/file’: Disk quota exceeded ##测试成功 21+0 records in 20+0 records out 20971520 bytes (21 MB) copied, 0.0121605 s, 1.7 GB/s [student@localhost ~]$ dd if=/dev/zero of=/pub/file bs=1M count=19 19+0 records in 19+0 records out 19922944 bytes (20 MB) copied, 0.0133879 s, 1.5 GB/s [student@localhost ~]$ exit logout [root@localhost ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 3298108 7175792 32% / devtmpfs 927072 0 927072 0% /dev tmpfs 942660 140 942520 1% /dev/shm tmpfs 942660 652 942008 1% /run tmpfs 942660 0 942660 0% /sys/fs/cgroup /dev/vdb1 1038336 52400 985936 6% /pub [root@localhost ~]#
7.增加磁盘读写速度
8.创建新加密的卷
• 使用 fdisk 创建新分区• cryptsetup luksFormat /dev/vdaN 可对新分区进行加密 ,
并设置解密密码
• 您输入正确的解密密码之后 , cryptsetup luksOpen
/dev/vdaN name 会将加密的卷 /dev/vdaN 解锁为
/dev/mapper/name
• 解密的卷上创建 xfs 文件系统 : mkfs -t xfs
/dev/mapper/name
• 创建目录挂载点 , 并挂载文件系统 : mkdir /secret
– mount /dev/mapper/name /secret
• 完成之后 , umount /dev/mapper/name 并运行
cryptsetup luksClose name 以锁定加密的卷
.
相关文章推荐
- Linux--RH134---unit 4 管理系统中的简单分区和文件系统
- 第二课unit4 管理系统中的简单分区和文件系统
- unit2.4管理系统中的简单分区和文件系统
- RHEL-RH134-UNIT4--管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- 第四 管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- Linux运维笔记----管理系统中的简单分区和文件系统
- ##II 第四单元##管理系统中的简单分区和文件系统
- 管理系统简单的分区和文件系统
- 管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- unit4 管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- Linux运维笔记-文档总结-管理系统中的简单分区和文件系统
- Linux高级管理之管理系统中的简单分区和文件系统
- liunx初级学习之管理系统中的简单分区和文件系统2-4
- 【基础部分】之管理系统中的简单分区和文件系统
- Linux学习第四单元-管理系统中的简单分区和文件系统
- linux服务器 磁盘和文件系统管理(一)管理磁盘及分区