linux系统增加磁盘空间
2011-04-12 15:54
369 查看
前段时间在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)。
解决办法:
使用sudo fdisk /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
--- 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
--- 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
需要使用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
至此,磁盘空间的扩展工作完毕。
另,更改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常用命令:
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
重启后 ,使用fdisk -l能够看到/dev/sda的空间已经增加了,但仍还是原来的两个磁盘/dev/sda1和/dev/sda2 (LVM)。在LVM逻辑卷管理其中仍是原来的10G空间,但在“未初始化的实例”中可以看到增加的3G未初始化的磁盘实例(unpartitioned space on /dev/sda)。
解决办法:
使用sudo fdisk /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
--- 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
--- 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
需要使用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
至此,磁盘空间的扩展工作完毕。
另,更改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常用命令:
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
相关文章推荐
- (转)虚拟机环境中linux系统增加磁盘空间
- vmware6 下为linux系统增加磁盘空间
- 解决linux系统下分区文件占用总空间比实际分区总容量要小却提示磁盘空间已满的问题
- 修改Linux内核增加系统调用(转载)
- Linux学习笔记——例说makefile 增加系统共享库
- 增加Linux系统调用——通过重新编译内核
- zz修改Linux内核增加系统调用
- Linux下如何增加一个系统用户
- Lab4_1树莓派上增加一个Linux系统调用
- linux安装系统后增加物理内存swap
- VMware下LINUX的虚拟机增加磁盘空间
- linux系统增加swap分区大小
- Linux下增加磁盘空间
- 增加linux service 系统服务
- Linux(AT91SAM9260)增加UBIFS文件系统支持
- Linux系统--查看磁盘空间
- VMware中虚拟的linux系统空间不足增加硬盘的办法
- 使用VMware workstation 7.1,增加Red hat linux虚拟机磁盘空间
- HP DL380 G4 磁盘阵列增加新硬盘(Linux系统)
- linux采用编译内核的方法增加系统功能调用