linux给磁盘扩容yast,虚拟机环境中linux系统增加磁盘空间

虚拟机环境中linux系统增加磁盘空间

前段时间在vmware ESXi虚拟化环境中安装了一套turbolinux系统,当时并没有在意磁盘如何规划,使用了LVM,心想反正能够随时扩展。不料时间不长,问题出现了,分配的磁盘空间满了。以为能够象windows Server环境中使用磁盘管理增加动态磁盘那样方便呢,就随意在ESX管理器中将原有的磁盘从10G增加到了13G,重启挂载LVM没有左右,重启系统了。

重启后 ,使用fdisk -l能够看到/dev/sda的空间已经增加了,但仍还是原来的两个磁盘/dev/sda1和/dev/sda2 (LVM)。在LVM逻辑卷管理其中仍是原来的10G空间,但在“未初始化的实例”中可以看到增加的3G未初始化的磁盘实例(unpartitioned space on /dev/sda)。

解决办法:    (用yast的paration)

使用sfdisk /dev/sda 命令,选择n (add a new partition),然后选择p (primary partition ),选择一个磁盘号,随后系统会自动提示选择起始块和最后的块。使用p(print the partion table)查看磁盘是否已经增加:

Disk /dev/sda: 13.9 GB, 13958643712 bytes

255 heads, 63 sectors/track, 1697 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          13      104391   83  Linux

/dev/sda2              14        1305    10377990   8e  Linux LVM

/dev/sda3            1306        1697     3148740   83  Linux

可以看到/dev/sda3的 id是83,这样的磁盘无法加入到lvm中,选择t(change a partition's system id),键入8e (Linux LVM 的id)。

最后,w保存退出。再使用sfsik -l即可看到新增的磁盘。

此时,使用lvm的初始化磁盘工具或者直接使用pvcreate /dev/sda3命令会提示出错,提示

Device “/dev/sda3” not found (or ignored by filtering)

出错的原因在于使用fdisk修改配置时没有在runlevel 1下进行,重启系统后可解决此问题。

[root@turbolinux ~]# fdisk -l

Disk /dev/sda: 13.9 GB, 13958643712 bytes

255 heads, 63 sectors/track, 1697 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          13      104391   83  Linux

/dev/sda2              14        1305    10377990   8e  Linux LVM

/dev/sda3            1306        1697     3148740   8e  Linux LVM

[root@turbolinux ~]# pvcreate /dev/sda3

Physical volume "/dev/sda3" successfully created

[root@turbolinux ~]# lvm

lvm> pvscan

PV /dev/sda2   VG VolGroup00      lvm2 [9.88 GB / 640.00 MB free]

PV /dev/sda3                      lvm2 [3.00 GB]

Total: 2 [12.88 GB] / in use: 1 [9.88 GB] / in no VG: 1 [3.00 GB]

lvm> vgextend VolGroup00 /dev/sda3

Volume group "VolGroup00" successfully extended

lvm>  lvdisplay  www.2cto.com

--- Logical volume ---

LV Name                /dev/VolGroup00/LogVol00

VG Name                VolGroup00

LV UUID                9tKx5o-7wgM-0BhF-OMqy-EY14-ttbL-30j1px

LV Write Access        read/write

LV Status              available

# open                 1

LV Size                7.25 GB

Current LE             232

Segments               2

Allocation             inherit

Read ahead sectors     auto

- currently set to     256

Block device           253:0

lvm>  lvextend

Please specify either size or extents but not both.

lvm> lvextend -L+2G /dev/VolGroup00/LogVol00

Extending logical volume LogVol00 to 9.25 GB

Logical volume LogVol00 successfully resized

lvm> lvdisplay  www.2cto.com

--- Logical volume ---

LV Name                /dev/VolGroup00/LogVol00

VG Name                VolGroup00

LV UUID                9tKx5o-7wgM-0BhF-OMqy-EY14-ttbL-30j1px

LV Write Access        read/write

LV Status              available

# open                 1

LV Size                9.25 GB

Current LE             296

Segments               3

Allocation             inherit

Read ahead sectors     auto

- currently set to     256

Block device           253:0

逻辑卷的大小已经更改到9.23G了,但文件系统仍没有增加:

[root@turbolinux ~]# df

文件系统               1K-块        已用     可用 已用% 挂载点

/dev/mapper/VolGroup00-LogVol00

7364072   5140148   1843844  74% /

/dev/sda1               101086     25946     69921  28% /boot

tmpfs                  2073968         0   2073968   0% /dev/shm

www.2cto.com

需要使用resize2fs命令将文件系统扩展到增加的空间上:

[root@turbolinux ~]# resize2fs /dev/VolGroup00/LogVol00

resize2fs 1.39 (29-May-2006)

Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required

Performing an on-line resize of /dev/VolGroup00/LogVol00 to 2424832 (4k) blocks.

The filesystem on /dev/VolGroup00/LogVol00 is now 2424832 blocks long.

[root@turbolinux ~]# df -m

文件系统               1M-块        已用     可用 已用% 挂载点

/dev/mapper/VolGroup00-LogVol00

9176      5020      3683  58% /

/dev/sda1                   99        26        69  28% /boot

tmpfs                     2026         0      2026   0% /dev/shm

[root@turbolinux ~]# df

文件系统               1K-块        已用     可用 已用% 挂载点

/dev/mapper/VolGroup00-LogVol00

9395560   5140156   3770492  58% /

/dev/sda1               101086     25946     69921  28% /boot

tmpfs                  2073968         0   2073968   0% /dev/shm

至此,磁盘空间的扩展工作完毕。

www.2cto.com

另,更改swap空间的内容如下:

默认安装时,不知为何,将swap的空间定为了5G,感觉没有必要这么大,需减少一点,因为swap在VolGroup00中,所以调整大小非常方便,

具体操作如下:

关闭swap先

# swapoff -v /dev/VolGroup00/LogVol01

# lvm lvreduce /dev/VolGroup00/LogVol01 -L -1G

# mkswap /dev/VolGroup00/LogVol01

重新打开swap

# swapon -va

swap常用命令:

www.2cto.com

cat /proc/swaps

swapon -s

调整swap大小:

dd if=/dev/zero of=swapfree bs=32k count=8192  (256MB)

mkswap swapfree

swapon /tmp/swapfree

停止:

swapoff /tmp/swapfree

启动时加载:

在/etc/fstab文件中,加入下行:

/tmp/swapfree swap swap defaults 0 0

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值