guodanhuai的个人博客分享 http://blog.sciencenet.cn/u/guodanhuai GIS,Spatio-temporal Analysis,Spatio-temoporal Data minig

博文

如何修改Linux的主分区的空间

已有 4871 次阅读 2009-8-1 11:29 |个人分类:Technology|系统分类:科研笔记| Linux, 修改, 主分区

 
如何修改Linux的主分区的空间
 
今日在学习Linux的时候,由于使用的是虚拟机,所以硬盘空间较小,在软件安装是比较麻烦(虽然可以将软件安装在指定的地址,但软件安装时需要将文件解压缩和make时产生大量的临时文件),所以,继续扩充,由于本人不是虚拟机管理员,又不好意思老是麻烦别人,所以,就自己将另加的一块盘加到主分区中,在网友“小宝”的帮助指导下,成功完成,贴出此文,为帮助有同样需要的朋友,也对小宝表示感谢!其中叙述有不规范和不全之处,请读者自行查阅资料。
 
 
 
l  第一步,给虚拟机加个硬盘
这个可以向管理员提出,或自行解决,
 
 
 
l  第二步,分区
[root@centos64 ~]# fdisk /dev/sdb
 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
 
Building a new DOS disklabel. Changes will remain in memory only,
 
until you decide to write them. After that, of course, the previous
 
content won't be recoverable.
 
 
 
 
 
The number of cylinders for this disk is set to 1958.
 
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)
 
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
 
 
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): 1
 
First cylinder (1-1958, default 1):
 
Using default value 1
 
Last cylinder or +size or +sizeM or +sizeK (1-1958, default 1958):
 
Using default value 1958
 
 
 
Command (m for help): w
 
The partition table has been altered!
 
 
 
Calling ioctl() to re-read partition table.
 
Syncing disks.
 
 
 
结束后,用df查看
 
[root@centos64 ~]# df
 
Filesystem           1K-blocks      Used Available Use% Mounted on
 
/dev/mapper/VolGroup00-LogVol00
 
                       4031168   3688700    134392  97% /
 
/dev/sda1               101086     12495     83372  14% /boot
 
tmpfs                  1029816         0   1029816   0% /dev/shm
 
 
 
没有发现sdb,不要进行格式化,格式化后分区表又没了,我就上了这个当
 
 
 
用fdisk –l可以看见
 
[root@centos64 ~]# fdisk -l
 
 
 
Disk /dev/sda: 8589 MB, 8589934592 bytes
 
255 heads, 63 sectors/track, 1044 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
 
 
 
Disk /dev/sdb: 16.1 GB, 16106127360 bytes
 
255 heads, 63 sectors/track, 1958 cylinders
 
Units = cylinders of 16065 * 512 = 8225280 bytes
 
 
 
   Device Boot      Start         End      Blocks   Id  System
 
/dev/sdb1               1        1958    15727603+  83  Linux
 
 
 
 
 
l  第三步,将分区指定为pv
 
 
[root@centos64 ~]# pvcreate  --help
 
  pvcreate: Initialize physical volume(s) for use by LVM
 
 
 
