四章

  1. 描述GPT是什么,应该怎么使用。

GPT—GUID分区表,GPT提供了更加灵活的磁盘分区机制,分区指物理或逻辑磁盘上彼此连接的存储空间。以及优点
支持2TB的大磁盘
每个分区硬盘分区个数几乎没有限制
分区表自带备份、在磁盘首尾部分别保存了一份相同的分区表,其中一份破坏、可通过另一份恢复
每个分区都可以有一个名称
循环冗余检验值针对关键数据结构而计算,提高了数据崩溃的检测几率

  1. **创建一个10G的分区,并格式化为ext4文件系统。要求:
    (1)block大小为2048,预留空间20%,卷标为MYDATA,
    (2) 挂载至/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳。
    (3)可开机自动挂载。
      [root@JiangXiaoXiao ~]~**~fdisk /dev/sdc**
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 0x4083d30b.
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): 
First sector (2048-125829119, default 2048): +10G
Last sector, +sectors or +size{K,M,G} (20971520-125829119, default 125829119): +10G
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): p

Disk /dev/sdc: 64.4 GB, 64424509440 bytes, 125829120 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: 0x4083d30b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1        20971520    41943039    10485760   83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.
 [root@JiangXiaoXiao ~]~~ mkfs.ext4 -b 2048 -m 20 -L MYDATA  /dev/sdc1
[root@JiangXiaoXiao ~]~~blkid
/dev/sr0: UUID="2018-06-30-01-50-46-00" LABEL="CentOS-6.10-x86_64-LiveDVD" TYPE="iso9660" PTTYPE="dos" 
/dev/sr1: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/sda1: UUID="fe1acbe7-6d8d-40fc-8a00-eddd0a8e3d71" TYPE="xfs" 
/dev/sda2: UUID="cjk2sI-Mead-b9bl-YzNb-WwvH-pfuY-rseyFb" TYPE="LVM2_member" 
/dev/sdd1: UUID="405a397e-ee2e-4485-9d02-094dc5829869" TYPE="xfs" 
/dev/mapper/centos-root: UUID="51a36f5e-18de-4a8c-9eec-7d1596823069" TYPE="xfs" 
/dev/mapper/centos-swap: UUID="bc0a7571-47e0-49f2-bdd5-996cf2bf898f" TYPE="swap" 
/dev/mapper/centos-home: UUID="cb058a9d-cceb-4ae5-bcd7-8b9351f5473d" TYPE="xfs" 
/dev/sdb1: LABEL="MYDATA" UUID="0a4e63c7-711b-43ea-978b-91d9e16ed596" TYPE="ext4" 
/dev/sdc1: LABEL="MYDATA" UUID="1e7838ce-c10a-483f-94ca-5620041a3f35" TYPE="ext4" 

[root@JiangXiaoXiao ~]~~mkdir /mydata

[root@JiangXiaoXiao ~]~~mount |grep sdc1



将自动挂载

vim /etc/fstab
/dev/sdc1  /mydata  ext4   defaults,noexec,noatime  0 0
  1. 创建一个大小为1G的swap分区,并启用。

[root@JiangXiaoXiao ~]~~fdisk /dev/sdc
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 (2048-125829119, default 2048): +1G
Last sector, +sectors or +size{K,M,G} (2097152-20971519, default 20971519): +1G
Partition 2 of type Linux and of size 1 GiB is set
Command (m for help): p
Disk /dev/sdc: 64.4 GB, 64424509440 bytes, 125829120 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: 0x4083d30b
Device Boot      Start         End      Blocks   Id  System
/dev/sdc1        20971520    41943039    10485760   83  Linux
/dev/sdc2         2097152     4194303     1048576   83  Linux
Partition table entries are not in disk order
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/sdc: 64.4 GB, 64424509440 bytes, 125829120 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: 0x4083d30b
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1        20971520    41943039    10485760   83  Linux
/dev/sdc2         2097152     4194303     1048576   82  Linux swap / Solaris
Partition table entries are not in disk order
Command (m for help): w
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.

