挂载磁盘 以及 磁盘扩容

挂载磁盘

云主机后台挂载磁盘,或者实体机插入磁盘后,可以在主机里查看所有的分区

fdisk -l

[root@songfei-test ~]# fdisk -l
Disk /dev/vda: 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: 0x803dc0e1
   Device Boot      Start         End      Blocks   Id  System
/dev/vda1             128        4223        2048    e  W95 FAT16 (LBA)
/dev/vda2   *        6144     1030143      512000   83  Linux
/dev/vda3         1030144    41943039    20456448   83  Linux
Disk /dev/vdb: 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: 0x124b9d61
   Device Boot      Start         End      Blocks   Id  System

可以看到我们新插入的磁盘 /dev/vdb 还没有分区

另外也可以通过下述方式来查看系统所有块信息

lsblk

[root@songfei-test ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda    253:0    0   20G  0 disk
├─vda1 253:1    0    2M  0 part
├─vda2 253:2    0  500M  0 part /boot
└─vda3 253:3    0 19.5G  0 part /
vdb    253:16   0   20G  0 disk
└─vdb1 253:17   0   10G  0 part /mnt/disk0

####磁盘分区
依次输入下列命令来新建分区

fdisk /dev/vdb

n

p

1

回车

回车

wq

[root@songfei-test ~]# 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.
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-41943039, default 2048):     #回车默认
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): #回车
Using default value 41943039
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

再次查看分区,可以看到已经有一个 /dev/vdb1 的分区

[root@songfei-test ~]# fdisk -l
Disk /dev/vda: 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: 0x803dc0e1
   Device Boot      Start         End      Blocks   Id  System
/dev/vda1             128        4223        2048    e  W95 FAT16 (LBA)
/dev/vda2   *        6144     1030143      512000   83  Linux
/dev/vda3         1030144    41943039    20456448   83  Linux
Disk /dev/vdb: 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: 0x124b9d61
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    41943039    20970496   83  Linux
然后将磁盘的新分区进行的文件系统格式化处理,文件系统按照自己的需要指定,这边是ext4

mkfs.ext4 /dev/vdb1

[root@songfei-test ~]# mkfs.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
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
160 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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
挂载新分区,指定挂载到的目录

mount /dev/vdb1 /mnt/disk0

对应的卸载命令

umount /mnt/disk0

将挂载信息写入/etc/fstab

最后要将设备挂载的信息写入/etc/fstab,否则机器重启,磁盘将恢复到初始状态(无分区,无文件系统)。

echo /dev/vdb1 /mnt/disk0 ext4 defaults 0 0 >> /etc/fstab

注释:

/dev/sdb1 代表哪个分区

/mnt/disk0 表示挂载的目录
ext4 是该分区文件系统的格式

defaults 表示挂载时所要设定的参数 (只读,读写,启用 quota 等)
输入 defaults 包括的参数有 (rw、dev、exec、auto、nouser、async)

0 是使用 dump 是否要记录,1 要,0 不要

0 是开机时检查的顺序, boot 系统文件就为 1,其他文件系统都为 2,如不要检查就为 0

磁盘扩容

1,首先要终止以下程序:nginx、apache、mysql、php-fpm、ftp

2,卸载磁盘

umount /mnt/disk0

3,购买云主机服务商的后台界面卸载磁盘扩容

4,扩容完挂载磁盘以后,查看分区

[root@songfei-test ~]# fdisk -l
Disk /dev/vda: 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: 0x803dc0e1
   Device Boot      Start         End      Blocks   Id  System
/dev/vda1             128        4223        2048    e  W95 FAT16 (LBA)
/dev/vda2   *        6144     1030143      512000   83  Linux
/dev/vda3         1030144    41943039    20456448   83  Linux
Disk /dev/vdb: 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: 0x124b9d61
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    20971519    10484736   83  Linux

5,首先要删除原来的分区

fdisk /dev/vdb

d

wq

[root@songfei-test ~]# 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 0x7d2d2d43.
Command (m for help): d
No partition is defined yet!
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

6,新建一个分区,参考上面挂载磁盘

7,格式化磁盘

e2fsck -f /dev/vdb1

[root@songfei-test ~]# e2fsck -f /dev/vdb1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdb1: 12/655360 files (0.0% non-contiguous), 439421/2621184 blocks

resize2fs /dev/vdb1

[root@songfei-test ~]# resize2fs /dev/vdb1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vdb1 to 5242624 (4k) blocks.
The filesystem on /dev/vdb1 is now 5242624 blocks long.
[root@songfei-test ~]# mount /mnt/disk0/
mount: can't find /mnt/disk0/ in /etc/fstab

8,挂载分区,磁盘已经扩容,数据仍然存在(但是还是建议对数据进行备份)

mount /dev/vdb1 /mnt/disk0

[root@songfei-test ~]# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/vda3      xfs        20G  1.6G   18G   8% /
devtmpfs       devtmpfs  911M     0  911M   0% /dev
tmpfs          tmpfs     920M     0  920M   0% /dev/shm
tmpfs          tmpfs     920M  8.4M  912M   1% /run
tmpfs          tmpfs     920M     0  920M   0% /sys/fs/cgroup
/dev/vda2      xfs       497M  123M  375M  25% /boot
tmpfs          tmpfs     184M     0  184M   0% /run/user/0
/dev/vdb1      ext4       20G  1.5G   18G   8% /mnt/disk0
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值