Linux挂载磁盘目录

一、背景

由于安装oracle数据库,磁盘空间不足,已经加了存储,但是没有挂载,需要将/dev/sdb全部挂载到/oracle目录下

[root@database-001 ~]#  lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   50G  0 disk 
└─sda1   8:1    0   50G  0 part /
sdb      8:16   0  800G  0 disk 
[root@database-001 ~]#  

二、开始挂载磁盘

1、查看
[root@database-001 ~]# fdisk -l
                                                                                                                                    
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000f24de
                                                                                                                                    
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   104857566    52427759+  83  Linux
                                                                                                                                    
Disk /dev/sdb: 859.0 GB, 858993459200 bytes, 1677721600 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@database-001 ~]# 

从上面查看,/dev/sdb 可以挂载
2、挂载磁盘

说明:

分区的起始磁柱值和截止磁柱值计算方法:

sectors值=容量/512 bytes,1GiB=1073741824 bytes

  • First sector (2048-209715199, default 2048)是数据盘/dev/vdb(100 GiB)的磁柱范围

    起始磁柱=2048

    截止磁柱值=sectors值-1=(100 * 1073741824 / 512)-1=209715200-1=209715199

  • 数据盘/dev/vdb的第1个分区/dev/vdb1(40 GiB):

    起始磁柱值=2048(此处使用数据盘/dev/vdb的起始磁柱)

    截止磁柱值=sectors值-1=(40 * 1073741824 / 512 )-1=83886079

  • 数据盘/dev/vdb的第2个分区/dev/vdb2(60 GiB):

    起始磁柱值 = /dev/vdb1的截止磁柱值 + 1 = 83886079+1 = 83886080

    截止磁柱值 = 起始磁柱值 + sectors - 1 = 83886080+(60 * 1073741824 / 512 ) -1 = 209715199

  • fdisk /dev/sdb :开始挂载

  • n:新建一个分区

  • p:“p”表示主分区,“e”表示扩展分区。

  • 1:"Partition number (1-4): "选择主分区号   输入"1"表示第一个主分区

  • First sector:起始磁柱值

  • Last sector:截止磁柱值

  • p:查看分区情况

  • w:保存

[root@database-001 ~]# 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): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p):p
Partition number (1-4, default 1): 1
First sector (2048-1677721599, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1677721599, default 1677721599): 1677721599
Partition 1 of type Linux and of size 800 GiB is set
                                                                                                                                    
Command (m for help): p
                                                                                                                                    
Disk /dev/sdb: 859.0 GB, 858993459200 bytes, 1677721600 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: 0xf3c5bc73
                                                                                                                                    
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  1677721599   838859776   83  Linux
                                                                                                                                    
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

[root@database-001 ~]#
 3、确认分区格式
[root@database-001 ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p                                                                
Model: Huawei VBS fileIO (scsi)
Disk /dev/sdb: 859GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 
                                                                                                                                    
Number  Start   End    Size   Type     File system  Flags
 1      1049kB  859GB  859GB  primary
                                                                                                                                    
(parted) q                                                                
[root@database-001 ~]# 

说明:

“Partition Table:msdos”表示磁盘分区格式为MBR

输入“q”,按“Enter”,退出parted模式。

4、对分区/dev/sdb1 创建ext4文件系统
[root@database-001 ~]# mkfs -t ext4 /dev/sdb1
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
52428800 inodes, 209714944 blocks
10485747 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2357198848
6400 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
                                                                                                                                    
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done     
                                                                                                                                    
[root@database-001 ~]# 
5、再次确认分区格式

执行“parted /dev/sdb”命令,再输入“p”,查看分区文件系统类型已经是ext4。

[root@database-001 ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p                                                                
Model: Huawei VBS fileIO (scsi)
Disk /dev/sdb: 859GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 
                                                                                                                                    
Number  Start   End    Size   Type     File system  Flags
 1      1049kB  859GB  859GB  primary  ext4
                                                                                                                                    
(parted) q                                                                
[root@ecs-database-001 ~]# 
6、新建目录,并将新建分区挂载至新建目录
[root@database-001 ~]# mkdir /oracle
[root@database-001 ~]# mount /dev/sdb1 /oracle

[root@database-001 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   50G  0 disk 
└─sda1   8:1    0   50G  0 part /
sdb      8:16   0  800G  0 disk 
└─sdb1   8:17   0  800G  0 part /oracle
7、使用磁盘分区的UUID来设置开机自动挂载磁盘分区
-- 查询磁盘分区的UUID。
[root@database-001 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="c5a0a667-fa70-49ee-aaf3-6ef60b81f633" TYPE="ext4" 

-- 设置开机自动挂载磁盘分区
[root@database-001 ~]# vi /etc/fstab
UUID=c5a0a667-fa70-49ee-aaf3-6ef60b81f633    /oracle     ext4    defaults     0    2

8、挂载完成
[root@database-001 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         31G     0   31G   0% /dev
tmpfs            31G     0   31G   0% /dev/shm
tmpfs            31G  8.6M   31G   1% /run
tmpfs            31G     0   31G   0% /sys/fs/cgroup
/dev/sda1        50G  4.0G   43G   9% /
tmpfs           6.1G     0  6.1G   0% /run/user/0
/dev/sdb1       788G   73M  748G   1% /oracle
[root@database-001 ~]# 

猜你喜欢

转载自blog.csdn.net/weixin_69821704/article/details/140613777