实践: 扩充/ 根目录的空间

给 linux 跟目录增加空间:

先看一下目前的磁盘的使用情况:
[root@sheng ~]# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         515     4088542+  83  Linux
/dev/sda3             516         776     2096482+  82  Linux swap / Solaris
/dev/sda4             777        1044     2152710    5  Extended
/dev/sda5             777        1044     2152678+  83  Linux


先试着扩大磁盘:
[root@sheng ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 1044.
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)

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help):

要扩的话,要键入:n (new)


Command (m for help): n
No free sectors available

注意:sectors: 扇区
好,下面进行扩空间做一个新的分区。

Step2:

增加vmware disk space:
vmware 提供了一个命令行工具:vmware-vdiskmanager.exe
注意,到vmware 的安装目录下去,而不是linux 所在的位置:
右键 桌面上的vmware 的图标 :D:/Program Files/VMware/VMware Workstation

运行--> cmd -->D:/Program Files/VMware/VMware Workstation>

D:/Program Files/VMware/VMware Workstation>vmware-vdiskmanager -x 10Gb C:/clear_RHEL5/RHEL5.vmdk
  Grow: 42% done.
  慢慢的等到:100%就可以了:
 
  在增加的过程中,会看到 在C:/clear_RHEL5 有个文件:RHEL5.vmdk.dfgshkgrw-tmp 一直在增加。

最后:
D:/Program Files/VMware/VMware Workstation>vmware-vdiskmanager -x 10Gb C:/clear
RHEL5/RHEL5.vmdk
  Grow: 100% done.
Disk expansion completed successfully.

WARNING: If the virtual disk is partitioned, you must use a third-party
         utility in the virtual machine to expand the size of the
         partitions. For more information, see:
         http://www.vmware.com/support/kb/enduser/std_adp.php?p_faqid=1647

D:/Program Files/VMware/VMware Workstation>

好现在我们来看看:
fdisk -l (我是把虚拟机关掉再扩充的)

说明:要扩容的系统这时不能在运行 ,参数 "-x" 表示要扩展虚拟机硬盘空间,紧随其后的数字是要扩展到的大小 ,而非增加量 (本例为扩展到 16GB ,这是一个磁盘总量,包含了原先的磁盘容量 ) 。 最后是指定要操作的虚拟机磁盘的具体文件,要是路径名中有空格,必须以双引号括起来。按回车键开始执行,执行完毕,退出命令提示符窗口,重启 VMware ,会发现虚拟机硬盘空间已变成 16GB 了。

2、我们重启虚拟机后,发现虚拟机的硬盘是变成 10GB 了,但进入 linux 系统后,用 "df -h"查看发现硬盘空间还是原先那么大。 虽然已经扩大了磁盘,但是由于还没有经过分区,指定文件系统,所以 linux 操作系统无法识别。其实就相当于你的硬盘虽然大了,但是你并没有对其进行分区是一个道理。

[root@localhost ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 1305.
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)

Command (m for help): n
No free sectors available

我就奇怪了:
[root@localhost ~]# fdisk -l

Disk /dev/sda: 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/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         515     4088542+  83  Linux
/dev/sda3             516         776     2096482+  82  Linux swap / Solaris
/dev/sda4             777        1044     2152710    5  Extended
/dev/sda5             777        1044     2152678+  83  Linux

前面执行fdisk -l的时候明明最后才是1044柱面,而且应该有1305柱面,为什么说没有空闲的扇区。

再看看fdisk -l执行结果,原来是/dev/sda5分配了作为swap分区,找到原因了就容易解决。

参考:http://www.cppblog.com/cfrolife/archive/2011/04/13/144082.html
我进行下面的实验:说明:

如果出现:

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         515     4088542+  83  Linux
/dev/sda3             777        1044     2152710    5  Extended
/dev/sda4             777        1044     2152678+  83  Linux
/dev/sda5             516         776     2096482+  82  Linux swap / Solaris

swap 在最下面的,就需要swapoff sda5 再进行 delete sda4.和sda5

好,下面不进行关闭 swap 分区,我们来试delete sda4,和sda5:

[root@localhost ~]# fdisk -l

Disk /dev/sda: 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/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         515     4088542+  83  Linux
/dev/sda3             516         776     2096482+  82  Linux swap / Solaris
/dev/sda4             777        1044     2152710    5  Extended
/dev/sda5             777        1044     2152678+  83  Linux
[root@localhost ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 1305.
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)

Command (m for help): d
Partition number (1-5): d
Partition number (1-5): 5

Command (m for help): d
Partition number (1-5): 4

Command (m for help): d
Partition number (1-4): 4
Warning: partition 4 has empty type

Command (m for help): p

