linux添加磁盘

1、添加三块硬盘: 第一块硬盘,虚拟磁盘类型选择SCSI。大小选择5G。按mbr格式分区。分两个主分区,大小分别为2G和3G。第一个主分区创建ext2类型的文件系统。第一个主分区挂载到/guazai1目录,并在其中存入1.txt的文件。其文件内容是this is 1。

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): +2g
 
Created a new partition 1 of type 'Linux' and of size 2 GiB.
 
Command (m for help): p
Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 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: 0xd3df5b52
 
Device     Boot Start     End Sectors Size Id Type
/dev/sdb1        2048 4196351 4194304   2G 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): p
Partition number (2-4, default 2): 
First sector (4196352-10485759, default 4196352): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (4196352-10485759, default 10485759): +2g 
Created a new partition 2 of type 'Linux' and of size 2 GiB.
 
Command (m for help): p
Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 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: 0xd3df5b52
 
Device     Boot   Start     End Sectors Size Id Type
/dev/sdb1          2048 4196351 4194304   2G 83 Linux
/dev/sdb2       4196352 8390655 4194304   2G 83 Linux
 
Command (m for help): wq
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
 
[root@localhost ~]# lsblk -p
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
/dev/sda                    8:0    0   10G  0 disk 
/dev/sdb                    8:16   0    5G  0 disk 
├─/dev/sdb1                 8:17   0    2G  0 part 
└─/dev/sdb2                 8:18   0    2G  0 part 
/dev/nvme0n1              259:0    0   20G  0 disk 
├─/dev/nvme0n1p1          259:1    0  600M  0 part /boot/efi
├─/dev/nvme0n1p2          259:2    0    1G  0 part /boot
└─/dev/nvme0n1p3          259:3    0 18.4G  0 part 
  ├─/dev/mapper/rhel-root 253:0    0 16.4G  0 lvm  /
  └─/dev/mapper/rhel-swap 253:1    0    2G  0 lvm  [SWAP]
/dev/nvme0n2              259:4    0   15G  0 disk 
[root@localhost ~]# mkfs.ext2 /dev/sdb1
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: c65551c6-40c0-4857-a4ba-b19d4ce5995d
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@localhost ~]# blkid /dev/sdb1
/dev/sdb1: UUID="c65551c6-40c0-4857-a4ba-b19d4ce5995d" TYPE="ext2" PARTUUID="d3df5b52-01"
[root@localhost ~]# mkfs.ext3 /dev/sdb2
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: 6b6f1178-1631-47ad-b046-375d3b3a7018
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/sdb1
/dev/sdb1: UUID="c65551c6-40c0-4857-a4ba-b19d4ce5995d" TYPE="ext2" PARTUUID="d3df5b52-01"
[root@localhost ~]# blkid /dev/sdb2
/dev/sdb2: UUID="6b6f1178-1631-47ad-b046-375d3b3a7018" SEC_TYPE="ext2" TYPE="ext3" PARTUUID="d3df5b52-02"
[root@localhost ~]# mkfs.ext3 /dev/sdb2
mke2fs 1.46.5 (30-Dec-2021)
/dev/sdb2 contains a ext3 file system
	created on Sun Oct 20 14:31:43 2024
Proceed anyway? (y,N) mkdir /guazai1
 
[root@localhost ~]# mount /dev/sdb1 /guazai1
[root@localhost ~]# echo this is 1 > /guazai1/1.txt
[root@localhost ~]# mkdir /guazai2
mkdir: cannot create directory ‘/guazai2’: File exists
[root@localhost ~]# rm -rf /guazai2
[root@localhost ~]# mkdir /guazai2
[root@localhost ~]# mount /dev/sdb2 /guazai2
[root@localhost ~]# echo this is 2 > /guazai2/2.txt
[root@localhost ~]# 

第二个主分区创建ext3的类型的文件系统。第二个主分区挂载到/guazai2目录,并在其中存入2.txt的文件。其文件内容是this is 2。 第二块硬盘,虚拟磁盘类型选择STAT。大小选择10G。按mbr格式分区。分一个主分区,大小为1G 。分一个扩展分区。大小为6G。分一个逻辑分区,大小为4G。将主分区创建为ext4类型的文件系统。挂载到/guazai3目录。在其中存入3.txt的文件,其文件内容是this is 3。 将逻辑分区创建xfs类型的文件系统。挂载到/guazai4目录。在其中存入4.txt的文件,其文件内容是this is 4。

