linux磁盘管理

知识脑图

https://note.youdao.com/s/Zraw9hSl

题目

1、基本存储配置
1) 添加一块10G大小的磁盘,将该磁盘分为两个主分区,大小为1G、2G。将剩余的空间全部划分为扩展分
区。划分一个逻辑分区,大小为3G。(主分区文件系统类型为ext4,逻辑分区文件系统类型为xfs)
2) 将三个分区分别挂载到/dir1、/dir2、/dir3。
3) 在第一个主分区中创建一个文件为file1,内容为this is partition1。在第二个分区中创建一个文
件为file2,内容为this is partition2。在第三个分区中创建一个文件为file3,内容为this is
partition3。

答案

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

[root@localhost ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0   50G  0 disk 
├─sda1          8:1    0  600M  0 part /boot
└─sda2          8:2    0   38G  0 part 
  ├─rhel-root 253:0    0   30G  0 lvm  /
  ├─rhel-swap 253:1    0    3G  0 lvm  [SWAP]
  └─rhel-home 253:2    0    5G  0 lvm  /home
sdb             8:16   0   10G  0 disk 
sr0            11:0    1 10.2G  0 rom  
[root@localhost ~]# fd
fdformat  fdisk     
[root@localhost ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x109ae473.

Command (m for help): n
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): 3
First sector (6293504-20971519, default 6293504): 
Last sector, +sectors or +size{K,M,G,T,P} (6293504-20971519, default 20971519): +7G
Value out of range.
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.

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.
Command (m for help): p
Disk /dev/sdb: 10 GiB, 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
Disklabel type: dos
Disk identifier: 0x109ae473

Device     Boot   Start      End  Sectors Size Id Type
/dev/sdb1          2048  2099199  2097152   1G 83 Linux
/dev/sdb2       2099200  6293503  4194304   2G 83 Linux
/dev/sdb3       6293504 20971519 14678016   7G  5 Extended
/dev/sdb5       6295552 12587007  6291456   3G 83 Linux

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@localhost ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: f244ae4c-6f80-4d9d-b3ab-6582dafb9ca7
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/sdb2
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: b850b145-73f9-4dc2-bab7-891cf31db966
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 ~]# blkid
/dev/sda1: UUID="36ba8315-64a9-433f-88ca-dbb1d995b7f5" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="32361dfd-01"
/dev/sda2: UUID="Gdz4Gv-HrX2-weAR-XfJk-fFa9-tCqJ-oc8OBH" TYPE="LVM2_member" PARTUUID="32361dfd-02"
/dev/sdb1: UUID="f244ae4c-6f80-4d9d-b3ab-6582dafb9ca7" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="109ae473-01"
/dev/sdb2: UUID="b850b145-73f9-4dc2-bab7-891cf31db966" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="109ae473-02"
/dev/sdb5: UUID="323e38bd-9e59-4274-837e-f21d5a9cfe63" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="109ae473-05"
/dev/sr0: BLOCK_SIZE="2048" UUID="2021-10-13-03-57-25-00" LABEL="RHEL-8-5-0-BaseOS-x86_64" TYPE="iso9660" PTUUID="4d694e6c" PTTYPE="dos"
/dev/mapper/rhel-root: UUID="6708cd69-63f5-4717-837f-3213b6703943" BLOCK_SIZE="512" TYPE="xfs"
/dev/mapper/rhel-swap: UUID="f0cc1221-a76d-4d45-90de-76f9b88eb779" TYPE="swap"
/dev/mapper/rhel-home: UUID="7526f9a5-37fa-43f2-a44a-0680c6f6602b" BLOCK_SIZE="512" TYPE="xfs"

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

[root@localhost /]# mkdir /dir1
[root@localhost /]# mkdir /dir2
[root@localhost /]# mkdir /dir3
[root@localhost /]# mount /dev/sdb1 /dir1
[root@localhost /]# mount /dev/sdb2 /dir2
[root@localhost /]# mount /dev/sdb3 /dir3
[root@localhost /]# mount /dev/sdb5 /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 /]# ll /dir1 /dir2 /dir3
/dir1:
total 24
-rw-r--r--. 1 root root    19 Nov  4 10:43 file1
drwx------. 2 root root 16384 Nov  4 09:18 lost+found

/dir2:
total 20
-rw-r--r--. 1 root root    19 Nov  4 10:44 file2
drwx------. 2 root root 16384 Nov  4 09:18 lost+found

/dir3:
total 4
-rw-r--r--. 1 root root 19 Nov  4 10:45 file3

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值