RH134 UNIT4

管理系统中的简单分区和文件系统

一.简单分区和文件系统
     存储是每个计算机系统的基本需求。 Red Hat EnterpriseLinux 提供了一些强大的工具 , 它们能在       大量的场景中管理多种类型的存储设备
    disk 是用于管理磁盘分区的实用程序。您可以通过选择 -l选项和指定磁盘名称 ( fdisk -cul/dev/vda)         运行该实用程序 , 以查看磁盘及其分区。您可以通过交互式地运行该实用程序 , 并选择相应的菜            单选项 ( fdisk -cu /dev/vda ) 进行更改。 -c 禁用旧的 DOS 兼容模式 , -u 以扇区 ( 而不是柱            面已经过时 ) 的格式显示输出
二.查看系统设备信息
     fdisk -l
        – 显示系统中所有可以使用的设备信息
     blkid
        – 显示系统正在使用的设备 id

三.创建新分区

1.创建新分区

[[email protected] ~]# 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                           ###m查看帮助 n新建分区

Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):                                       ###p主逻辑卷 e扩展分区
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): +500M ##大小
Partition 1 of type Linux and of size 500 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: 0x4a3c53fa

Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     1026047      512000   83  Linux

Command (m for help): wq                        ###保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] ~]# partprobe                 ###同步分区表
[[email protected] ~]# mkfs.xfs /dev/vdb1  ###格式化新建分区为xfs文件系统
meta-data=/dev/vdb1              isize=256    agcount=4, agsize=32000 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=128000, 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

2.挂载分区

自动挂载

编辑配置文件 /etc/fstab

3.删除分区

卸载分区

umount /mnt

删除分区

配置文件/etc/fstab

[[email protected] ~]# 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
Selected partition 1
Partition 1 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: 0x4a3c53fa

Device Boot      Start         End      Blocks   Id  System

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] ~]# partprobe

四.swap分区的管理

[[email protected] ~]# 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): +100M
Partition 1 of type Linux and of size 100 MiB is set

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 (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): t        ###修改分区功能标签
Partition number (1,2, default 2): 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
Changed type of partition ‘Linux‘ to ‘Linux swap / Solaris‘

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): 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: 0x4a3c53fa

Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   82  Linux swap / Solaris
/dev/vdb2          206848      411647      102400   82  Linux swap / Solaris

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

格式化swap分区

mkswap /dev/vdb{1..2}

挂载swap分区

swapon -a /etc/vdb*      ###激活swap分区

wapon -s                       ###查看swap分区状态

开机自动激活

配置/etc/fstab

优先级priority设定

1激活时加入参数-p num

swapon -a /dev/vdb1 -p num

2配置fstab

五.分区配额

分区并格式化

挂载并开启quota

[[email protected] westos]# mount -o usrquota,grpquota /dev/vdb1 /pub/ ###挂载时开启quota
[[email protected] westos]# df -h                       ###查看挂载状态
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        10G  3.1G  7.0G  31% /
devtmpfs        906M     0  906M   0% /dev
tmpfs           921M   80K  921M   1% /dev/shm
tmpfs           921M   21M  901M   3% /run
tmpfs           921M     0  921M   0% /sys/fs/cgroup
/dev/vdb1      1014M   33M  982M   4% /pub

设置用户westos的限制

edquota -u westos

测试westos可使用的空间

[[email protected] westos]# su westos                                ###切换用户
[[email protected] ~]$ dd if=/dev/zero of=/pub/file bs=1M count=10000###截取1G到/pub

dd: error writing ‘/pub/file’: Disk quota exceeded
201+0 records in
200+0 records out
209715200 bytes (210 MB) copied, 0.077746 s, 2.7 GB/s
[[email protected] ~]$ du -sh /pub/                                ###查看/pub下文件大小
200M    /pub/

六.磁盘阵列

建立raid功能的三个分区

[[email protected] westos]# 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
Selected partition 1
Partition 1 is deleted

Command (m for help): d
No partition is defined yet!

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: 0x4a3c53fa

Device Boot      Start         End      Blocks   Id  System

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] westos]# partprobe
[[email protected] westos]# clear
[3;J
[[email protected] westos]# 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): +100M
Partition 1 of type Linux and of size 100 MiB is set

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 (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): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p):
Using default response 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): t
Partition number (1-3, default 3): 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): fd
Changed type of partition ‘Linux‘ to ‘Linux raid autodetect‘

Command (m for help): t
Partition number (1-3, default 3): 2
Hex code (type L to list all codes): fd
Changed type of partition ‘Linux‘ to ‘Linux raid autodetect‘

Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): fd
Changed type of partition ‘Linux‘ to ‘Linux raid autodetect‘

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: 0x4a3c53fa

Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   fd  Linux raid autodetect
/dev/vdb2          206848      411647      102400   fd  Linux raid autodetect
/dev/vdb3          411648      616447      102400   fd  Linux raid autodetect

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

新建raid分区

mdadm -C /dev/md0 -l 1 -n 2 -x 1 /dev/vdb{1..3}

mdadm -D /dev/md0    ##设备配置信息
mdadm /dev/md0    -f /dev/vdb1    ##损坏设备1
mdadm /dev/md0 -r /dev/vdb1     ##移除设备1
mdadm /dev/md0 -a /dev/vdb1    ##恢复设备1
mdadm -S /dev/md0        ##停止设备

