```
[root@centos7 ~]#
[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 0x146853c4.
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): +9G ----分区大小
Partition 1 of type Linux and of size 9 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 ~]#
block大小为2048,预留空间20%,卷标 MYDATA
[root@centos7 ~]# mkfs -t 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
589824 inodes, 4718592 blocks
943718 blocks (20.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=273154048
288 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@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.
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): 2
First sector (18876416-20971519, default 18876416): +1G
Value out of range.
First sector (18876416-20971519, default 18876416):
Using default value 18876416
Last sector, +sectors or +size{K,M,G} (18876416-20971519, default 20971519): +900M
Partition 2 of type Linux and of size 900 MiB 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): 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.
[root@centos7 ~]# fdisk -l /dev/sdb
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: 0x146853c4
Device Boot Start End Blocks Id System
/dev/sdb1 2048 18876415 9437184 83 Linux
/dev/sdb2 18876416 20719615 921600 82 Linux swap / Solaris
[root@centos7 ~]# mkswap /dev/sdb2
/dev/sdb2: No such file or directory
[root@centos7 ~]# partprobe ----重读分区表,不重启的情况下重读分区表
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@centos7 ~]# mkswap /dev/sdb2
Setting up swapspace version 1, size = 921596 KiB
no label, UUID=972c95ea-8324-4b23-b8a5-34c43381c1d7
[root@centos7 ~]# swapon /dev/sdb2
[root@centos7 ~]# echo "UUID=972c95ea-8324-4b23-b8a5-34c43381c1d7 swap swap 0 0" >> /etc/fstab
#!/bin/bash
read -p "请输入用户名: " usename
id=$(id -u $usename)
echo "The user \"$usename\" id is $id"
id_yu=$[${id}%2]
if [ $id_yu -eq 0 ];then
echo "是个偶数"
else
echo "是个奇数"
fi