将自动挂载

vim /etc/fstab
/dev/sdc2    swap    swap    defaults        0  0 

例2

dd if=/dev/zero of=/swapfile bs=1G count=1
chmod 600 /swapfile
mkswap /swapfile

vim /etc/fstab
/swapfile         swap       swap    defaults      0 0
  1. 编写脚本计算/etc/passwd文件中第10个用户和第20个用户id号之和。
[root@JiangXiaoXiao /shflie]~~cat sumid.sh 
#!/bin/bash
#
#**************************************************
#Author:                        jiangxiaoxiao
#Date:                          2019-04-10
#QQ:                            14282819888
#FileName:                      sumid.sh
#URL:                           http://www.jiangniuer.com.cn
#
#**************************************************
ID1=`cat /etc/passwd |head -10|tail -1 |cut -d: -f3`
ID2=`cat /etc/passwd |head -20|tail -1 |cut -d: -f3`
let SUMID=ID1+ID2
echo $SUMID
unset ID1 ID2
[root@JiangXiaoXiao /shflie]~~chmod +x sumid.sh 
[root@JiangXiaoXiao /shflie]~~ls
sumid.sh
[root@JiangXiaoXiao /shflie]~~./sumid.sh 
1011
  1. . 将当前主机名保存至hostName变量中,主机名如果为空,或者为localhost.localdomain则将设置为www.magedu.com
[root@www /shflie]~~cat hostname.sh 
#!/bin/bash
#
#**************************************************
#Author:                        jiangxiaoxiao
#Date:                          2019-04-10
#QQ:                            1428281888
#FileName:                      hostname.sh
#URL:                           http://www.jiangniuer.com.cn
#
#**************************************************
hstName=$(hostname)
[ "$hostName" == "localhost.localdomain" -o -z "hostName" -o -n "hostname" ] && hostnamectl set-hostname www.magedu.com;echo 'hostName='$hostName || echo "nothing to be change"
[root@www /shflie]~~hostname
www.magedu.com
[root@www /shflie]~~

  1. 编写脚本,通过命令行参数传入一个用户名,判断id号是偶数还是奇数。
[root@jiangxiaoxiao_now1 ~]~~cat /shflie/e-o.sh 
#!/bin/bash
#
#**************************************************
#Author:                        jiangxiaoxiao
#Date:                          2019-04-10
#QQ:                            1428281888
#FileName:                      e-o.sh
#URL:                           http://www.jiangniuer.com.cn
#
#**************************************************
[ $[ $(id -u $1)%2 ] -eq 0 ] && echo $1 this ID is  Even numbers || echo $1 this ID is  Odd numbers
[root@jiangxiaoxiao_now1 ~]~~bash /shflie/e-o.sh 
this ID is Even numbers
[root@jiangxiaoxiao_now1 ~]~~bash /shflie/e-o.sh jiang
jiang this ID is Even numbers
[root@jiangxiaoxiao_now1 ~]~~bash /shflie/e-o.sh operator
operator this ID is Odd numbers
[root@jiangxiaoxiao_now1 ~]~~


例2

[root@jiangxiaoxiao_now1 /shflie]~~cat e-o_02.sh 
#!/bin/bash
#
#**************************************************
#Author:                        jiangxiaoxiao
#Date:                          2019-04-11
#QQ:                            1428281888
#FileName:                      e-o_02.sh
#URL:                           http://www.jiangniuer.com.cn
#
#**************************************************
if  [ $[ $(id -u $1)%2 ] -eq 0 ]
then
echo $1 this ID is  Even numbers
else
echo $1 this ID is  Odd numbers
fi
[root@jiangxiaoxiao_now1 /shflie]~~./e-o_02.sh 
ID is Even numbers
[root@jiangxiaoxiao_now1 /shflie]~~./e-o_02.sh jiang
jiang ID is Even numbers
[root@jiangxiaoxiao_now1 /shflie]~~./e-o_02.sh operator
operator ID is Odd numbers
[root@jiangxiaoxiao_now1 /shflie]~~

