Linux的磁盘管理

1) 添加一块10G大小的磁盘,将该磁盘分为两个主分区,大小为1G、2G。将剩余的空间全部划分为扩展分
区。划分一个逻辑分区,大小为3G。(主分区文件系统类型为ext4,逻辑分区文件系统类型为xfs)

#使用fdisk命令工具,默认情况下将磁盘划分为mbr格式
[root@localhost ~]# fdisk /dev/sda
Command (m for help): n							#输入n创建新分区。输入m可查看帮助文档
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): +1G
 
Created a new partition 1 of type 'Linux' and of size 1 GiB.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2099200-20971519, default 2099200):
Last sector, +sectors or +size{K,M,G,T,P} (2099200-20971519, default 20971519): +2G
 
Created a new partition 2 of type 'Linux' and of size 2 GiB.

#从这里开始,创建扩展分区
Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (3,4, default 3):
First sector (6293504-20971519, default 6293504):
Last sector, +sectors or +size{K,M,G,T,P} (6293504-20971519, default 20971519):
 
Created a new partition 3 of type 'Extended' and of size 7 GiB.
 
#划分大小为3G的逻辑分区
Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (6295552-20971519, default 6295552):
Last sector, +sectors or +size{K,M,G,T,P} (6295552-20971519, default 20971519): +3G
 
Created a new partition 5 of type 'Linux' and of size 3 GiB.
#格式化,根据题目可知主分区系统文件为ext4,逻辑文件类型为xfs
[root@localhost ~]# mkfs.ext4 /dev/sda1
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: d0f614a7-6210-419d-b995-c5315afb126a
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376
 
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

[root@localhost ~]# mkfs.ext4 /dev/sda2
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: ec1719b8-1bdf-4b7d-8a59-b31c822556e4
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

[root@localhost ~]# mkfs.xfs /dev/sda5
meta-data=/dev/sda5              isize=512    agcount=4, agsize=196608 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=786432, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

2) 将三个分区分别挂载到/dir1、/dir2、/dir3。

#创建挂载点目录
[root@localhost ~]# mkdir /dir{1,2,3}
 
#挂载
[root@localhost ~]# mount /dev/sda1 /dir1
[root@localhost ~]# mount /dev/sda2 /dir2
[root@localhost ~]# mount /dev/sda5 /dir3
 

3) 在第一个主分区中创建一个文件为file1,内容为this is partition1。在第二个分区中创建一个文件为file2,内容为this is partition2。在第三个分区中创建一个文件为file3,内容为this is partition3。

[root@localhost ~]# echo "this is partition1" >> /dir1/file1
[root@localhost ~]# echo "this is partition2" >> /dir2/file2
[root@localhost ~]# echo "this is partition3" >> /dir3/file3
 
[root@localhost ~]# cat /dir1/file1 
this is partition1

[root@localhost ~]# cat /dir2/file2 
this is partition2

[root@localhost ~]# cat /dir3/file3
this is partition3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值