[root@localhost ~]# 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 0x094ec07d.
 
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: 0x094ec07d
 
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-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): 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: 0x094ec07d
 
Device     Boot Start     End Sectors Size Id Type
/dev/sda1        2048 2099199 2097152   1G 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): 
First sector (2099200-20971519, default 2099200): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2099200-20971519, default 20971519): +6g 
Created a new partition 2 of type 'Extended' and of size 6 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: 0x094ec07d
 
Device     Boot   Start      End  Sectors Size Id Type
/dev/sda1          2048  2099199  2097152   1G 83 Linux
/dev/sda2       2099200 14682111 12582912   6G  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 (2101248-14682111, default 2101248): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2101248-14682111, default 14682111): +4g 
Created a new partition 5 of type 'Linux' and of size 4 GiB.
 
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
 
[root@localhost ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda             8:0    0   10G  0 disk 
├─sda1          8:1    0    1G  0 part 
├─sda2          8:2    0    1K  0 part 
└─sda5          8:5    0    4G  0 part 
sdb             8:16   0    5G  0 disk 
├─sdb1          8:17   0    2G  0 part /guazai1
└─sdb2          8:18   0    2G  0 part /guazai2
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   15G  0 disk 
[root@localhost ~]# lsblk -p
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
/dev/sda                    8:0    0   10G  0 disk 
├─/dev/sda1                 8:1    0    1G  0 part 
├─/dev/sda2                 8:2    0    1K  0 part 
└─/dev/sda5                 8:5    0    4G  0 part 
/dev/sdb                    8:16   0    5G  0 disk 
├─/dev/sdb1                 8:17   0    2G  0 part /guazai1
└─/dev/sdb2                 8:18   0    2G  0 part /guazai2
/dev/nvme0n1              259:0    0   20G  0 disk 
├─/dev/nvme0n1p1          259:1    0  600M  0 part /boot/efi
├─/dev/nvme0n1p2          259:2    0    1G  0 part /boot
└─/dev/nvme0n1p3          259:3    0 18.4G  0 part 
  ├─/dev/mapper/rhel-root 253:0    0 16.4G  0 lvm  /
  └─/dev/mapper/rhel-swap 253:1    0    2G  0 lvm  [SWAP]
/dev/nvme0n2              259:4    0   15G  0 disk 
[root@localhost ~]# mafs.ext4 /dev/sda1
bash: mafs.ext4: command not found...
[root@localhost ~]# mkfs.ext4 /dev/sda1
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: c07622a9-d152-401f-9857-8e1d8924afa6
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 ~]# blkid /dev/sda1
/dev/sda1: UUID="c07622a9-d152-401f-9857-8e1d8924afa6" TYPE="ext4" PARTUUID="094ec07d-01"
[root@localhost ~]# mkdir /guazai3
[root@localhost ~]# mount /dev/sda1 /guazai3
[root@localhost ~]# echo this is 3 > /guazai3/3.txt
[root@localhost ~]# mkfs.xfs /dev/sda5
meta-data=/dev/sda5              isize=512    agcount=4, agsize=262144 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1 nrext64=0
data     =                       bsize=4096   blocks=1048576, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=16384, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# blkid /dev/sda5
/dev/sda5: UUID="2f3ebfc7-6575-4392-bf96-417a7be089cc" TYPE="xfs" PARTUUID="094ec07d-05"
[root@localhost ~]# mkdir /guazai4
[root@localhost ~]# mount /dev/sda5 /guazai4
[root@localhost ~]# echo this is 4 > /guazai4
-bash: /guazai4: Is a directory
[root@localhost ~]# echo this is 4 > /guazai4/4.txt
[root@localhost ~]# lsblk -p
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
/dev/sda                    8:0    0   10G  0 disk 
├─/dev/sda1                 8:1    0    1G  0 part /guazai3
├─/dev/sda2                 8:2    0    1K  0 part 
└─/dev/sda5                 8:5    0    4G  0 part /guazai4
/dev/sdb                    8:16   0    5G  0 disk 
├─/dev/sdb1                 8:17   0    2G  0 part /guazai1
└─/dev/sdb2                 8:18   0    2G  0 part /guazai2
/dev/nvme0n1              259:0    0   20G  0 disk 
├─/dev/nvme0n1p1          259:1    0  600M  0 part /boot/efi
├─/dev/nvme0n1p2          259:2    0    1G  0 part /boot
└─/dev/nvme0n1p3          259:3    0 18.4G  0 part 
  ├─/dev/mapper/rhel-root 253:0    0 16.4G  0 lvm  /
  └─/dev/mapper/rhel-swap 253:1    0    2G  0 lvm  [SWAP]
