linux lvm增大 根目录,linux增多根目录的磁盘空间(LVM)

linux增加根目录的磁盘空间(LVM)

第一步:添加磁盘

第二步:使用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/sdaCommand (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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值