坚持
  • 微信

当前位置:首页 > 应用服务 > LINUX系统 >

Linux 磁盘挂载

作者:管理员 时间:2021-12-31 阅读数: 1648人阅读

[root@localhost /]# fdisk -l           

查看硬盘信息
使用fdisk命令对sdb硬盘进行分区:
[root@linuxprobe ~]# 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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x47d24a34.
敲击字符p查看分区表信息(当前为空):
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x47d24a34
Device Boot Start End Blocks Id System
敲击字符n创建新的分区信息:
Command (m for help): n
敲击字符p,这个p代表是主分区,e为扩展分区:
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
敲击数字1代表分区编号为1:
Partition number (1-4, default 1):
磁盘的起始扇区,直接回车即可:
First sector (2048-41943039, default 2048):
键入+2G,代表该分区的大小为2G:
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +2G
Partition 1 of type Linux and of size 2 GiB is set
再看下分区表信息(增加了sdb1分区信息):
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x47d24a34
Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
敲击字符w,将上述分区信息保存:
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
让内核同步分区信息(此步骤仅在没有找到分区设备的情况下才需要执行,非必要动作。):
[root@linuxprobe ~]# partprobe(非必要)
第3步:格式化为xfs文件系统。
在Linux系统中用于格式化的命令是mkfs,它支持的文件类型有:
cramfs,ext2,ext3,ext4,fat,msdos,xfs,btrfs,minix,vfat
使用方法非常的简单:”mkfs.文件类型名称“,例如要格式分区为ext4,则命令为”mkfs.ext4 硬盘分区名称“。
使用mkfs.xfs来对/dev/sdb1进行格式化:
[root@linuxprobe ~]# mkfs.xfs /dev/sdb1
 
 
第4步:将硬盘设备挂载到/new目录。
[root@linuxprobe ~]# mkdir /new
[root@linuxprobe ~]# mount /dev/sdb1 /new/
第5步:设置系统启动后自动挂载该硬盘设备。
[root@linuxprobe ~]# echo "/dev/sdb1         /new         xfs           defaults            0 0" >> /etc/fstab

第6步: 重新挂载所有分区
#mount -a
第7步 检查是否挂载成功
#df