码迷,mamicode.com
首页 > 其他好文 > 详细

RH134 UNIT4

时间:2017-04-24 23:10:01      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:redhat

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


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

三.创建新分区

1.创建新分区

[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                           ###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.
[root@localhost ~]# partprobe                 ###同步分区表
[root@localhost ~]# 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

[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): 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.
[root@localhost ~]# partprobe
技术分享


四.swap分区的管理

[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): +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

[root@localhost westos]# mount -o usrquota,grpquota /dev/vdb1 /pub/ ###挂载时开启quota
[root@localhost 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可使用的空间

[root@localhost westos]# su westos                                ###切换用户
[westos@localhost ~]$ 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
[westos@localhost ~]$ du -sh /pub/                                ###查看/pub下文件大小
200M    /pub/                                                            

技术分享


六.磁盘阵列

建立raid功能的三个分区

[root@localhost 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.
[root@localhost westos]# partprobe
[root@localhost westos]# clear
[3;J
[root@localhost 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        ##停止设备


七.分区加密

[root@desktop ~]# cryptsetup luksFormat /dev/vdb1

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

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

技术分享


设备解密

[root@desktop ~]# cryptsetup open /dev/vdb1 disk           ###打开加密设备
Enter passphrase for /dev/vdb1:
[root@desktop ~]# 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
[root@desktop ~]# mount /dev/mapper/disk /mnt/         ###挂载设备
[root@desktop ~]# umount /mnt/                                   ###卸载设备
[root@desktop ~]# cryptsetup close disk                       ###关闭设备加密层

技术分享

技术分享


自动挂载加密设备

设定开机解密

vim /etc/cryptab

技术分享

配置/etc/fstab

技术分享

写密码文件

vim /root/passwd

技术分享

配置解密密码

cryptsetup   luksAddKey   /dev/vdb1   /root/passwd

技术分享


RH134 UNIT4

标签:redhat

原文地址:http://supermk.blog.51cto.com/12763230/1918981

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!