Linux的文件系统分区结构一般有2种,MBR和GPT
由于MBR仅仅为分区表保留了64字节的存储空间,而每个分区则占用16字节的空间,也就是只能分4个分区,而4个分区在实际情况下往往是不够用的,因此就有了扩展分区.
GPT磁盘分区结构解决了MBR只能分4个主分区的的缺点,理论上说,GPT磁盘分区结构对分区的数量好像是没有限制的。但某些操作系统可能会对此有限制。
GPT的分区结构相对于MBR要简单许多,并且分区表以及GPT头都有备份。
[root@centos7 ~]#parted /dev/sda
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type ‘help‘ to view a list of commands.
(parted)
创建GPT分区步骤
1、使用parted工具:parted /dev/sdb
2、输入:mklabel gpt 切换分区模式,print查看是否成功
3、输入:mkpart
[root@centos7 ~]#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 0xc5f2d556.
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): 1
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos7 ~]#
[root@centos7 ~]#fdisk -l
Disk /dev/sdb: 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: 0xc5f2d556
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20971519 10484736 83 Linux
[root@centos7 ~]#mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621184 blocks
131059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos7 ~]#
(1)block大小为2048,预留空间20%,卷标为MYDATA
mke2fs -b 2048 -t ext4 -m 20 -L MYDATA /dev/sdb1
(2)挂载至/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳
[root@centos7 ~]#mount -o noexec -o noatime /dev/sdb1 /mydata
[root@centos7 ~]#mount | grep sdb
/dev/sdb1 on /mydata type ext4 (rw,noexec,noatime,seclabel,data=ordered)
[root@centos7 ~]#
(3)可开机自动挂载
[root@centos7 ~]#vim /etc/fstab
LABEL=‘MYDATA‘ /mydata ext4 noexec,noatime 0 0
[root@centos7 ~]#fdisk /dev/sdb
Command (m for help): n
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 82
Changed type of partition ‘Linux‘ to ‘Linux swap / Solaris‘
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos7 ~]#
[root@centos7 ~]#mkswap /dev/sdb1
mkswap: /dev/sdb1: warning: wiping old ext4 signature.
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=11ef8a8c-bd90-4a92-9c2c-e97301b0c537
[root@centos7 ~]#cat /proc/meminfo | grep SwapTotal
SwapTotal: 4194300 kB
[root@centos7 ~]#swapon /dev/sdb1
[root@centos7 ~]#cat /proc/meminfo | grep SwapTotal
SwapTotal: 5242872 kB
[root@centos7 ~]#
#!/bin/bash
#
uid10=$(head -10 /etc/passwd | tail -1 | cut -d: -f3)
uid20=$(head -20 /etc/passwd | tail -1 | cut -d: -f3)
sumuid=$[$uid10+$uid20]
echo "User No.10 and No.20 uidsum="$sumuid
#!/bin/bash
#
hostname=$(hostname)
if [ -z "$hostname" -o "$hostname" == "localhost.localdomain" ]; then
echo "hostname is wrong. Change it."
hostname www.magedu.com
else
echo "hostname is right."
fi
#!/bin/bash
#
if [ $# -lt 1 ]; then
echo "At least one username"
exit 1
fi
judgeuid=$(id $1)
if [ $? != 0 ]; then
echo "No such user."
exit 2
fi
uid=$(id -u $1)
if [ $[$uid%2] -eq 0 ]; then
echo $1" uid is Even number."
else
echo $1" uid is Odd number."
fi
待补充
原文:https://blog.51cto.com/473997/2431159