欢迎来到冘冗的博客

个性签名:世上只有想不通的人,没有走不通的路。

Linux磁盘分区

添加 10G 硬盘,为硬盘分三个分区:

查看添加磁盘

 1 [root@localhost ~]# fdisk -l
 2 
 3 Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
 4 Units = sectors of 1 * 512 = 512 bytes
 5 Sector size (logical/physical): 512 bytes / 512 bytes
 6 I/O size (minimum/optimal): 512 bytes / 512 bytes
 7 Disk label type: dos
 8 Disk identifier: 0x000b8c20
 9 
10    Device Boot      Start         End      Blocks   Id  System
11 /dev/sda1   *        2048     2099199     1048576   83  Linux
12 /dev/sda2         2099200   209715199   103808000   8e  Linux LVM
13 
14 Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
15 Units = sectors of 1 * 512 = 512 bytes
16 Sector size (logical/physical): 512 bytes / 512 bytes
17 I/O size (minimum/optimal): 512 bytes / 512 bytes
18 Disk label type: dos
19 Disk identifier: 0x98e3f29a
20 
21    Device Boot      Start         End      Blocks   Id  System
22 /dev/sdb1            2048     2099199     1048576   83  Linux
23 /dev/sdb2         2099200     6293503     2097152   83  Linux

创建分区

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

进入创建分区(主分区最多创建4个)其他创建步骤一样,使用p查看分区,w保存退出,如果创建swap交换磁盘创建磁盘后使用 t 选择磁盘修改类型swap是82

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-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1G
Partition 1 of type Linux and of size 1 GiB is set

创建挂载目录

[root@localhost ~]# mkdir /part-ext4
[root@localhost ~]# mkdir /part-xfs

格式化,如果格式化出错使用partprobe 命令重新写入表

[root@localhost ~]# mkfs.ext4 /dev/sdb1
[root@localhost ~]# mkfs.xfs /dev/sdb2
[root@localhost ~]# mkswap /dev/sdb3

挂载

临时挂载

[root@localhost ~]# mount /dev/sdb1 /part-ext4/
[root@localhost ~]# mount /dev/sdb2 /part-xfs/

永久挂载,并开机自启 使用vim 打开/etc/fstab添加

/dev/sdb1               /part-ext4              ext4    defaults        0 0
/dev/sdb2               /part-xfs               xfs     defaults        0 0

查看挂载情况 命令 lsblk 

├─sdb1 8:17 0 1G 0 part /part-ext4
├─sdb2 8:18 0 2G 0 part /part-xfs

查看swap

[root@localhost ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         667          86          13         218         150
Swap:          2047          14        2033

启动交换分区

[root@localhost ~]# swapon /dev/sdb3

再次查看 如果永久挂载写入/etc/fstab文件

[root@localhost ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         668          85          13         218         149
Swap:          4095          14        4081

查看挂载情况
sdb 8:16 0 10G 0 disk
├─sdb1 8:17 0 1G 0 part /part-ext4
├─sdb2 8:18 0 2G 0 part /part-xfs
└─sdb3 8:19 0 2G 0 part [SWAP]

创建扩展分区

[root@localhost ~]# fdisk /dev/sdb
Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e
Selected partition 4
First sector (10487808-20971519, default 10487808): 
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-20971519, default 20971519): 
Using default value 20971519
Partition 4 of type Extended and of size 5 GiB is set

创建逻辑分区

Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (10489856-20971519, default 10489856): 
Using default value 10489856
Last sector, +sectors or +size{K,M,G} (10489856-20971519, default 20971519): +2G
Partition 5 of type Linux and of size 2 GiB is set

查看分区使用 p查看分区

/dev/sdb1            2048     2099199     1048576   83  Linux
/dev/sdb2         2099200     6293503     2097152   83  Linux
/dev/sdb3         6293504    10487807     2097152   82  Linux swap / Solaris
/dev/sdb4        10487808    20971519     5241856    5  Extended
/dev/sdb5        10489856    14684159     2097152   83  Linux

格式化

[root@localhost ~]# mkfs.ext4 /dev/sdb5

修改配置文件vim /etc/auto.master

/autodir /etc/auto.misc --timeout=20

修改配置文件 vim /etc/auto.misc 

test            -fstype=ext4            :/dev/sdb5

启动autofs

[root@localhost ~]# systemctl start autofs

设置开机自启

systemctl enable autofs

查看挂载
sdb 8:16 0 10G 0 disk
├─sdb1 8:17 0 1G 0 part /part-ext4
├─sdb2 8:18 0 2G 0 part /part-xfs
├─sdb3 8:19 0 2G 0 part [SWAP]
├─sdb4 8:20 0 512B 0 part
└─sdb5 8:21 0 2G 0 part
sr0 11:0 1 4.4G 0 rom /mnt/cdrom
跳转后查看 cd /autodir/test
sdb 8:16 0 10G 0 disk
├─sdb1 8:17 0 1G 0 part /part-ext4
├─sdb2 8:18 0 2G 0 part /part-xfs
├─sdb3 8:19 0 2G 0 part [SWAP]
├─sdb4 8:20 0 512B 0 part
└─sdb5 8:21 0 2G 0 part /autodir/test

退出/autodir/test目录等待20s后自动取消挂载

 

posted @ 2020-10-29 17:49  冘冗  阅读(134)  评论(0编辑  收藏  举报