实验环境:腾讯云Centos7.2
挂载信息:添加/dev/vdc1到/data/ 添加/dev/vdc2到/web/
生产环境:在我们实际的应用也是同样命令步骤挂载
腾讯云云硬盘挂载得先购买具体操作如下:
1、在登录到腾讯云控制台在左侧找到云硬盘-新建-添加一块自己所需求的区域的主机云硬盘,如下图操作:
2、支付完后就会在刚刚的位置多出一块属性为数据盘的云硬盘,状态为待挂载;
3、接下来即后台先挂载上,(就如实际我们买了块硬盘需要接在电脑上样的意思)
到这里我们在腾讯云控制台即操作完毕接下来要去系统中分区格式化挂载使用的目录。
一、检测Linux系统识别的硬盘设备,新添加硬盘被识别为/dev/vdb,如果有多块硬盘,会依次识别成/dev/vdc、/dev/vdd、/dev/vde等设备名,当然也有可能/dev/sdb、/dev/vdc这样的根据实际情况操作。
登录到linux系统执行命令查看刚刚挂载的盘
fdisk -l
二、基于新硬盘/dev/vdc设备,创建磁盘分区/dev/vdc1和/dev/vdc2,如下图;
fdisk /dev/vdc
(1)输入m,fdisk分区命令输入帮助信息,我们常用的参数包括 m、n、p、d、w
- m:输出帮助菜单;
- n:添加一个新分区;
- p:输出分区表信息;
- d:删除一个分区;
- w:将分区表写入磁盘并退出。
(2)接下来继续执行命令分区;
创建/dev/vdc1分区方法,执行命令fdisk /dev/vdc然后按照屏幕提示一次输入n、p、1,按Enter键在输入+5G(这里的+5G即该分区大小根据自己实际情况输入),按Enter键输入w,最后执行 fdisk -l | tail -10,就可以看到刚刚创建的/dev/vdc1分区,(再次创建分区同样的步骤只修将数字变换为2、3、4等此磁盘最多4个分区)如下图;
示例:
[root@VM_173_49_centos ~]# fdisk /dev/vdc 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-20971519, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +5G Partition 1 of type Linux and of size 5 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@VM_173_49_centos ~]# fdisk -l | tail -10 Disk /dev/vdc: 10.7 GB, 10737418240 bytes, 20971520 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: 0x1d8f4532 Device Boot Start End Blocks Id System /dev/vdc1 2048 10487807 5242880 83 Linux [root@VM_173_49_centos ~]# [root@VM_173_49_centos ~]# fdisk /dev/vdc 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 (10487808-20971519, default 10487808): Using default value 10487808 Last sector, +sectors or +size{K,M,G} (10487808-20971519, default 20971519): +4G Partition 2 of type Linux and of size 4 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
(3)格式化磁盘分区 mkfs.ext4 /dev/vdc1(其他即改设备名如分区2:mkfs.ext4 /dev/vdc2)如下图;
示例:
[root@VM_173_49_centos ~]# mkfs.ext4 /dev/vdc1 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 327680 inodes, 1310720 blocks 65536 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1342177280 40 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 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@VM_173_49_centos ~]# mkfs.ext4 /dev/vdc2 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 262144 inodes, 1048576 blocks 52428 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1073741824 32 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 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@VM_173_49_centos ~]#
三、格式化完后我们要挂载到系统目录,使用mount命令挂载到/data/目录和/web/,
mount /dev/vdc1 /data #挂载 /dev/vdc1 分区到/data/目录 mount /dev/vdc2 /web #挂载 /dev/vdc2 分区到/web/目录 df -h #查看磁盘分区挂载详情
示例:
[root@VM_173_49_centos ~]# mount /dev/vdc1 /data [root@VM_173_49_centos ~]# mount /dev/vdc2 /web [root@VM_173_49_centos ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 50G 1.8G 46G 4% / devtmpfs 487M 0 487M 0% /dev tmpfs 497M 24K 497M 1% /dev/shm tmpfs 497M 404K 496M 1% /run tmpfs 497M 0 497M 0% /sys/fs/cgroup tmpfs 100M 0 100M 0% /run/user/0 /dev/vdc1 4.8G 20M 4.6G 1% /data /dev/vdc2 3.9G 16M 3.6G 1% /web [root@VM_173_49_centos ~]#
四、将挂载命令加入到开机启动里面;
echo "mount /dev/vdc1 /data" >>/etc/rc.local echo "mount /dev/vdc2 /web" >>/etc/rc.local
本文作者为SKY RING,转载请注明。