zoukankan      html  css  js  c++  java
  • CentOS 6.3 卷组挂载硬盘教程 linux的VPS如何分区

    XEN架构VPS提供的容量一般都不会低于10G,但大部分基于Xensystem面板的VPS默认挂载10G硬盘(第一磁盘),剩下的容量(第二磁盘)就需要通过手动挂载才能扩充默认的10G容量了。
    默认装完系统只装载了10G,如果你购买了更多需要自行挂载才可以。需要使用ROOT登陆SSH进行操作,使用PUTTY 或XSHELL 之类软件,或面板的VNC控制也可以。

    挂载建议在系统全新的系统下操作,如系统已经有数据建议先完整备份,以防挂载出现失误导致数据丢失。

    一、查看当前硬盘情况

    fdisk -l

    如下图:

    其中,“Disk /dev/xvdb: 21.5 GB”表示第二虚拟硬盘有21.5GB容量,“/dev/mapper/vg_501153278-lv_root: 9135 MB”表示“/”当前分配有9135MB(在第一虚拟磁盘)。

    二、第二磁盘格式化为LVM分区
     

    把/dev/xvdb(第二磁盘)挂载并叠加容量到Linux系统“/”目录,需先将第二磁盘格式化为LVM分区

    fdisk /dev/xvdb

    SSH执行以上命令,然后操作如下:

    Command (m for help): n #新建分区

    Command action
       e   extended
       p   primary partition (1-4)
    p                                     #设置为主分区
    Partition number (1-4): 1             #主分区号
    First cylinder (1-2610, default 1):1  #开始扇区(直接默认回车)
    Using default value 1
    Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):2610 
    Using default value 2610              #结束扇区(直接默认回车)
    Command (m for help): t               #指定分区类型
    Selected partition 1                  #选择1号分区
    Hex code (type L to list codes): 8e   #8e为LVM
    Changed system type of partition 1 to 8e (Linux LVM)
    
    Command (m for help): w               #保存
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.

    三、查看卷组

    vgdisplay
     

    SSH执行以上命令,查看当前PV,并记录“VG Name”:vg_501153278,如下图。

    四、添加卷组

    1、将刚刚创建的LVM创建为PV

    pvcreate /dev/xvdb1

    SSH执行以上命令。

    2、添加卷组

    vgextend vg_501153278 /dev/xvdb1

    SSH执行以上命令,填入组名(Vg Name)和对应分驱号(/dev/xvdb1),回车执行。

    3、查看空闲卷组

    vgdisplay

    再次执行以上命令,记录“Free  PE / Size”里的值:5118。

    五、扩展磁盘

    1、扩展LV大小

    lvresize -l +5118 /dev/mapper/vg_501153278-lv_root
     

    SSH执行以上命令,将“+5118”替换为对应的“Free  PE / Size”里值,将“vg_501153278”替换为“VG Name”的名字。

    2、重设大小(使其生效)

    resize2fs /dev/mapper/vg_501153278-lv_root

    SSH执行以上命令,扩展格式化使其生效。如下图。

    写在最后:

    卷组挂载的原理是将两块盘通过卷组虚拟为1块硬盘,当第一块硬盘不够容量时,数据将直接写到第二硬盘。

    由于处于数据保护机制,我们都会给客户准备2块硬盘,一块用来存放用户数据,一块用来存放系统,这样在后台选择重做系统之后,另外一个磁盘分区的数据就不会丢失了..所以在购买VPS之后,要手动将另外一块硬盘激活,于是乎,就有了这个如何启用分区的教程:
    通过fdisk -l我们可以看到/dev/xvdb(此名称因系统而异)容量有23.6G,
    而且没有分区,接下来我们对它进行分区和挂载

    1.fdisk -l
    01.[root@MyVPS ~]# fdisk -l
    02.Disk /dev/xvda: 8589 MB, 8589934592 bytes
    03.255 heads, 63 sectors/track, 1044 cylinders
    04.Units = cylinders of 16065 * 512 = 8225280 bytes
    05.Device Boot      Start         End      Blocks   Id  System
    06./dev/xvda1   *           1          13      104391   83  Linux
    07./dev/xvda2              14        1044     8281507+  8e  Linux LVM
    08. 
    09.Disk /dev/xvdb: 23.6 GB, 23622320128 bytes
    10.255 heads, 63 sectors/track, 2871 cylinders
    11.Units = cylinders of 16065 * 512 = 8225280 bytes
    12.Device Boot      Start         End      Blocks   Id  System

    对/dev/xvdb(此名称因系统而异)进行分区:

    1.fdisk /dev/xvdb
    01.[root@MyVPS ~]# fdisk /dev/xvdb
    02.The number of cylinders for this disk is set to 2871.
    03.There is nothing wrong with that, but this is larger than 1024,
    04.and could in certain setups cause problems with:
    05.1) software that runs at boot time (e.g., old versions of LILO)
    06.2) booting and partitioning software from other OSs
    07.(e.g., DOS FDISK, OS/2 FDISK)
    08. 
    09.输入n新建分区
    10.Command (m for help): n
    11.Command action
    12.e   extended
    13.p   primary partition (1-4)
    14.p
    15. 
    16./dev/xvdb中第1个分区
    17.Partition number (1-4): 1
    18.First cylinder (1-2871, default 1):
    19.Using default value 1
    20.Last cylinder or +size or +sizeM or +sizeK (1-2871, default 2871):
    21.Using default value 2871
    22. 
    23.输入W保存退出
    24.Command (m for help): w
    25.The partition table has been altered!
    26.Calling ioctl() to re-read partition table.
    27.Syncing disks.


    将新分区xvdb1(此名称因系统而异)格式化为ext3格式

    1.mkfs -t ext3 /dev/xvdb1
    01.[root@MyVPS ~]# mkfs -t ext3 /dev/xvdb1
    02.mke2fs 1.39 (29-May-2006)
    03.Filesystem label=
    04.OS type: Linux
    05.Block size=4096 (log=2)
    06.Fragment size=4096 (log=2)
    07.2883584 inodes, 5765319 blocks
    08.288265 blocks (5.00%) reserved for the super user
    09.First data block=0
    10.Maximum filesystem blocks=4294967296
    11.176 block groups
    12.32768 blocks per group, 32768 fragments per group
    13.16384 inodes per group
    14.Superblock backups stored on blocks:
    15.32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    16.4096000
    17.Writing inode tables: done
    18.Creating journal (32768 blocks): done
    19.Writing superblocks and filesystem accounting information: done
    20.This filesystem will be automatically checked every 24 mounts or
    21.180 days, whichever comes first.  Use tune2fs -c or -i to override.


    我们示范将新分区xvdb1挂载到目录/home
    因为home已经存在,所以我们挂载
    mount /dev/xvdb1 /home
    如果你需要挂载在别的目录.可以新建一个目录挂载.如:home1,使用如下命令:

    1.mkdir /home1
    2.mount /dev/xvdb1 /home1


    完成后我们通过df -hal可以看到,新分区已经挂载到目录/home上了

    01.[root@MyVPS ~]# df -hal
    02.Filesystem            Size  Used Avail Use% Mounted on
    03./dev/mapper/VolGroup00-LogVol00
    04.5.7G  1.4G  4.1G  25% /
    05.proc                     0     0     0   -  /proc
    06.sysfs                    0     0     0   -  /sys
    07.devpts                   0     0     0   -  /dev/pts
    08./dev/xvda1             99M   28M   67M  30% /boot
    09.tmpfs                 256M     0  256M   0% /dev/shm
    10.none                     0     0     0   -  /proc/sys/fs/binfmt_misc
    11.sunrpc                   0     0     0   -  /var/lib/nfs/rpc_pipefs
    12./dev/xvdb1             22G  173M   21G   1% /home


    最后添加开机自动挂载:

    1.echo "/dev/xvdb1 /home ext3 defaults 1 2" >> /etc/fstab


    这样就完成了!
    通过后台控制系统重做系统之后,只需要重新挂载一次即可

    1.mount /dev/xvdb1 /home


    最后,重新添加自动挂载即可:

    1.echo "/dev/xvdb1 /home ext3 defaults 1 2" >> /etc/fstab
  • 相关阅读:
    C语言指针
    Windows环境下 PHP+Apache+Mysql配置
    游戏贴图中常用术语《DC》的理解
    C# winform程序如何打包64位安装程序
    C# winform中的datagridview控件标头加入checkbox,实现全选功能。
    C# WinForm控件之Dock顺序调整
    关于struts2.0 中 struts.xml设置了struts.devMode 的值为TRUE后仍然不起作用的分析
    Java Web项目 配置 ueditor心得
    关于VS中文件属性的解释
    使用Ueditor的心得。
  • 原文地址:https://www.cnblogs.com/guke/p/3156678.html
Copyright © 2011-2022 走看看