前言
Windows系统中加入新的硬盘后需要对硬盘进行格式化分区方可以使用。
同样的在Linux系统中新增的硬盘也要进行相应的操作才可以被用户使用。
下面将用虚拟机来演示Linux系统中如何操作用户才能使用新加的硬盘。
首先在虚拟机中新建一块硬盘,然后对新建的硬盘进行分区,格式化,挂载。
下面是具体操作。
查看磁盘分区状态
fdisk -l
[root@sunny ~]# fdisk -l
Disk /dev/sda: 322.1 GB, 322122547200 bytes, 629145600 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 label type: dos
Disk identifier: 0x00090af9
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 18876415 8388608 82 Linux swap / Solaris
/dev/sda3 18876416 629145599 305134592 83 Linux
Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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
硬盘分区
fdisk /dev/sdb >>> 对新加的硬盘sdb进行分区
[root@sunny ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
m查看帮助
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help):
n >>>添加一个新的分区
Command (m for help): n
p >>>分区的类型是主分区(四个主分区,扩展分区从第五个开始)
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
1 >>> 设置第一个分区
Partition number (1-4, default 1): 1
回车键/2048 >>> MBR占用2048
First sector (2048-629145599, default 2048): 2048
设置分区大小+10G >>> 注意单位要大写
Last sector, +sectors or +size{K,M,G} (2048-629145599, default 629145599): +10G
Partition 1 of type Linux and of size 10 GiB is set
p >>> 查看设置完的分区
p print the partition table
Command (m for help): p
Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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 label type: dos
Disk identifier: 0x4a237150
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20973567 10485760 83 Linux
w >>> 保存设置并退出
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
sdb的第一个分区的设置完成了
重启或者键入如下指令启用分区设置
[root@sunny ~]# partprobe /dev/sdb
格式化,设置为xfs文件系统
[root@sunny ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2621440, 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
挂载
创建一个空目录
[root@sunny /]# mkdir yewu
进入/etc/fstab配置文件进行编辑,将/dev/sdb1 挂载到/yewu下。
[root@sunny home]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Jul 3 23:42:00 2024
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=812997ec-d573-4e02-bcef-baa72af34518 / xfs defaults 0 0
UUID=ddf9b4c1-b230-47d9-8d77-cbb470b68e63 /boot xfs defaults 0 0
UUID=6a9460aa-f4f8-426b-b998-272af990752d swap swap defaults 0 0
/dev/sdb1 /yewu xfs defaults 0 0
编辑完成重新加载编辑的内容
[root@sunny home]# mount -a
查看挂载是非成功
[root@sunny /]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 12M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda3 xfs 291G 2.0G 289G 1% /
/dev/sda1 xfs 1014M 142M 873M 14% /boot
tmpfs tmpfs 378M 0 378M 0% /run/user/0
/dev/sdb1 xfs 10G 33M 10G 1% /yewu
已经成功将硬盘sdb的sdb1分区挂载到/yewu下。