您的位置:首页 > 运维架构 > Linux

Linux中对VPS的硬盘扩容后的分区记录

2011-11-12 15:03 369 查看
对新硬盘的分区,相对来说比较方便,也比较容易,因为不用担心原来的数据丢失等等问题,操作失败了,大不了重来,就这么简单,如果不清楚如何对新硬盘进行分区,可以查看一下这篇文章:Linux中对VPS新硬盘的分区示例以及如何进行分区的教程,我这里记录的是如何对原来已经存在的硬盘,对扩容部分进行的分区及挂载的记录。

linux中进行分区主要使用到三个工具:

fdisk:对分区信息进行查看,以及对分区进行操作;

mkfs:对新分区进行格式化;

mount:这个就是对分区后的硬盘进行挂载,只有挂载到指定的目录后,才可以被正常使用。

因为是对已经存在的硬盘进行再分区,那操作就相对要小心、仔细一点,首先通过命令 “fdisk -l”查看所有的分区信息,显示如下:

root@MyVPS2282:/dev# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x000a5e58

Device Boot Start End Blocks Id System

/dev/sda1 * 1 32 248832 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2 32 1045 8136705 5 Extended

/dev/sda3 1045 1305 2094828+ 8e Linux LVM

/dev/sda5 32 1045 8136704 8e Linux LVM

Disk /dev/sdb: 64.4 GB, 64424509440 bytes

255 heads, 63 sectors/track, 7832 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x9d47bcdd

Device Boot Start End Blocks Id System

/dev/sdb1 1 3916 31455238+ 83 Linux

从列出来的结果可以看到,当前两块磁盘sda和sdb,sda的空间大小是10.7G,分了5个区,基本上是使用完了;第二块磁盘sdb有64.4G,而我们看到标红字的显示只使用了30个G,那说明还有30个G没有使用,那这没有使用的30个G就是新增加的30个G硬盘空间了,这时我们要做的就是把sdb中剩余的30个G给分出来。打入命令:

root@MyVPS2282:/dev# fdisk /dev/sdb

Command (m for help): n (n表示新创建新区,如果不知道命令如何使用,先打入m先查看帮助)

Command action

e extended

p primary partition (1-4)

(以上是让选择创建主分区还是扩展,我这里刚开始选择创建的是扩展分区,因为原来的30个G我创建的主分区,但是后面通过mkfs创建文件系统的时候会报错,所以这里我后来是删除了创建的扩展分区,重新选择创建主分区才成功)

p (选择创建主分区)

Partition number (1-4): 2 (通过命令fdisk -l例出来的分区信息可以看到,已经sdb已经分了第一个区sdb1,因而这里必须输入大于1的数字,否则系统会提示你输入的分区号已经存在,要求重新输入)

First cylinder (3917-7832, default 3917):
(让选择是从磁盘的那个位置开始创建,这里可以不需要输入,直接回车即可,默认为从上个分区的结束位置开始)


Using default value 3917

Last cylinder, +cylinders or +size{K,M,G} (3917-7832, default 7832):(选择硬盘结束位置,如果不想再分其它区了,直接回车即可,默认为剩余的所有磁盘空间)

Using default value 7832

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: Device or resource busy.

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)

最后这一行的提示是说,需要重新启动系统,分区才可以生效,如果这个时候不重启系统,直接通过mkfs创建文件系统,系统会报错:

mke2fs 1.41.12 (17-May-2010)

mkfs.ext3: inode_size (128) * inodes_count (0) too big for a

filesystem with 0 blocks, specify higher inode_ratio (-i)

or lower inode count (-N).

那就乖乖的重启系统吧。

重启后,再通过:

mkfs -t exts /dev/sdb2

对新分区创建文件系统,分有如下提示:

ke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

1966080 inodes, 7863817 blocks

393190 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=0

240 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

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 33 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

到此,分区就创建成功了,这个需要只需要将其挂载到指定的目录即可:

mount /dev/sdb2 /aaa

当然为了能够在下次启动的时候,让其自动挂载,我们需要在分区表中加入如下信息:

/dev/sdb2 /aaa ext3 defaults 1 2

分区表的文件位于:/etc/fstab

通过df命令就可以看到我们挂载后的分区了,至此分区成功完成。

本文出自:冯立彬的博客
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: