歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> VMware虛擬機RedHat 4增加根目錄的磁盤空間

VMware虛擬機RedHat 4增加根目錄的磁盤空間

日期:2017/2/28 16:06:17   编辑:Linux教程

RedHat4下裝了Oracle,空間不夠用了,在網上找了半天終於搞定

第一步:編輯vm的磁盤大小



選擇磁盤編輯想改變的大小。

第二步:使用Linux下的fdisk工具進行分區

用root用戶登錄:

打印當前的磁盤分區表,這時我們可以看到磁盤的總量的確增加到30GB 了,但是分區只有以前的那幾個原有的分區
[root@localhost ~]# fdisk -l


鍵入命令: fdisk /dev/sda “sda 就是經過擴容的硬盤,為 SCSI 硬盤, IDE 類型硬盤對應為 hda ,是對該硬盤進行操作 ”

選擇主分區吧,則鍵入 p

此時, fdisk 會讓你選擇主分區的編號,如果已經有了主分區 sda1 , sda2 ,那麼編號就選3 ,即要創建的該分區為 sda3.
鍵入: 3

此時, fdisk 又會讓你選擇該分區的開始值這個就是分區的 Start 值( start cylinder );這裡最好直接按回車, 如果您輸入了一個非默認的數字,可能會造成空間浪費;

對於分區的 End 值(end cylinder),同樣直接按回車。這時候會顯示出你新建分區的柱面范圍和空間大小。

此時鍵入: w 表示" 保存所有並退出,分區劃分完畢 "

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


The number of cylinders for this disk is set to 3916.
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
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1045-3916, default 1045):
Using default value 1045
Last cylinder or +size or +sizeM or +sizeK (1045-3916, default 3916):
Using default value 3916


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.
Syncing disks.


我們的新建分區/dev/sda3,卻不是LVM的。所以,接下來使用fdisk將其改成LVM的。

[root@CNGI-SIP6-BUPT ~]# fdisk /dev/sda
Command (m for help): m
Command (m for help): t //改變分區系統id
Partition number (1-4): 3 //指定分區號
Hex code (type L to list codes): 8e //指定要改成的id號,8e代表LVM。
Command (m for help): w

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


The number of cylinders for this disk is set to 3916.
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): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
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.
Syncing disks.


重新登錄後:
[root@localhost ~]# reboot


Broadcast message from root (pts/1) (Thu Sep 22 09:54:45 2011):


The system is going down for reboot NOW!

[root@localhost ~]# fdisk -l


Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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 1044 8281507+ 8e Linux LVM
/dev/sda3 1045 3916 23069340 8e Linux LVM


Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


Device Boot Start End Blocks Id System
/dev/sdb1 1 783 6289416 83 Linux


第三步、格式化該新添加的分區

格式化磁盤
[root@localhost ~]# mkfs -t ext3 /dev/sda3
mke2fs 1.35 (28-Feb-2004)
max_blocks 4294967295, rsv_groups = 0, rsv_gdb = 1024
max_blocks 4294967295, rsv_groups = 0, rsv_gdb = 1024
warning: 167 blocks unused.


Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2889216 inodes, 5767168 blocks
288366 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=8388608
176 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
inode.i_blocks = 90120, i_size = 4243456
Creating journal (8192 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.

第四步、擴充根分區
[root@localhost ~]# lvs
LV VG Attr LSize Origin Snap% Move Copy%
LogVol00 VolGroup00 -wi-ao 5.91G
LogVol01 VolGroup00 -wi-ao 1.94G
[root@localhost ~]# pvcreate /dev/sd
sda sda1 sda2 sda3 sdb sdb1
[root@localhost ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
[root@localhost ~]# df -h
Filesystem 容量 已用 可用 已用% 掛載點
/dev/mapper/VolGroup00-LogVol00
5.9G 5.5G 120M 98% /
/dev/sda1 99M 9.0M 85M 10% /boot
none 506M 0 506M 0% /dev/shm
/dev/sdb1 6.0G 347M 5.3G 7% /disk2


[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 7.88 GB
PE Size 32.00 MB
Total PE 252
Alloc PE / Size 251 / 7.84 GB
Free PE / Size 1 / 32.00 MB
VG UUID HvKxmm-WazL-TjFN-yXNH-ui8U-pcl9-Pk6psB

[root@localhost ~]# vgextend VolGroup00 /dev/sda3
Volume group "VolGroup00" successfully extended
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 29.88 GB
PE Size 32.00 MB
Total PE 956
Alloc PE / Size 251 / 7.84 GB
Free PE / Size 705 / 22.03 GB
VG UUID HvKxmm-WazL-TjFN-yXNH-ui8U-pcl9-Pk6psB

#不能把 Free PE / Size 705 / 22.03 GB的空間全部加上,應該下雨22.03


[root@localhost ~]# lvextend -L+22.03G /dev/VolGroup00/LogVol00 /dev/sda3
Rounding up size to full physical extent 22.03 GB
Extending logical volume LogVol00 to 27.94 GB
Insufficient allocatable logical extents (893) for logical volume LogVol00: 894 required


[root@localhost ~]# lvextend -L+21.03G /dev/VolGroup00/LogVol00 /dev/sda3
Rounding up size to full physical extent 21.03 GB
Extending logical volume LogVol00 to 26.94 GB
Logical volume LogVol00 successfully resized


[root@localhost ~]# cat /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
/dev/sdb1 /disk2 ext3 defaults 1 1
/dev/hdc /media/cdrom auto pamconsole,exec,noauto,managed 0 0
/dev/fd0 /media/floppy auto pamconsole,exec,noauto,managed 0 0


[root@localhost ~]# e2fsck -a /dev/VolGroup00/LogVol00
/dev/VolGroup00/LogVol00 is mounted.


WARNING!!! Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.


Do you really want to continue (y/n)? yes


/dev/VolGroup00/LogVol00: recovering journal
/dev/VolGroup00/LogVol00: Clearing orphaned inode 596983 (uid=501, gid=501, mode=0100660, size=0)
/dev/VolGroup00/LogVol00: clean, 144094/774144 files, 1440278/1548288 blocks


#redhat4 沒有resize2fs命令
[root@localhost ~]# resize2fs
-bash: resize2fs: command not found

#redhat4下用ext2online
[root@localhost ~]# ext2online /dev/VolGroup00/LogVol00
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b
[root@localhost ~]# df -h
Filesystem 容量 已用 可用 已用% 掛載點
/dev/mapper/VolGroup00-LogVol00
27G 5.5G 20G 22% /
/dev/sda1 99M 9.0M 85M 10% /boot
none 506M 0 506M 0% /dev/shm
/dev/sdb1 6.0G 347M 5.3G 7% /disk2

現在大公告成

Copyright © Linux教程網 All Rights Reserved