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


(1)block大小为2048,预留空间20%,卷标为MYDATA。


    在Linux中添加一块20G的新硬盘/dev/sdb并重启。


    使用fdisk创建10G的分区。


        [root@centos ~]# fdisk /dev/sdb

        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): w

        The partition table has been altered!


    使用mke2fs将sdb1格式化为ext4文件系统,block大小为2048,预留20%空间,卷标为MYDATA。


        [root@centos ~]# mke2fs -t ext4 -b 2048 -m 20 -L MYDATA -q /dev/sdb1


(2)挂载至/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳。


    [root@centos ~]# mkdir /mydata

    [root@centos ~]# mount -o noexec,noatime /dev/sdb1 /mydata


(3)可开机自动挂载。


    [root@centos ~]# echo "/dev/sdb1 /mydata ext4 noexec,noatime 0 0" >> /etc/fstab


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


创建1G的分区,将分区ID设为swap。


    [root@centos ~]# fdisk /dev/sdb

    Command (m for help): n

    Select (default p): p

    Partition number (2-4, default 2): 

    First sector (20973568-41943039, default 20973568): 

    Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G

    Command (m for help): t

    Partition number (1,2, default 2): 2

    Hex code (type L to list all codes): 82

    Command (m for help): w


重读分区表,格式化swap分区并启用。


    [root@centos ~]# partx -a /dev/sdb

    partx: /dev/sdb: error adding partition 1

    [root@centos ~]# partx -a /dev/sdb

    partx: /dev/sdb: error adding partitions 1-2

    [root@centos ~]# mkswap /dev/sdb2

    Setting up swapspace version 1, size = 1048572 KiB

    no label, UUID=3f4be657-d865-4f55-a1eb-279b635db303

    [root@centos ~]# swapon /dev/sdb2