七.分区加密

[[email protected] ~]# cryptsetup luksFormat /dev/vdb1

WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.

Are you sure? (Type uppercase yes): YES            ###是否加密
Enter passphrase:                                               ###请输入密码
Verify passphrase:                                              ###确认密码

设备解密

[[email protected] ~]# cryptsetup open /dev/vdb1 disk           ###打开加密设备
Enter passphrase for /dev/vdb1:
[[email protected] ~]# mkfs.xfs /dev/mapper/disk -f                ###格式化设备
meta-data=/dev/mapper/disk       isize=256    agcount=4, agsize=6272 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=25088, 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
[[email protected] ~]# mount /dev/mapper/disk /mnt/         ###挂载设备
[[email protected] ~]# umount /mnt/                                   ###卸载设备
[[email protected] ~]# cryptsetup close disk                       ###关闭设备加密层

自动挂载加密设备

设定开机解密

vim /etc/cryptab

配置/etc/fstab

写密码文件

vim /root/passwd

配置解密密码

cryptsetup   luksAddKey   /dev/vdb1   /root/passwd

时间: 2024-12-24 05:49:20

RH134 UNIT4的相关文章

linux运维基础篇 unit4

#### unit4 #### #### 1.管理输入输出 #### 在linux系统中,正确输出的编号为1,错误输出编号为2 在系统中用普通用户执行 "student" find /etc -name passwd 因为student用户权限问题会有以下输出 find: '/etc/pki/CA/private': Permission denied##没有进入权力,报错 find: '/etc/pki/rsyslog': Permission denied find: '/etc/

Linux 2 unit4

unit4  管理系统中的简单分区和文件系统 ###磁盘划分###分为主分区<最多四个>和扩展分区(可划分为逻辑分区<一般16个>)口令:fdisk /dev/vdb过程:[[email protected] ~]# fdisk /dev/vdb    ##划分磁盘Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them.Be ca

unit4 管理系统中的简单分区和文件系统

*************unit4 管理系统中的简单分区和文件系统********** 1.学习目标 添加文件系统空间 增添swap交换分区 读系统分区加密 2.查看磁盘的命令 fdisk -l /*显示系统中所有可以使用的设备信息 blkid /*显示系统正在使用的设备id 3.文件系统的比较 fs:vfat/ntfs(windows上面的文件系统) ext(日志系统32T)xfs(18eb)文件系统. 4.系统启动过程的了解 1)bios自检 bios:又称为基本输入/输出系统. 2)启动

Unit4中的Annotation

Unit4中的Annotation(注解.注释) JUnit4 使用 Java 5 中的注解(annotation),以下是JUnit4 常用的几个annotation介绍@Before:初始化方法@After:释放资源@Test:测试方法,在这里可以测试期望异常和超时时间@Ignore:忽略的测试方法@BeforeClass:针对所有测试,只执行一次,且必须为static void@AfterClass:针对所有测试,只执行一次,且必须为static void一个JUnit4 的单元测试用例执

RH134 UNIT1

一.自动安装 RED HAT ENTERPRISE LINUX Kickstart 概述 使用 kickstart, 系统管理员可以创建一个包含安装期间所有常见问题的答案的文件 , 以自动安装RedHat Enterprise Linux Kickstart 类似于 Oracle solaris 中的Jumpstart 或 Microsoft Windows 的无人值守安装 安装system-config-kickstart 2.创建*.cfg文件 3.自动安装脚本

RH134 UNIT2

一.控制对文件的访问 读取文件权限[[email protected] Desktop]$ getfacl file# file: file 文件名称# owner: kiosk 文件所有人# group: kiosk 文件所有组user::rw- 用户权限user:kiosk:rwx 特殊指派用户及权限group::rw- 组权限mask::rwx 可指派最大权限other::r-- 其他人权限 2.设定权限列表 setfacl -m u:bob:rw filename         – 授

RH134 UNIT7

第七单元 访问网络文件共享服务 1.CIFS CIFS 是针对windows操作系统的本地文件网络文件系统 安装samba-client.x86_64 识别共享 smbclient -L //ip 挂载 mount //ip/sharename /mnt -o username=guest ###挂载共享文件 windows中匿名用户为guest 自动挂载 2.NFS NFS是由linux,unix及其他类似操作系统使用的互联网标准协议 安装nfs-utils yum install nfs-u

RH134 UNIT8

第八单元  LDAP网络用户账户 安装ldap客户端所需软件 yum sssd krb5-workstation -y 开启ldap用户认证 authconfig-tui 自动安装并配置auth脚本 #/bin/bashecho "install packages..."yum install sssd krb5-workstation autofs -y &> /dev/null     ###安装所需软件echo "config autoconfig...&

RH134 UNIT6

第六单元  文本处理工具 1.diff diff命令用于比较两个文件的内容,以了解其区别.还可以用于创造补丁文件 参数 -c    显示上下文周围的内容 -u    使用统一输出格式(用于生成补丁) -r     从指定的目录开始文件执行递归式比较 创建两个text文件 vim /mnt/old hellow world vim /mnt/new hellow world 123 用diff命令比较这两个文件的不同 2.patch patch 采用补丁文件  patchfile(包含由diff生