/dev/nvme0n2              259:4    0   15G  0 disk 
[root@localhost ~]# 

第三块硬盘,虚拟磁盘类型选择NVME。大小选择15G。按gpt格式分区。分一个主分区。主分区创建xfs类型的文件系统,挂载到/guazai5,在其

[root@localhost ~]# lsblk -p
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
/dev/sda                    8:0    0   10G  0 disk 
├─/dev/sda1                 8:1    0    1G  0 part /guazai3
├─/dev/sda2                 8:2    0    1K  0 part 
└─/dev/sda5                 8:5    0    4G  0 part /guazai4
/dev/sdb                    8:16   0    5G  0 disk 
├─/dev/sdb1                 8:17   0    2G  0 part /guazai1
└─/dev/sdb2                 8:18   0    2G  0 part /guazai2
/dev/nvme0n1              259:0    0   20G  0 disk 
├─/dev/nvme0n1p1          259:1    0  600M  0 part /boot/efi
├─/dev/nvme0n1p2          259:2    0    1G  0 part /boot
└─/dev/nvme0n1p3          259:3    0 18.4G  0 part 
  ├─/dev/mapper/rhel-root 253:0    0 16.4G  0 lvm  /
  └─/dev/mapper/rhel-swap 253:1    0    2G  0 lvm  [SWAP]
/dev/nvme0n2              259:4    0   15G  0 disk 
[root@localhost ~]# 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 0x98850692.
 
Command (m for help): p
Disk /dev/nvme0n2: 15 GiB, 16106127360 bytes, 31457280 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: dos
Disk identifier: 0x98850692
 
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 
Command (m for help): g
 
Created a new GPT disklabel (GUID: 77BE4738-70CF-8241-8E57-A7B24C4A79BD).
 
Command (m for help): p
Disk /dev/nvme0n2: 15 GiB, 16106127360 bytes, 31457280 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: 77BE4738-70CF-8241-8E57-A7B24C4A79BD
 
Command (m for help): n
Partition number (1-128, default 1): 
First sector (2048-31457246, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-31457246, default 31457246): +5g
 
Created a new partition 1 of type 'Linux filesystem' and of size 5 GiB.
 
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
 
[root@localhost ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda             8:0    0   10G  0 disk 
├─sda1          8:1    0    1G  0 part /guazai3
├─sda2          8:2    0    1K  0 part 
└─sda5          8:5    0    4G  0 part /guazai4
sdb             8:16   0    5G  0 disk 
├─sdb1          8:17   0    2G  0 part /guazai1
└─sdb2          8:18   0    2G  0 part /guazai2
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   15G  0 disk 
└─nvme0n2p1   259:6    0    5G  0 part 
[root@localhost ~]# mkfs.xfs /dev/nvme0n2p1
meta-data=/dev/nvme0n2p1         isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1 nrext64=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=16384, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# blkid /dev/nvme0n2p1
/dev/nvme0n2p1: UUID="3f7031e8-c314-439c-9bef-3d1a1c1174b5" TYPE="xfs" PARTUUID="61f2af0e-8188-5045-95b7-853fd98538a4"
[root@localhost ~]# mkdir /guazai5
[root@localhost ~]# mount /dev/nvme0n2p1 /guazai5
[root@localhost ~]# echo this is 5 > /guazai5/5.txt
[root@localhost ~]# cat /guazai5
cat: /guazai5: Is a directory
[root@localhost ~]# cat /guazai5/5.txt
this is 5

中存入5.txt的文件,其文件内容是this is 5。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值