linux磁盘分区、挂载

查看当前分区状态并分区

df -h
fdisk -l
fdisk -u /dev/vdb
fdisk -l
[root@iZ8vb1fe0qi2dtzk12mtc6Z ~]# fdisk -l

Disk /dev/vda: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x000bb9c1

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048  1048575966   524286959+  83  Linux

Disk /dev/vdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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@iZ8vb1fe0qi2dtzk12mtc6Z ~]# fdisk /dev/vdb
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 0x92762a19.

Command (m for help): p

Disk /dev/vdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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: 0x92762a19

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): q

[root@iZ8vb1fe0qi2dtzk12mtc6Z ~]# blkid
/dev/vda1: UUID="9f2d3e15-a78a-4f3d-8385-0165b4b67864" TYPE="ext4" 
[root@iZ8vb1fe0qi2dtzk12mtc6Z ~]# 
[root@iZ8vb1fe0qi2dtzk12mtc6Z ~]# fdisk -u /dev/vdb
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 0x8b486dcc.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 0
Invalid partition type `0'

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-4194303999, default 2048): 2097154047^H^C
[root@iZ8vb1fe0qi2dtzk12mtc6Z ~]# fdisk -u /dev/vdb
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 0xbb6c8522.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-4194303999, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303999, default 4194303999): 2097154047
Partition 1 of type Linux and of size 1000 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@iZ8vb1fe0qi2dtzk12mtc6Z ~]# fdisk -l

Disk /dev/vda: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x000bb9c1

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048  1048575966   524286959+  83  Linux

Disk /dev/vdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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: 0xbb6c8522

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048  2097154047  1048576000   83  Linux
[root@iZ8vb1fe0qi2dtzk12mtc6Z ~]# fdisk -u /dev/vdb
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): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2097154048-4194303999, default 2097154048): 
Using default value 2097154048
Last sector, +sectors or +size{K,M,G} (2097154048-4194303999, default 4194303999): 
Using default value 4194303999
Partition 2 of type Linux and of size 1000 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@iZ8vb1fe0qi2dtzk12mtc6Z ~]# fdisk -l

Disk /dev/vda: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x000bb9c1

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048  1048575966   524286959+  83  Linux

Disk /dev/vdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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: 0xbb6c8522

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048  2097154047  1048576000   83  Linux
/dev/vdb2      2097154048  4194303999  1048574976   83  Linux

将/dev/vdb1和/dev/vdb2格式化为ext4格式

mkfs -t ext4 /dev/vdb1 
mkfs -t ext4 /dev/vdb2
[root@iZ8vb1fe0qi2dtzk12mtc6Z ~]# mkfs -t ext4 /dev/vdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536000 inodes, 262144000 blocks
13107200 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2409627648
8000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848

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

[root@iZ8vb1fe0qi2dtzk12mtc6Z ~]# mkfs -t ext4 /dev/vdb2
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536000 inodes, 262143744 blocks
13107187 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2409627648
8000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848

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

[root@iZ8vb1fe0qi2dtzk12mtc6Z ~]# 

新增目录用来挂载数据

mkdir -p /rssp/code /rssp/data /rssp/exdata

备份fstab文件(linux之fstab文件详解

cp /etc/fstab /etc/fstab-bak

写入挂载目录

echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\"//g'` /rssp/data ext4 defaults 0 0 >> /etc/fstab
echo `blkid /dev/vdb2 | awk '{print $2}' | sed 's/\"//g'` /rssp/exdata ext4 defaults 0 0 >> /etc/fstab

查看写入成功否,成功后重启服务器

cat /etc/fstab
reboot

补充:
有时候使用blkid 查询不出来UUID,可以使用以下步骤来解决问题:

  • 确保设备被识别:使用 lsblk 命令查看系统上的块设备列表,确保你的设备(如 /dev/vdb2)在列表中显示。
  • 检查文件系统:确保设备上已经存在一个有效的文件系统。你可以使用 file -s /dev/vdb2 命令检查设备上的文件系统类型。
  • 尝试重新扫描设备:有时,重新扫描设备可以帮助系统识别设备。你可以使用以下命令尝试重新扫描设备:sudo partprobe /dev/vdb
  • 如果上述步骤都无法解决问题,可能是设备或系统配置存在问题。你可能需要检查系统日志以获取更多信息,例如 /var/log/messages或 /var/log/syslog。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值