RHCSA第二次小作业(关于磁盘)

例1:新添加一块硬盘,大小为5g,给这块硬盘分一个mbr格式的主分区(大小为3g),给此主分区创建ext2的文件系统,挂载到/guazai1目录,并写入文件内容为 "this is fist disk" 文件名为1.txt的文件。

[root@UpKer ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0            11:0    1  9.8G  0 rom  /run/media/redhat/RHEL-9-3-0-BaseOS-x86_64
nvme0n1       259:0    0   20G  0 disk 
├─nvme0n1p1   259:1    0  600M  0 part /boot/efi
├─nvme0n1p2   259:2    0    1G  0 part /boot
└─nvme0n1p3   259:3    0 18.4G  0 part 
  ├─rhel-root 253:0    0 16.4G  0 lvm  /
  └─rhel-swap 253:1    0    2G  0 lvm  [SWAP]
nvme0n2       259:4    0    5G  0 disk 
[root@UpKer ~]# fdisk -l
Disk /dev/nvme0n2: 5 GiB, 5368709120 bytes, 10485760 sectors
Disk model: VMware Virtual NVMe Disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@UpKer ~]# fdisk /dev/nvme0n2

Welcome to fdisk (util-linux 2.37.4).
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 0xc1c80604.

Command (m for help): o
Created a new DOS disklabel with disk identifier 0x205e8b92.

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): 
First sector (2048-10485759, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-10485759, default 10485759): +3G

Created a new partition 1 of type 'Linux' and of size 3 GiB.

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

[root@UpKer ~]# mkfs.ext2 /dev/nvme0n2p1
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 786432 4k blocks and 196608 inodes
Filesystem UUID: 64d94593-f22e-40c0-ad5f-45aac8bdc165
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done 

[root@UpKer ~]# mkdir /guazai1
[root@UpKer ~]# mount /dev/nvme0n2p1 /guazai1
[root@UpKer ~]# echo "this is first disk" | tee /guazai1/1.txt
this is first disk
[root@UpKer ~]# cat /guazai1/1.txt
this is first disk
[root@UpKer ~]# umount /guazai1

例2:新添加一块硬盘,大小为10g,给这块硬盘分一个mbr格式的主分区(大小为4g),分一个扩展分区为(大小为5g),一个逻辑分区(大小为1g),给此主分区创建ext3的文件系统,挂载到/guazai2目录,并写入文件内容为 "The first primary partition on the second disk" 文件名为2.txt的文件,给此逻辑分区创建ext4的文件系统,挂载到/guazai3目录,并写入文件内容为 "Logical partition on the second disk " 文件名为3.txt的文件。

[root@UpKer ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda             8:0    0   10G  0 disk 

[root@UpKer ~]# fdisk -l

Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@UpKer ~]# fdisk /sev/sda

Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

fdisk: cannot open /sev/sda: No such file or directory
[root@UpKer ~]# o
bash: o: command not found...
[root@UpKer ~]# fdisk /dev/sda

Welcome to fdisk (util-linux 2.37.4).
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 0x54c98c06.

Command (m for help): o
Created a new DOS disklabel with disk identifier 0x78141994.

Command (m for help): o
Created a new DOS disklabel with disk identifier 0x816de9d3.

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): +5G

Created a new partition 1 of type 'Linux' and of size 5 GiB.

Command (m for help): N
N: unknown command

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): 
First sector (10487808-20971519, default 10487808): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (10487808-20971519, default 20971519): 

Created a new partition 2 of type 'Linux' and of size 5 GiB.

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): p
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual S
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: 0x816de9d3

Device     Boot Start      End  Sectors Size Id Type
/dev/sda1        2048 10487807 10485760   5G 83 Linux

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): p
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual S
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: 0x816de9d3

Command (m for help): o
Created a new DOS disklabel with disk identifier 0x19c8d886.

Command (m for help): p
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual S
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: 0x19c8d886

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): +4G

Created a new partition 1 of type 'Linux' and of size 4 GiB.

Command (m for help): p
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual S
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: 0x19c8d886

Device     Boot Start     End Sectors Size Id Type
/dev/sda1        2048 8390655 8388608   4G 83 Linux

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2): 2
First sector (8390656-20971519, default 8390656): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (8390656-20971519, default 20971519): +4G

Created a new partition 2 of type 'Extended' and of size 4 GiB.

Command (m for help): p
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual S
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: 0x19c8d886

Device     Boot   Start      End Sectors Size Id Type
/dev/sda1          2048  8390655 8388608   4G 83 Linux
/dev/sda2       8390656 16779263 8388608   4G  5 Extended

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2): 2
First sector (8390656-20971519, default 8390656): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (8390656-20971519, default 20971519): +5G

Created a new partition 2 of type 'Extended' and of size 5 GiB.

Command (m for help): p
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual S
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: 0x19c8d886

Device     Boot   Start      End  Sectors Size Id Type
/dev/sda1          2048  8390655  8388608   4G 83 Linux
/dev/sda2       8390656 18876415 10485760   5G  5 Extended

Command (m for help): n
Partition type
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l

Adding logical partition 5
First sector (8392704-18876415, default 8392704): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (8392704-18876415, default 18876415): +1G

Created a new partition 5 of type 'Linux' and of size 1 GiB.

Command (m for help): p
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual S
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: 0x19c8d886

