Linux下磁盘挂载

Posted 夜里码码

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下磁盘挂载相关的知识,希望对你有一定的参考价值。

1.查看是否已分配

[[email protected] ~]# fdisk -l

Disk /dev/vda: 536.9 GB, 536870912000 bytes
16 heads, 63 sectors/track, 1040253 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00062b97

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       41611    20458496   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

2、发现有磁盘,路径为/dev/vda。然后使用fdisk命令进行分区

[[email protected] ~]# fdisk /dev/vda

WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to
         switch off the mode (command ‘c‘) and change display units to
         sectors (command ‘u‘).

Command (m for help): p

Disk /dev/vda: 536.9 GB, 536870912000 bytes
16 heads, 63 sectors/track, 1040253 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00062b97

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       41611    20458496   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1-1040253, default 1): 41611
Last cylinder, +cylinders or +size{K,M,G} (41611-1040253, default 1040253): 665776

Command (m for help): p

Disk /dev/vda: 536.9 GB, 536870912000 bytes
16 heads, 63 sectors/track, 1040253 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00062b97

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       41611    20458496   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda3           41611      665776   314579584   83  Linux

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Selected partition 4
First cylinder (1-1040253, default 1): 4
Sector 3024 is already allocated
First cylinder (665777-1040253, default 665777): 665777
Last cylinder, +cylinders or +size{K,M,G} (665777-1040253, default 1040253):
Using default value 1040253

Command (m for help): p

Disk /dev/vda: 536.9 GB, 536870912000 bytes
16 heads, 63 sectors/track, 1040253 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00062b97

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       41611    20458496   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda3           41611      665776   314579584   83  Linux
/dev/vda4          665777     1040253   188736408   83  Linux

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

解释:

Partition number表示分区号,由于1、2号已经分区所有从3号分区开始

其中 n 新建分区 d删除分区 p打印分区 w将表写入磁盘保存并退出

3、然后使用fdisk -l 命令查看,已经新建的分区

[[email protected] ~]# fdisk -l

Disk /dev/vda: 536.9 GB, 536870912000 bytes
16 heads, 63 sectors/track, 1040253 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00062b97

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       41611    20458496   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda3           41611      665776   314579584   83  Linux
/dev/vda4          665777     1040253   188736408   83  Linux

红色部分为刚刚新建的分区

6.建好分区后对分区进行格式化,建立文件系统 mkfs.ext3

[[email protected] ~]# mkfs.ext3 /dev/vda3
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
19668992 inodes, 78644896 blocks
3932244 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
2401 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

正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[[email protected] ~]# mkfs.ext3 /dev/vda4
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
11796480 inodes, 47184102 blocks
2359205 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
1440 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

正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


7.然后mount选择一个挂载点挂上

[[email protected] ~]# mount /dev/vda3 /var
[[email protected] ~]# mount /dev/vda4 /opt

8.使用 df -TH  查看文件大小


[[email protected] ~]# df -TH /opt
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/vda4      ext3  191G  197M  181G   1% /opt
[[email protected] ~]# df -TH /var
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/vda3      ext3  318G  201M  301G   1% /var

注意:

如果挂载错误可以使用umount取消挂载,如果找不到分区使用partprobe 刷新分区实在不行就reboot下

使用fdisk -l即可查看新的分区

 

来源:https://blog.csdn.net/scmrpu/article/details/86498961

























































































































以上是关于Linux下磁盘挂载的主要内容,如果未能解决你的问题,请参考以下文章

linux下挂载磁盘的命令是啥

linux中划分新的磁盘分区并挂载到一个目录下的目的是啥?如何知道一个目录挂载了那个磁盘剩多少空间?

linux磁盘挂载

linux中划分新的磁盘分区并挂载到一个目录下的目的是啥?如何知道一个目录挂载了那个磁盘剩多少空间?

磁盘分区开机自动挂载

linux怎么移动文件到挂载的磁盘,求详细命令