1、描述GPT是什么,应该怎么使用。
GUID磁盘分区表(GUID Partition Table,缩写:GPT)其含义为“全局唯一标识磁盘分区表”,是一个实体硬盘的分区表的结构布局的标准。
parted命令
[root@localhost ~]# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE 设定使用的分区类型, 如果要用MBR分区,输入msdos即可
mkpart PART-TYPE [FS-TYPE] START END 添加一个分区
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free
space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
resizepart NUMBER END resize partition NUMBER
rm NUMBER delete partition NUMBER
select DEVICE 选择你要操作的设备
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of
GNU Parted
(parted)
[root@localhost ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mktable gpt
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
(parted) mkpart
Partition name? []? part1
File system type? [ext2]? ext4
Start? 0
End? 25%
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 5369MB 5369MB part1
(parted) unit GB
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 0.00GB 5.37GB 5.37GB part1
(parted)
2、创建一个10G的分区,并格式化为ext4文件系统。要求:
(1)block大小为2048,预留空间20%,卷标为MYDATA。
(2)挂载至/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳。
(3)可开机自动挂载。
[root@localhost ~]# mke2fs -t ext4 -b 2048 -m 20 -L MYDATA /dev/sda3
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
[root@localhost ~]# cat /proc/partitions
major minor #blocks name
8 0 125829120 sda
8 1 524288 sda1
8 2 106961920 sda2
8 3 10485760 sda3
8 4 1 sda4
8 5 524288 sda5
8 6 131072 sda6
8 16 20971520 sdb
11 0 4481024 sr0
253 0 52428800 dm-0
253 1 2097152 dm-1
253 2 52428800 dm-2
[root@localhost ~]# mount -o noexec,noatime /dev/sda3 /mydata/
/dev/sda3 /mydata ext4 rw,seclabel,noexec,noatime,data=ordered 0 0
[root@localhost ~]# vim /etc/fstab
/dev/sda3 /mydata ext4 defaults 0 0
3、创建一个大小为1G的swap分区,并启用。
[root@localhost ~]# mkswap /dev/sdb1
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=386dac56-52ae-4fb9-87b8-a2598204fcca
[root@localhost ~]# free -m
total used free shared buff/cache available
Mem: 972 104 673 7 194 682
Swap: 2047 0 2047
[root@localhost ~]# swapon /dev/sdb1
[root@localhost ~]# free -m
total used free shared buff/cache available
Mem: 972 105 672 7 194 681
Swap: 3071 0 3071
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)
sum=$[$id1+$id2]
echo $sum
5、将当前主机名保存至hostName变量中,主机名如果为空,或者为localhost.localdomain则将设置为www.magedu.com
#!/bin/bash
hostName=$(hostname)
[ -z "$hostName " -o "$hostName" == "localhost.localdomain" -o "$hostName"=="localhost" ] && hostname www.magedu.com
6、编写脚本,通过命令行参数传入一个用户名,判断id好是偶数还是奇数。
#!/bin/bash
#
read -p "Input username: " username
user_id=$(grep "^$username\>" /etc/passwd | cut -d: -f3)
#echo $1, $user_id
let user_id%=2
#echo $user_id
if [ $user_id -eq 0 ]; then
echo "oushu"
else
echo "jishu"
fi
7、lvm基本引用以及扩展缩减实现。
pv管理工具:
pvs: 简要pv信息显示
pvdisplay: 显示pv的详细信息
pvcreate /dev/DEVICE: 创建pv
vg管理工具:
vgs
vgdisplay
vgcreate [ -s #[bBsSkKmMgGtTpPeE]] VolumeGroupName PhysicalDevicePath [ PhysicalDevicePath... ]
vdextend VolumeGroupName PhysicalDevicePath [ PhysicalDevicePath... ]
vgreduce VolumeGroupName PhysicalDevicePath [ PhysicalDevicePath... ]
先做pvremove
vgremove
lv管理工具:
lvs
lvdisplay
lvcreate -L #[mMgGtT] -n NAME VolumeGroup
lvremove /dev/VG_NAME/LV_NAME
扩展逻辑卷:
# lvextend -L [+]#[mMgGtT] /dev/VG_NAME_LVNAME
# resize2fs /dev/VG_NAME/LV_NAME
缩减逻辑卷:
# umount /dev/VG_NAME/LV_NAME
# e2fsck -f /dev/VG_NAME/LV_NAME
# resuze2fs /dev/VG_NAME/LV_NAME #[mMgGtT]
# lvreduce -L [-]#[mMgGtT] /dev/VG_NAME/LV_NAME
# mount
快照:snapshot
lvcreate -L #[mMgGtT] -p r -s -n snapshot_lv_name original_lv_name