设为首页 收藏本站
查看: 653|回复: 0

[经验分享] linux增加根目录的磁盘空间(LVM)

[复制链接]

尚未签到

发表于 2016-3-14 08:56:31 | 显示全部楼层 |阅读模式
  
  第一步:添加磁盘
  第二步:使用Linux下的fdisk工具进行分区
  
  
  用root用户登录:
  打印当前的磁盘分区表,这时我们可以看到磁盘的总量的确增加到30GB 了,但是分区只有以前的那几个原有的分区
[iyunv@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    表示" 保存所有并退出,分区划分完毕 "
  [iyunv@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的。
  [iyunv@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
  [iyunv@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.
  
  重新登录后:
[iyunv@localhost ~]# reboot


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


The system is going down for reboot NOW!

[iyunv@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
  
第三步、格式化该新添加的分区
  格式化磁盘 
[iyunv@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.
  
  第四步、扩充根分区
[iyunv@localhost ~]# lvs
  LV       VG         Attr   LSize Origin Snap%  Move Copy% 
  LogVol00 VolGroup00 -wi-ao 5.91G                          
  LogVol01 VolGroup00 -wi-ao 1.94G                          
[iyunv@localhost ~]# pvcreate /dev/sd
sda   sda1  sda2  sda3  sdb   sdb1  
[iyunv@localhost ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
[iyunv@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


[iyunv@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

[iyunv@localhost ~]# vgextend VolGroup00 /dev/sda3
  Volume group "VolGroup00" successfully extended
[iyunv@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
  
[iyunv@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
  
[iyunv@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
  
[iyunv@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


[iyunv@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命令
[iyunv@localhost ~]# resize2fs
-bash: resize2fs: command not found
  #redhat4下用ext2online 
[iyunv@localhost ~]# ext2online /dev/VolGroup00/LogVol00 
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b
[iyunv@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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-190478-1-1.html 上篇帖子: Linux命令中正则表达式的运用 下篇帖子: 揭开Linux操作系统的Swap交换区之谜
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表