Disk /dev/sda: 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/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         515     4088542+  83  Linux
/dev/sda3             516         776     2096482+  82  Linux swap / Solaris

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Selected partition 4
First cylinder (777-1305, default 777):
Using default value 777
Last cylinder or +size or +sizeM or +sizeK (777-1305, default 1305):
Using default value 1305

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.
Syncing disks.
[root@localhost ~]#

好下面看一下啊:
[root@localhost ~]# fdisk -l

Disk /dev/sda: 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/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         515     4088542+  83  Linux
/dev/sda3             516         776     2096482+  82  Linux swap / Solaris
/dev/sda4             777        1305     4249192+   5  Extended

增加新的分区;

[root@localhost ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 1305.
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)

Command (m for help): n
First cylinder (777-1305, default 777):
Using default value 777
Last cylinder or +size or +sizeM or +sizeK (777-1305, default 1305):
Using default value 1305

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.
Syncing disks.
[root@localhost ~]#

[root@localhost ~]# fdisk -l

Disk /dev/sda: 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/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         515     4088542+  83  Linux
/dev/sda3             516         776     2096482+  82  Linux swap / Solaris
/dev/sda4             777        1305     4249192+   5  Extended
/dev/sda5             777        1305     4249161   83  Linux

发现比原来的结束的变了: 1305

我们的新建分区/dev/sda5,却不是LVM的。所以,接下来使用fdisk将其改成LVM的
[root@localhost ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 1305.
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)

Command (m for help): t
Partition number (1-5): 4
Hex code (type L to list codes): 8e
You cannot change a partition into an extended one or vice versa
Delete it first.

Command (m for help): t (改变分区系统id)
Partition number (1-5): 5 (指定分区号)
Hex code (type L to list codes): 8e (指定要改成的id号,8e代表LVM)
Changed system type of partition 5 to 8e (Linux LVM)

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.
Syncing disks.
[root@localhost ~]#

我们现在还不能用这个分区 , 因为我们没格式化。这时要重启系统就能够在 dev 下面看到 sda3 ,
如果不重启不能进行下面操作(这个切记,很重要)。

重启后,在此查看fdisk -l

[root@localhost ~]# fdisk -l

Disk /dev/sda: 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/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         515     4088542+  83  Linux
/dev/sda3             516         776     2096482+  82  Linux swap / Solaris
/dev/sda4             777        1305     4249192+   5  Extended
/dev/sda5             777        1305     4249161   8e  Linux LVM

可以看到/dev/sda5已支持LVM。

第三步、格式化该新添加的分区

键入:
mkfs -t ext3 /dev/sda5
或者
mkfs.ext3 /dev/sda5

来格式化指定的分区,依次类推,现在的系统大部分都是 ext3 格式,如果你需要其它的,可以查看mkfs 的帮助。

到此为止,我们就新建了一个分区/dev/sda5,此时我们已经可以通过挂载,来使用这个新的空间。但是对于我,这并不能满足我的需求,
因为服务器的服务程序是在根目录上的,目前根目录空间已经使用完毕,所以能把新建的分区使用在更目录上,分担根目录的空间,才能解决问题。

下面用到的理论是基于LVM的,如果不知道的话,建议稍微查些资料有助于理解。当然,一步步的跟我做,应该也没有问题。

[root@localhost ~]# mkfs -t ext3 /dev/sda5
mke2fs 1.39 (29-May-2006)
/dev/sda5 is mounted; will not make a filesystem here!

分析:
一定要记住,不可以在分区挂载之后再进行格式化!!
在错误提示当中可以看出你的分区已经挂载了。先将这个分区卸载了再重新格式化:
umount /dev/sda5
mkfs.ext3 /dev/sda5
这样就没有问题了.然后你再重新挂载分区:

[root@localhost ~]# umount /dev/sda5
[root@localhost ~]# mkfs -t ext3 /dev/sda5
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
269280 inodes, 538169 blocks
26908 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=553648128
17 block groups
32768 blocks per group, 32768 fragments per group
15840 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912

Writing inode tables: done                           
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

哦,特别要注意:
/home 是挂在/dev/sda5 上的,如果把它删了,就不能启动了:
[root@sheng ~]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2              3960348   3893912         0 100% /
/dev/sda5              2085172    228292   1749248  12% /home
/dev/sda1                46633     10516     33709  24% /boot
tmpfs                   263624         0    263624   0% /dev/shm

可以考虑 删除 /sda3, sda4
还有如果 后面的类型是 extend 类型,海还是不能改成 lvm 的要把它测定删除再 建
还有要注意的是: 不能见 sda3 的,因为其在/fstab 中已经定义为swap 的类型了。

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shenghuiping2001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值