pvcreate
 
        [--restorefile file]
 
        [-d|--debug]
 
        [-f[f]|--force [--force]]
 
        [-h|-?|--help]
 
        [--labelsector sector]
 
        [-M|--metadatatype 1|2]
 
        [--metadatacopies #copies]
 
        [--metadatasize MetadataSize[kKmMgGtTpPeE]]
 
        [--setphysicalvolumesize PhysicalVolumeSize[kKmMgGtTpPeE]
 
        [-t|--test]
 
        [-u|--uuid uuid]
 
        [-v|--verbose]
 
        [-y|--yes]
 
        [-Z|--zero {y|n}]
 
        [--version]
 
        PhysicalVolume [PhysicalVolume...]
 
 
 
[root@centos64 ~]# pvcreate  /dev/sdb
 
  Device /dev/sdb not found (or ignored by filtering).
 
[root@centos64 ~]# pvcreate  /dev/sdb1
 
  Physical volume "/dev/sdb1" successfully created
 
 
 
l  第三步vgextend
添加分区组
 
[root@centos64 ~]# vgextend --help
 
  vgextend: Add physical volumes to a volume group
 
 
 
vgextend
 
        [-A|--autobackup y|n]
 
        [-d|--debug]
 
        [-h|--help]
 
        [-t|--test]
 
        [-v|--verbose]
 
        [--version]
 
        VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
 
这时关键要查到 VolumeGroupName PhysicalDevicePath这两个名称
 
可用vgdisplay查看
 
[root@centos64 ~]# 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       252 / 7.88 GB
 
  Free  PE / Size       0 / 0  
 
  VG UUID               PqvyQ3-4JXx-PGCc-9H2q-7BcJ-HW7N-xHZeNP
 
所以,执行如下命令:
 
[root@centos64 ~]# vgextend VolGroup00 /dev/sdb1
 
  Volume group "VolGroup00" successfully extended
 
 
 
 
 
l  第四步lvextend
扩展分区组
 
[root@centos64 ~]# lvextend --help
 
  lvextend: Add space to a logical volume
 
 
 
lvextend
 
        [-A|--autobackup y|n]
 
        [--alloc AllocationPolicy]
 
        [-d|--debug]
 
        [-f|--force]
 
        [-h|--help]
 
        [-i|--stripes Stripes [-I|--stripesize StripeSize]]
 
        {-l|--extents [+]LogicalExtentsNumber[%{VG|PVS|FREE}] |
 
         -L|--size [+]LogicalVolumeSize[kKmMgGtTpPeE]}
 
        [-m|--mirrors Mirrors]
 
        [-n|--nofsck]
 
        [-r|--resizefs]
 
        [-t|--test]
 
        [--type VolumeType]
 
        [-v|--verbose]
 
        [--version]
 
        LogicalVolume[Path] [ PhysicalVolumePath... ]
 
后执行
 
[root@centos64 ~]# lvextend -l 1000000 /dev/VolGroup00/LogVol00
 
  Extending logical volume LogVol00 to 30.52 TB
 
  Insufficient free space: 999873 extents needed, but only 479 available
 
这里比较容易出错的是 是logicalVolum的名称容易输成VolGroup00LogVol00,logicalnumber的单位应该是簇,也不要估计,如果你想把整个分区都加上去,数个天文数字吧,系统会告诉你最大数应该是多少
 
 
 
l  最后一步resize2fs lvm卷名
[root@centos64 ~]# 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 3923968 (4k) blocks.
 
The filesystem on /dev/VolGroup00/LogVol00 is now 3923968 blocks long.
 
最后用df查一下,呵呵,大了吧
 
 
 
[root@centos64 ~]# df
 
Filesystem           1K-blocks      Used Available Use% Mounted on
 
/dev/mapper/VolGroup00-LogVol00
 
                      15207152   3690736  10733404  26% /
 
/dev/sda1               101086     12495     83372  14% /boot
 
tmpfs                  1029816         0   1029816   0% /dev/shm
 
 
 
再次感谢网友小宝的帮助。
 
 
 
【Reference】
 
Normal07.8 磅02falsefalsefalseEN-USZH-CNX-NONE/* Style Definitions */table.MsoNormalTable{mso-style-name:普通表格;mso-tstyle-rowband-size:0;mso-tstyle-colband-size:0;mso-style-noshow:yes;mso-style-priority:99;mso-style-qformat:yes;mso-style-parent:"";mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-para-margin-top:0cm;mso-para-margin-right:0cm;mso-para-margin-bottom:10.0pt;mso-para-margin-left:0cm;line-height:115%;mso-pagination:widow-orphan;font-size:11.0pt;font-family:"Calibri","sans-serif";mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin;mso-fareast-language:EN-US;mso-bidi-language:EN-US;}
 
许杜村 (2003). Red Hat Linux 9中文版入门与进阶. 北京, 清华大学出版社.
 
 
 


https://blog.sciencenet.cn/blog-204718-246835.html

上一篇:Linux入门(六)
下一篇:PostgreSQL学习
收藏 IP: .*| 热度|

0

发表评论 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-21 23:16

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部