Device     Boot   Start      End  Sectors Size Id Type
/dev/sda1          2048  8390655  8388608   4G 83 Linux
/dev/sda2       8390656 18876415 10485760   5G  5 Extended
/dev/sda5       8392704 10489855  2097152   1G 83 Linux

Command (m for help): mkfs.ext3 /dev/sda1

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


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

[root@UpKer ~]# mkfs.ext3 /dev/sda1
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 1048576 4k blocks and 262144 inodes
Filesystem UUID: ab2880e3-8933-4427-94ef-1c36849f2ef1
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

[root@UpKer ~]# mkfs.ext4 /dev/sda5
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: 2317f42a-c0ce-41e8-b6e5-85bb4320f4ff
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@UpKer ~]# mount /dev/sda1 /guazai2
[root@UpKer ~]# echo "The first primary partition on the second disK" | tee /guazai2/2.txt
The first primary partition on the second disK
[root@UpKer ~]# mount /dev/sda5 /guazai3
[root@UpKer ~]# echo "Logical partition on the second disk" | tee /guazai3/3.txt
Logical partition on the second disk
[root@UpKer ~]# cat /guazai2/2.txt
The first primary partition on the second disK
[root@UpKer ~]# cat /guazai3/3.txt
Logical partition on the second disk
[root@UpKer ~]# umount /guazai2
[root@UpKer ~]# umount /guazai3

例3:新添加一块硬盘,大小为15g,给这块硬盘分一个gpt格式的主分区(大小为6g),给此主分区创建xfs的文件系统,挂载到/guazai4目录,并写入文件内容为 "This is a partition formatted in GPT (GUID Partition Table) format." 文件名为4.txt 的文件

[root@UpKer ~]# 
[root@UpKer ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda             8:0    0   15G  0 disk 

[root@UpKer ~]# fdisk -l
Disk /dev/nvme0n1: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual NVMe Disk
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: gpt
Disk identifier: DBE29FFF-1385-432C-9E0B-A4A673BB7EE6

Device           Start      End  Sectors  Size Type
/dev/nvme0n1p1    2048  1230847  1228800  600M EFI System
/dev/nvme0n1p2 1230848  3327999  2097152    1G Linux filesystem
/dev/nvme0n1p3 3328000 41940991 38612992 18.4G Linux LVM


Disk /dev/sda: 15 GiB, 16106127360 bytes, 31457280 sectors
Disk model: VMware Virtual I
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 /dev/mapper/rhel-root: 16.41 GiB, 17620271104 bytes, 34414592 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 /dev/mapper/rhel-swap: 2 GiB, 2147483648 bytes, 4194304 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
[root@UpKer ~]# 
[root@UpKer ~]# gdisk /dev/sad
GPT fdisk (gdisk) version 1.0.7

Problem opening /dev/sad for reading! Error is 2.
The specified file does not exist!
[root@UpKer ~]# o
bash: o: command not found...
[root@UpKer ~]# 
[root@UpKer ~]# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.7

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries in memory.

Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y

Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-31457246, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-31457246, default = 31457246) or {+-}size{KMGTP}: 
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): d^Hp
Using 1

Command (? for help): p
Disk /dev/sda: 31457280 sectors, 15.0 GiB
Model: VMware Virtual I
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 4E91E6E0-9185-46FC-8E6F-F103819ACD51
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 31457246
Partitions will be aligned on 2048-sector boundaries
Total free space is 31457213 sectors (15.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name

Command (? for help): d
No partitions

Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-31457246, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-31457246, default = 31457246) or {+-}size{KMGTP}: +6GB
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): p
Disk /dev/sda: 31457280 sectors, 15.0 GiB
Model: VMware Virtual I
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 4E91E6E0-9185-46FC-8E6F-F103819ACD51
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 31457246
Partitions will be aligned on 2048-sector boundaries
Total free space is 18874301 sectors (9.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        12584959   6.0 GiB     8300  Linux filesystem

Command (? for help): t
Using 1
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 1\^H
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): t
Using 1
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): t
Using 1
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 1
Exact type match not found for type code 0001; assigning type code for
'Linux filesystem'
Changed type of partition to 'Linux filesystem'

Command (? for help): 8300
b	back up GPT data to a file
c	change a partition's name
d	delete a partition
i	show detailed information on a partition
l	list known partition types
n	add a new partition
o	create a new empty GUID partition table (GPT)
p	print the partition table
q	quit without saving changes
r	recovery and transformation options (experts only)
s	sort partitions
t	change a partition's type code
v	verify disk
w	write table to disk and exit
x	extra functionality (experts only)
?	print this menu

Command (? for help): t
Using 1
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 8300
Changed type of partition to 'Linux filesystem'

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
The operation has completed successfully.
[root@UpKer ~]# mkfs.xfs /dev/sda
mkfs.xfs: /dev/sda appears to contain a partition table (gpt).
mkfs.xfs: Use the -f option to force overwrite.
[root@UpKer ~]# mkdir /guazai4
[root@UpKer ~]# mount /dev/sda /guazai4
mount: /guazai4: wrong fs type, bad option, bad superblock on /dev/sda, missing codepage or helper program, or other error.
[root@UpKer ~]# echo "This is a partition formatted in GPT (GUID Partition Table) format." | tee /guazai4/4.txt
This is a partition formatted in GPT (GUID Partition Table) format.
[root@UpKer ~]# cat /guazai4/4.txt
This is a partition formatted in GPT (GUID Partition Table) format.
[root@UpKer ~]# umount /guazai4
umount: /guazai4: not mounted.
[root@UpKer ~]# 

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值