1、对磁盘进行分区,创建文件系统,挂载,Linux命令

已有硬盘情况

[root@localhost redhat]# lsblk -p
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
/dev/sda                    8:0    0   10G  0 disk  #第二块硬盘,虚拟磁盘类型选择STAT。大小选择10G。
/dev/sdb                    8:16   0    5G  0 disk  #第一块硬盘,虚拟磁盘类型选择SCSI。大小选择5G。
/dev/sr0                   11:0    1   11G  0 rom  
/dev/nvme0n1              259:0    0   40G  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 38.4G  0 part 
  ├─/dev/mapper/rhel-root 253:0    0 36.4G  0 lvm  /
  └─/dev/mapper/rhel-swap 253:1    0    2G  0 lvm  [SWAP]
/dev/nvme0n2              259:4    0   15G  0 disk  #第三块硬盘,虚拟磁盘类型选择NVME。大小选择15G。

第一块硬盘

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

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

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 0x4a0cec1a.

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): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response 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): 

Created a new partition 2 of type 'Linux' and of size 3 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: 0x4a0cec1a

Device     Boot   Start      End Sectors Size Id Type   
/dev/sdb1          2048  4196351 4194304   2G 83 Linux
/dev/sdb2       4196352 10485759 6289408   3G 83 Linux
[root@localhost redhat]# mkfs.ext2 /dev/sdb1
[root@localhost ~]# mkdir /guazai1
[root@localhost ~]# mount /dev/sdb1 /guazai1

[root@localhost ~]# touch /guazai1/1.txt

[root@localhost ~]# mkfs.ext2 /dev/sdb2  

[root@localhost ~]# mkdir /guazai2

[root@localhost ~]# mount /dev/sdb2  /guazai2     #第二个主分区挂载到/guazai2目录

[root@localhost ~]# echo this is 2.txt >> /guazai2/2.txt   #并在其中存入2.txt的文件。其文件内容是this is 2.txt

第二块硬盘,

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


[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 0xe2a851af.

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): 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): 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): 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: 0xe2a851af

Device     Boot   Start      End  Sectors Size Id Type
/dev/sda1          2048  2099199  2097152   1G 83 Linux
/dev/sda2       2099200 14682111 12582912   6G  5 Extended 扩展分区
/dev/sda5       2101248 10489855  8388608   4G 83 Linux #逻辑分区

Command (m for help): w
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/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    3G  0 part /guazai2
/dev/sr0                   11:0    1   11G  0 rom  
/dev/nvme0n1              259:0    0   40G  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 38.4G  0 part 
  ├─/dev/mapper/rhel-root 253:0    0 36.4G  0 lvm  /
  └─/dev/mapper/rhel-swap 253:1    0    2G  0 lvm  [SWAP]
/dev/nvme0n2              259:4    0   15G  0 disk 
└─/dev/nvme0n2p1          259:5    0    5G  0 part /guazai5

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

mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: 7501cc02-66b7-4845-b21a-9a782d7e65c2
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 ~]# mkdir /guazai3
[root@localhost ~]# mount /dev/sda1 /guazai3    #将主分区创建为ext4类型的文件系统。挂载到/guazai3目录。

[root@localhost ~]# touch this is 3.txt >> /guazai3/3.txt    #在其中存入3.txt的文件,其文件内容是this is 3.txt

[root@localhost ~]# mkfs.xfs /dev/sda5    #将逻辑分区创建xfs类型的文件系统。
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 ~]# mkdir /guazai4

[root@localhost ~]# mount /dev/sda5 /guazai4
[root@localhost ~]# echo this is 4.txt >> /guazai4/4.txt

第三块硬盘,

虚拟磁盘类型选择NVME。大小选择15G。按gpt格式分区。分一个主分区。大小为5G。主分区创建xfs类型的文件系统,挂载到/guazai5目录,在其中存入5.txt的文件,其文件内容是this is 5.txt。

[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 0x6443ddfc.

Command (m for help): g
Created a new GPT disklabel (GUID: D978E9DC-00E9-AB4F-8275-3DF965AF56F3).

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 ~]# 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 ~]# mkdir /guazai5

[root@localhost ~]# mount /dev/nvme0n2p1 /guazai5    #挂载到/guazai5目录

[root@localhost ~]# echo this is 5.txt >> /guazai5/5.txt 


©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,997评论 6 502
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,603评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,359评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,309评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,346评论 6 390
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,258评论 1 300
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,122评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,970评论 0 275
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,403评论 1 313
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,596评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,769评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,464评论 5 344
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,075评论 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,705评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,848评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,831评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,678评论 2 354

推荐阅读更多精彩内容