7. lvm基本应用以及扩展缩减实现。
|LV |
|VG–|VG–|
| PV | PV || PV |

LVM是逻辑盘管理、对磁盘分区进行管理一种机制、建立在硬盘和分区之上的一个逻辑层、提高磁盘管理的灵活性。
LVM优点
LVM将存储虚拟化,使用逻辑卷、不会受限于物理磁盘的大小,与硬件相关的存储设置被其隐藏、可以不用停止应用或卸载文件系统来调整卷大小或数据迁移
1、灵活的容量
2、可伸缩的存储池
3、在线的数据在分配
4、方便的设备命名
5、磁盘条块化
6镜像卷
7、卷快照

一、 创建物理卷 创建PV /dev/sdb1

[root@jiangxiaoxiao_now1 ~]~~pvcreate /dev/sdb1
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdb1.
  Physical volume "/dev/sdb1" successfully created.

查看pvs 是否创建成功

[root@jiangxiaoxiao_now1 ~]~~pvs
  PV         VG     Fmt  Attr PSize    PFree 
  /dev/sda2  centos lvm2 a--  <119.00g  4.00m
  /dev/sdb1         lvm2 ---    20.00g 20.00g```

显示物理卷 #pvs #pvscan #pvdisplay 显示当前系统中的物理卷 。
扫描块设备 #lvmdiskscan 可以看到那些设备成为了物理卷


[root@jiangxiaoxiao_now1 ~]~~pvdisplay /dev/sdb1
  "/dev/sdb1" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               ZL8LnA-Abz4-cufg-hcTw-kzTH-I9QQ-GuBAwO

#pvremove /dev/sdc 移除物理卷

二、创建卷组 创建VG
创建pv之后则是创建一个VG,可用vgcreate -s指明PE的大小,这里我指明PE为6M,vg名字为pvdata,创建完后用vgs和vgdisplay来查看vg的情况

[root@jiangxiaoxiao_now1 ~]~~vgcreate -s 6M pvdata /dev/sdb1
  Volume group "pvdata" successfully created
  创建6M 该卷组名pvdata 

激活卷组

[root@jiangxiaoxiao_now1 ~]~~vgchange -a y pvdata
  0 logical volume(s) in volume group "pvdata" now active

显示卷组#vgs #vgdisplay
扫描磁盘生成缓存文件 #vgscan

[root@jiangxiaoxiao_now1 ~]~~vgs
  VG     #PV #LV #SN Attr   VSize    VFree  
  centos   1   3   0 wz--n- <119.00g   4.00m
  pvdata   1   0   0 wz--n-  <20.00g <20.00g

详细

[root@jiangxiaoxiao_now1 ~]~~vgdisplay
  --- Volume group ---
  VG Name               pvdata
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <20.00 GiB
  PE Size               6.00 MiB
  Total PE              3413
  Alloc PE / Size       0 / 0   
  Free  PE / Size       3413 / <20.00 GiB
  VG UUID               FwQ93C-GrXH-c3G8-gEc4-iO3J-1rd7-k1hEYQ

三、创建逻辑卷
创建逻辑卷的命令为#lvcreate

[root@jiangxiaoxiao_now1 ~]~~lvcreate -L 1500 -n pvdata01 pvdata
  Logical volume "pvdata01" created.
  该命令就在卷组pvdata上创建名字为pvdata01,大小为1500M的逻辑卷

[root@jiangxiaoxiao_now1 ~]~~vgdisplay pvdata |grep "Total PE"
  Total PE              3413
lvcreate -l 3413 pvdata -n pvdata01

创建条块化的逻辑卷

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值