1、描述GPT是什么,应该怎么使用?
GPT和MBR的区别:GPT和MBR是不同的分区表类型:
MBR的意思是“主引导记录”(Master Boot Record),它有自己的启动器,也就是启动代码,一旦启动代码被破坏,系统就没法启动,只有通过修复才能启动系统。但是容量方面有很大的限制。
MBR分区表的硬盘最多能划分4个主分区磁盘,并且MBR最大仅支持2TB的硬盘,但拥有最好的兼容性。共用512bytes组成,其中446字节为bootloader,64字节为分区表,最后2个字节为有效位标记55AA。
GPT分区表类型GUID磁盘分区表(GUID Partition Table,缩写:GPT)其含义为“全局唯一标识磁盘分区表”,是一个实体硬盘的[分区表的结构布局的标准。此分区表类型不受分区个数、硬盘大小的限制,最大支最大支持18EB 大容量(EB=1024 PB,PB=1024 TB),而且GPT是一种新的硬盘分区标准
GPT是一个正逐渐取代MBR的新标准,它由UEFI辅住而形成的,这样就有了UEFI用于取代老旧的BIOS,而GPT则取代老旧的MBR。磁盘驱动器容量可以大得多,大到操作系统和文件系统都没法支持。
Linux中使用parted工具,可以把分区分为gpt和MBR格式,下面是把磁盘分为GPT格式;
输入命令parted,进入parted命令模式:他有两种分区模式,一种是问答模式,还有一种是直接命令模式。下面先说问答模式:
他的帮助命令是help;
我们用select /dev/sd?,默认是你的第一块硬盘
默认的是MBR格式分区,我们用mklabel pgt命令改变分区格式
下面会提示我们继续吗?输入yes就行
可以使用print命令看我们的分区格式
下面用命令mkpart进行分区,他会提示你分区的命字,你自己选择分区的名字,还有文件系统的格式,以及磁盘开始的位置和磁盘结束的位置,默认单位是M,可以使用unit GB改变默认单位GB
注意的就是我上面分区的开始位置和结束位置为0和2000,他会有一个warning(错误提示),然后输入Cancel,就可以了,然后再刚才的那个操作就行了,然后我们在前面给他留1M的空余空间,目的是为了让数据块整齐,提高磁盘的运行效率
这样就分好了,可以使用print命令查看,不需要向MBR分区一样再输入w命令写入了,他是即可保存。
下面是用命令模式进行分区,这个就简单了,直接一行命令就行了,mkpart磁盘名字 开始位置 结束位置:mkpart test 1000 2000,就可以了
2、创建一个10G的分区,并格式化为ext4文件系统要求block大小为2048,预留管理空间20%,卷标为MYDATA。并挂载至/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳,并可自动开机挂载。
查看新添加硬盘信息
[root@localhost yum.repos.d]# fdisk -l
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005fc18
对新硬盘分区
[root@localhost ~]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005fc18
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-5221, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221): +10G
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005fc18
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
创建ext4文件系统
[root@localhost ~]# mke2fs -t ext4 -b 2048 -m 20 -L MYDATA /dev/sdb1
挂载至/mydata
# mount /dev/sdb1 /mydata/
配置fstab自动挂载
[root@localhost ~]# blkid /dev/sdb1
/dev/sdb1: LABEL="MYDATA" UUID="ecc49ba3-0b9f-4960-abca-ed832cbbf6e8" TYPE="ext4"
#vim /etc/fstab
UUID="ecc49ba3-0b9f-4960-abca-ed832cbbf6e8" /mydata ext4 defaults,noexec,noatime 0 0
# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/VolGroup-lv_home on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sdb1 on /mydata type ext4 (rw,noexec,noatime)
3、创建一个大小1G的swap分区,并启动
分区并调整分区为swap标记
Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 82
Changed system type of partition 5 to 82 (Linux swap / Solaris)
格式化
[root@localhost ~]# mkswap /dev/sdb5
Setting up swapspace version 1, size = 1060252 KiB
no label, UUID=9ea01170-f461-4538-b11c-0d2ed34bf987
[root@localhost ~]# blkid /dev/sdb5
/dev/sdb5: UUID="9ea01170-f461-4538-b11c-0d2ed34bf987" TYPE="swap"
启用
[root@localhost ~]# swapon /dev/sdb5
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 482 258 224 0 12 138
-/+ buffers/cache: 107 375
Swap: 2027 1 2026
4、编写脚本计算/etc/passwd文件中第10个用户和第20个用户id之和
5、将当前主机名称保存至hostName变量中。主机名如果为空,或者为localhost.localdomain,则将其设置为 wwwmageducom
hostName=$(hostname)
[ -z "$hostName" -o "$hostName" == "localhost.localdomain" -o "$hostName" == "localhost" ] && hostname www.magedu.com
6、编写脚本,通过命令行参数传入一个用户名,判断id号是奇数还是偶数
7、lvm基本应用以及扩展缩减实现
LVM: Logical Volume Manager 逻辑卷管理
pv管理工具
pvs:简要pv信息显示
pvdisplay:显示pv的详细信息
pvcreate /dev/DEVICE: 创建pv
vg管理工具:
vgs:简要vg信息显示
vgdisplay:显示vg的详细信息
vgcreate [-s #[kKmMgGtTpPeE]] VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
vgextend VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
vgreduce VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
移除之间先做pvmove保证数据转移至其他vg再使用vgremove移除
lv管理工具:
lvs:简要lv信息显示
lvdisplay:显示lv的详细信息
lvcreate -L #[mMgGtT] -n NAME VolumeGroup 创建
lvremove /dev/VG_NAME/LV_NAME 移除
扩展逻辑卷:
lvextend -L [+]#[mMgGtT] /dev/VG_NAME/LV_NAME
resize2fs /dev/VG_NAME/LV_NAME
先扩展物理边界,再扩展逻辑边界
[root@localhost mydata]# lvextend -L 2G /dev/mapper/myvg-mydate
Size of logical volume myvg/mydate changed from 1.00 GiB (128 extents) to 2.00 GiB (256 extents).
Logical volume mydate successfully resized
[root@localhost mydata]# res
reset resize2fs resizecons restart restorecon restorecond
[root@localhost mydata]# resize2fs /dev/mapper/myvg-mydate
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/myvg-mydate is mounted on /mydata; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/mapper/myvg-mydate to 524288 (4k) blocks.
The filesystem on /dev/mapper/myvg-mydate is now 524288 blocks long.
缩减逻辑卷:
umount /dev/VG_NAME/LV_NAME
e2fsck -f /dev/VG_NAME/LV_NAME
resize2fs /dev/VG_NAME/LV_NAME #[mMgGtT]
lvreduce -L [-]#[mMgGtT] /dev/VG_NAME/LV_NAME
mount
先缩减逻辑边界,在缩减物理边界
[root@localhost ~]# e2fsck -f /dev/mapper/myvg-mydate
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
mydata: 12/131072 files (0.0% non-contiguous), 16816/524288 blocks
[root@localhost ~]# resize2fs /dev/mapper/myvg-mydate 1G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/myvg-mydate to 262144 (4k) blocks.
The filesystem on /dev/mapper/myvg-mydate is now 262144 blocks long.
[root@localhost ~]# lvreduce -L 1G /dev/mapper/myvg-mydate
WARNING: Reducing active logical volume to 1.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mydate? [y/n]: y
Size of logical volume myvg/mydate changed from 2.00 GiB (256 extents) to 1.00 GiB (128 extents).
Logical volume mydate successfully resized
[root@localhost ~]# !mount
mount /dev/mapper/myvg-mydate /mydata/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 1.4G 46G 4% /
tmpfs 242M 0 242M 0% /dev/shm
/dev/sda1 477M 33M 419M 8% /boot
/dev/mapper/VolGroup-lv_home
68G 52M 64G 1% /home
/dev/mapper/myvg-mydate
976M 1.3M 924M 1% /mydata
[root@localhost ~]# ls /mydata/
epel-release-6-8.noarch.rpm lost+found
快照:snapshot
lvcreate -L #[mMgGtT] -p r -s -n snapshot_lv_name original_lv_name