今天在Linux下通过sqlplus / as sysdba启动数据库时报以下错误:
ERROR:
ORA-09817: Write to audit file failed.
Linux-x86_64 Error: 28: No space left on device
ORA-09945: Unable to initialize the audit trail file
Linux-x86_64 Error: 28: No space left on device
经过检查发现原因是Linux的虚拟机根分区已经使用100%,以至于服务不能正常进行:
[oracle@etl110 ~]$ df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-lvm_root
16G 15G 0 100% /
/dev/mapper/VolGroup00-lv_home
2.0G 68M 1.8G 4% /home
/dev/sda1 99M 13M 82M 14% /boot
tmpfs 579M 0 579M 0% /dev/shm
考虑将虚拟机磁盘空间由20G扩大到40G,基于LVM操作,以下为操作过程:
第一步:使用VMware工具扩容分配的硬盘空间
1.vmware 提供一个命令行工具,在Windows下为vmware-vdiskmanager.exe 位于 vmware 的安装目录下,比如vmware-vdiskmanager.exe;
在Linux下有直接的vmware-vdiskmanager指令;
进行的操作:在 windows 下进入命令行窗口,转到 vmware 的安装目录,执行vmware-vdiskmanager.exe;在Linux下,直接
敲入vmware-vdiskmanager ,可执行该指令扩充使用的指令: vmware-vdiskmanager -x 40Gb vmdisk1.vmdk。
说明:要扩容的系统这时不能在运行 ,参数 "-x" 表示要扩展虚拟机硬盘空间,紧随其后的数字是要扩展到的大小 ,而非
增加量(本例为扩展到40GB,这是一个磁盘总量,包含了原先的磁盘容量)。最后是指定要操作的虚拟机磁盘的具体文件,要是
路径名中有空格,必须以双引号括起来。按回车键开始执行,执行完毕,退出命令提示符窗口,重启 VMware ,会发现虚拟机硬
盘空间已变成40GB了。
2.我们重启虚拟机后,发现虚拟机的硬盘是变成40GB,但进入 linux 系统后,用 "df -h"查看发现硬盘空间还是原先那么大。
虽然已经扩大了磁盘,但是由于还没有经过分区,指定文件系统,所以 linux 操作系统无法识别。其实就相当于你的硬盘虽然大了,
但是你并没有对其进行分区是一个道理。
第二步:使用Linux下的fdisk工具进行分区
首先,需要以root身份登录系统。
fdisk -l 命令打印当前的磁盘分区表:
[root@etl110 ~]# fdisk -l
Disk /dev/sda: 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/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
(1)键入命令:fdisk /dev/sda,sda就是经过扩容的硬盘,为 SCSI 硬盘, IDE 类型硬盘对应为 hda ,是对该硬盘进行操作;
(2)键入:m回车列出 fdisk 的帮助;
(3)键入:n回车用于添加新分区,此时, fdisk 会让你选择添加为逻辑分区呢(编号从 5 开始)还是主分区(编号 1 到 4 )
键入p选择主分区;键入l选择逻辑分区 ,此处我们键入p选择主分区,回车后此时fdisk会让你选择主分区的编号,如果已经有了
主分区sda1,sda2,那么编号就选3,即要创建的该分区为sda3,接下来fdisk 又会让你选择该分区的开始值就是分区的Start值以
及End值,直接回车选择默认值即可;最后键入w写入分区表,整个操作过程如下,后面带#号的为我加的注释,方便理解。
[root@etl110 ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 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)
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 #新建分区
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3 #创建id号为3的分区
First cylinder (2611-5221, default 2611): #直接回车,使用默认值
Using default value 2611
Last cylinder or +size or +sizeM or +sizeK (2611-5221, default 5221): #直接回车,使用默认值
Using default value 5221
Command (m for help): t #修改系统分区的id号
Partition number (1-4): 3 #指定要修改的分区id号
Hex code (type L to list codes): 8e #指定要改成的id号,8e代表LVM
Changed system type of partition 3 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: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
[root@etl110 ~]# reboot
重启系统后就可以在/dev/下看到sda3了
第三步:格式化该新添加的分区
键入命令:mkfs -t ext3 /dev/sda3,将/dev/sda3格式化为ext3格式,操作过程如下所示:
[root@etl110 ~]# mkfs -t ext3 /dev/sda3
mke2fs 1.39 (29-May-2006)
warning: 334 blocks unused.
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2626560 inodes, 5242880 blocks
262160 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
16416 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 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
到此为止,我们就新建了一个分区/dev/sda3,此时我们已经可以通过挂载来使用这个新的空间;但是,因为数据库是安装在
根目录上的,目前根目录空间已经使用完毕,所以能把新建的分区使用在更目录上,分担根目录的空间,才能解决问题。
第四步:基于LVM扩充根分区
[root@etl110 ~]# lvs
/dev/hdc: open failed: 找不到介质
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv_home VolGroup00 -wi-ao 2.00G
lvm_root VolGroup00 -wi-ao 15.59G
lvm_swap VolGroup00 -wi-ao 2.28G
[root@etl110 ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
[root@etl110 ~]# vgextend VolGroup00 /dev/sda3
/dev/hdc: open failed: 找不到介质
Volume group "VolGroup00" successfully extended
[root@etl110 ~]# vgdisplay
/dev/hdc: open failed: 找不到介质
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size 39.88 GB
PE Size 32.00 MB
Total PE 1276
Alloc PE / Size 636 / 19.88 GB
Free PE / Size 640 / 20.00 GB
VG UUID J7KBM7-dcwF-3SXr-WLlL-IJIg-LuNy-3rp0jg
主要查看Free PE / Size 640 / 20.00 GB,说明我们最多可以有20G的扩充空间。
最后,运行以下命令给根分区增加空间:
[root@etl110 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-lvm_root
16G 15G 0 100% /
/dev/mapper/VolGroup00-lv_home
2.0G 68M 1.8G 4% /home
/dev/sda1 99M 13M 82M 14% /boot
tmpfs 579M 0 579M 0% /dev/shm
[root@etl110 ~]# lvextend -L +20G /dev/mapper/VolGroup00-lvm_root /dev/sda3
/dev/hdc: open failed: 找不到介质
Extending logical volume lvm_root to 35.59 GB
Logical volume lvm_root successfully resized
[root@etl110 ~]# cat /etc/fstab
/dev/VolGroup00/lvm_root / ext3 defaults 1 1
/dev/VolGroup00/lv_home /home ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/VolGroup00/lvm_swap swap swap defaults 0 0
检查文件系统:e2fsck -f /dev/mapper/VolGroup00-lvm_root
然后,告诉系统,分割区大小有调整:resize2fs /dev/mapper/VolGroup00-lvm_root
[root@etl110 ~]# e2fsck -f /dev/mapper/VolGroup00-lvm_root
e2fsck 1.39 (29-May-2006)
/dev/mapper/VolGroup00-lvm_root is mounted.
WARNING!!! Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.
Do you really want to continue (y/n)? yes
/dev/mapper/VolGroup00-lvm_root: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/VolGroup00-lvm_root: ***** FILE SYSTEM WAS MODIFIED *****
/dev/mapper/VolGroup00-lvm_root: ***** REBOOT LINUX *****
/dev/mapper/VolGroup00-lvm_root: 225531/4088000 files (1.6% non-contiguous), 3897107/4087808 blocks
[root@etl110 ~]# resize2fs /dev/mapper/VolGroup00-lvm_root
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/VolGroup00-lvm_root is mounted on /; on-line resizing required
Performing an on-line resize of /dev/mapper/VolGroup00-lvm_root to 9330688 (4k) blocks.
The filesystem on /dev/mapper/VolGroup00-lvm_root is now 9330688 blocks long.
到此所有操作完毕,使用df -h来查看扩充后的空间大小:
[root@etl110 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-lvm_root
35G 15G 19G 44% /
/dev/mapper/VolGroup00-lv_home
2.0G 68M 1.8G 4% /home
/dev/sda1 99M 13M 82M 14% /boot
tmpfs 579M 0 579M 0% /dev/shm