CentOS VPS硬盘挂载操作

有些VPS 默认没有帮你挂载硬盘,这时你的VPS默认空间是很小的。挂载硬盘 实际就相当于你接了个移动硬盘来扩容。 
而硬盘挂载操作也比较简单,主要就是以下几句代码:

mkdir  /mnt/sdb
mkfs.ext3    /dev/xvdb1
mount /dev/xvdb1 /mnt/sdb

那么接下来,详细记录一下硬盘挂载的步骤。

1. 添加磁盘,查看磁盘状况

fdisk -l

2. 用fdisk 对/dev/xvdb进行分区

fdisk /dev/xvdb

说明:通过第一步查看了硬盘名称后,再对相应的硬盘座分区。 
然后看着说明依次输入n、p、1、w 四个步骤。(详细请看文章后面的步骤过程)

3. 格式化 /dev/xvdb1 分区

mkfs -t ext3 /dev/xvdb1

4. 创建目录 并将 /dev/sdb1 挂在到该目录下


mkdir /mnt/sdb
mount /dev/xvdb1 /mnt/sdb

5. 验证挂载是否成功

df -k

6. 设置开机自动挂载

vi /etc/fstab

这里用Vi命令进行文件编辑 
/dev/xvdb1 41279536 180240 39002416 1% /mnt/sdb

以下是我的完整操作流程记录:

[root@MyCloudServer ~]# fdisk -l

Disk /dev/xvdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/xvdb doesn't contain a valid partition table

Disk /dev/xvda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

	Device Boot	  Start		 End	  Blocks   Id  System
/dev/xvda1   *		   1		  13	  104391   83  Linux
/dev/xvda2			  14		1044	 8281507+  8e  Linux LVM
/dev/xvda3			1045		1305	 2096482+  8e  Linux LVM

[root@MyCloudServer ~]

# fdisk /dev/xvdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won’t be recoverable. The number of cylinders for this disk issetto 5221. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): p Disk /dev/xvdb: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-5221, default 1): Usingdefault value 1 Last cylinder or +size or +sizeM or +sizeK (1-5221, default 5221): Usingdefault value 5221 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.

[root@MyCloudServer ~]

# fdisk -l Disk /dev/xvdb: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/xvdb1 1 5221 41937651 83 Linux Disk /dev/xvda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/xvda1 * 1 13 104391 83 Linux /dev/xvda2 14 1044 8281507+ 8e Linux LVM /dev/xvda3 1045 1305 2096482+ 8e Linux LVM

[root@MyCloudServer ~]

# mkfs -t ext3 /dev/xvdb1 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 5242880 inodes, 10484412 blocks 524220 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=0 320 block groups 32768 blocks per group, 32768 fragments per group 16384 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 36 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@MyCloudServer ~]

# ls

[root@MyCloudServer ~]

# cd /

[root@MyCloudServer /]

# ls bin dev home lost+found misc net proc sbin srv tmp var boot etc lib media mnt opt root selinux sys usr

[root@MyCloudServer /]

# mount /dev/xvdb1 /mnt/sdb mount: mount point /mnt/sdb does not exist

[root@MyCloudServer /]

# cd mnt/sdb -bash: cd: mnt/sdb: 没有那个文件或目录

[root@MyCloudServer /]

# cd mnt/

[root@MyCloudServer mnt]

# ls xs-tools

[root@MyCloudServer mnt]

# mkdir sdb

[root@MyCloudServer mnt]

# mount /dev/xvdb1 /mnt/sdb

[root@MyCloudServer mnt]

# df -k 文件系统 1K-块 已用 可用 已用% 挂载点 /dev/mapper/VolGroup00-LogVol00 9743696 1425864 7814872 16% / /dev/xvda1 101086 44628 51239 47% /boot tmpfs 524380 0 524380 0% /dev/shm /dev/xvdb1 41279536 180240 39002416 1% /mnt/sdb

[root@MyCloudServer mnt]

# vi /etc/fstab

发表评论

电子邮件地址不会被公开。 必填项已用*标注