第四周

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

2、创建一个10G的分区,并格式化为ext4文件系统。

要求:
(1)block大小为2048,预留空间20%,卷标为MYDATA
(2)挂载至/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳
(3)可开机自动挂载

创建10G分区

~]# fdisk /dev/sdb
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 0x67dc56b9.

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x67dc56b9

   Device Boot      Start         End      Blocks   Id  System

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-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G
Partition 1 of type Linux and of size 10 GiB is set


Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x67dc56b9

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux

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

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

~]# partx -a /dev/sdb 
partx: /dev/sdb: error adding partition 1
~]# partx -a /dev/sdb 
partx: /dev/sdb: error adding partition 1

~]# cat /proc/partitions 
major minor  #blocks  name

   8        0  104857600 sda
   8        1    1048576 sda1
   8        2   19921920 sda2
   8       16   20971520 sdb
   8       17   10485760 sdb1
  11        0    4481024 sr0
 253        0   17821696 dm-0
 253        1    2097152 dm-1

创建文件系统

~]# mkfs.ext4 -b 2048 -m 20 -L MYDATA /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=MYDATA
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 5242880 blocks
1048576 blocks (20.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=273678336
320 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
	16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 
	2048000, 3981312

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

挂载文件系统

~]# mkdir /mydata
~]# mount -o noexec,noatime,nodiratime /dev/sdb1 /mydata/
~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=919452k,nr_inodes=229863,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
...
/dev/sdb1 on /mydata type ext4 (rw,noexec,noatime,nodiratime,seclabel,data=ordered)

开机自动挂载

~]# vim /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Wed Jan  2 06:07:10 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=3ed0b6fe-ac2e-4d11-9245-2b6955c3bc36 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
UUID=3f521d3b-9bd1-4a92-b2fd-cf1553a7161a	/mydata	ext4	defaults,noexec,noatime,nodiratime	0 0	//新增挂载

~]# mount -a

~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=919452k,nr_inodes=229863,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
...
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sdb1 on /mydata type ext4 (rw,noexec,noatime,nodiratime,seclabel,data=ordered)

3、创建一个大小为1G的swap分区,并启用。

~]# fdisk /dev/sdb
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 (20973568-41943039, default 20973568): 
Using default value 20973568
Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G
Partition 2 of type Linux and of size 1 GiB is set

Command (m for help): t
Partition number (1,2, default 2): 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/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x67dc56b9

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux
/dev/sdb2        20973568    23070719     1048576   82  Linux swap / Solaris

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.

 
~]# partx -a /dev/sdb
partx: /dev/sdb: error adding partition 1
~]# partx -a /dev/sdb
partx: /dev/sdb: error adding partitions 1-2

~]# cat /proc/partitions 
major minor  #blocks  name

  11        0    4481024 sr0
   8        0  104857600 sda
   8        1    1048576 sda1
   8        2   19921920 sda2
   8       16   20971520 sdb
   8       17   10485760 sdb1
   8       18    1048576 sdb2
 253        0   17821696 dm-0
 253        1    2097152 dm-1

~]# mkswap /dev/sdb2
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=3ac8d8e0-f938-43e9-b236-d95a2274bd28
~]# swapon /dev/sdb2

~]# cat /proc/swaps 
Filename				Type		Size	Used	Priority
/dev/dm-1                               partition	2097148	0	-2
/dev/sdb2                               partition	1048572	0	-3

4、编写脚本计算/etc/passwd文件中第10个用户和第20个用户的id号之和

#!/bin/bash
id1=$(head -10  /etc/passwd | tail -1  | cut  -d:  -f3)
id2=$(head -20   /etc/passwd | tail -1  | cut  -d:  -f3)
idsum=$id1+$id2
echo "The sum of the 10th and 20th userid is:$idsum"

5、将当前主机名保存至hostName变量中,主机名如果为空,或者为localhost.localdomain则将其设置为www.magedu.com

hostName=$(hostname)
[ -z "$hostName" -o "$hostName" == "localhost.localdomain" -o "$hostName" == "localhost" ] && hostname www.magedu.com 		

6、编写脚本,通过命令行参数传入一个用户名,判断id号是偶数还是奇数

#!/bin/bash
#
[ $# -lt 1 ] && echo "At least on user name." && exit 1

! id $1 &> /dev/null && echo "No such user." && exit 2

userid=$(id -u $1)

if [ $[$userid%2] -eq 0 ]; then
    echo "even number"
else
    echo "odd number"
fi

7、LVM基本应用以及扩展缩减

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值