• linux使用lvm分区


    lvm分区

    试验环境 centos 6.5

    借图如下

    一、LVM原理
    传统文件系统,比如这个盘只有300G,那么建立在这个300G上面的文件系统最多只能用到300G,但是有了LVM这个功能后,我们建立文件系统的盘就不是建立在物理盘上,而是建立在一个叫LV逻辑卷上面,这个卷是一个逻辑概念不是物理盘,空间可能大于一个物理盘,也可能小于一个物理盘。而且这个LV逻辑卷的空间可以扩展和缩小,这样就给上层的文件系统提供了更好的支持。
    需要理解的几个概念:
    PV(Physical Volume):物理空间的意思,其实就是指一个分区(如/dev/sdb1 )或者是一个盘(如/dev/sdb)
    VG(Volume Group):相当于一个Pool,由多个PV组成的pool
    LV(Logical Volume):用来建立一个文件系统的空间,这个空间来源于VG,大小随意,可以扩展。(比如/dev/mapper/rhel-root这个目录其实是一个文件系统挂载点,这个点就是承载在一个LV上,这个文件系统的大小就是这个LV的大小。 )

     二、实际操作

    1、使用fdisk -l查看磁盘情况,可以看到我有两块未分区的磁盘,分别是/dev/sdb /dev/sdc,我们先用一块磁盘/dev/sdb进行测试。

    [root@test_iptables ~]# fdisk -l
    
    Disk /dev/sdb: 1073 MB, 1073741824 bytes
    255 heads, 63 sectors/track, 130 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    
    
    Disk /dev/sda: 21.5 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0005b552
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          39      307200   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              39        2350    18566144   83  Linux
    /dev/sda3            2350        2611     2097152   82  Linux swap / Solaris
    
    Disk /dev/sdc: 1073 MB, 1073741824 bytes
    255 heads, 63 sectors/track, 130 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000

    2、对/dev/sdb进行分区

    (1)先进行标准分区

    [root@test_iptables ~]# fdisk /dev/sdb
    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel with disk identifier 0x34c351e7.
    Changes will remain in memory only, until you decide to write them.
    After that, of course, the previous content won't be recoverable.
    
    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
    
    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
             switch off the mode (command 'c') and change display units to
             sectors (command 'u').
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First cylinder (1-130, default 1): 
    Using default value 1
    Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): 
    Using default value 130
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.

    (2)查看使用vgdisplay查看已经存在的卷组名称

    [root@test_iptables ~]# vgdisplay
      No volume groups found

    (3)开始进行lvm处理

    创建物理卷(PV)

    [root@test_iptables ~]# pvcreate /dev/sdb1 
      dev_is_mpath: failed to get device for 8:17
      Physical volume "/dev/sdb1" successfully created

    创建卷组(VG)

    [root@test_iptables ~]# vgcreate vg01 /dev/sdb1
      Volume group "vg01" successfully created

    查看创建的物理卷及卷组

     在卷组vg01上创建名为date,大小为1000M的逻辑卷

    [root@test_iptables ~]# lvcreate -L 1000M -n data vg01
      Logical volume "data" created

     3、格式化分区

    [root@test_iptables ~]# mkfs.ext4 /dev/vg01/data
    mke2fs 1.41.12 (17-May-2010)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    64000 inodes, 256000 blocks
    12800 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=264241152
    8 block groups
    32768 blocks per group, 32768 fragments per group
    8000 inodes per group
    Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376
    
    Writing inode tables: done                            
    Creating journal (4096 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 33 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.

    4、挂载分区

    [root@test_iptables ~]# mkdir /u01
    [root@test_iptables ~]# mount /dev/vg01/data /u01/
    [root@test_iptables ~]# df -h
    Filesystem             Size  Used Avail Use% Mounted on
    /dev/sda2               18G  9.2G  7.4G  56% /
    tmpfs                  931M   72K  931M   1% /dev/shm
    /dev/sda1              291M   39M  238M  14% /boot
    /dev/vg01/data  985M   18M  918M   2% /u01

    5、设置开机自动挂载

    [root@test_iptables ~]# cat /etc/fstab 
    
    #
    # /etc/fstab
    # Created by anaconda on Wed Sep 11 09:19:25 2019
    #
    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
    #
    UUID=fe5d2642-dc89-45a2-963a-2a5e0f7e5a3a /                       ext4    defaults        1 1
    UUID=e356222c-cde8-4f30-a38c-3fcf905b65c8 /boot                   ext4    defaults        1 2
    UUID=4d5bbee9-6557-4b6b-a275-4c43b14dce9d swap                    swap    defaults        0 0
    tmpfs                   /dev/shm                tmpfs   defaults        0 0
    devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
    sysfs                   /sys                    sysfs   defaults        0 0
    proc                    /proc                   proc    defaults        0 0
    /dev/vg01/data          /u01                    ext4    defaults        0 0

    至此,一个lvm分区设置完毕

    三、PV扩容

    1、首先进行标准分区

    root@test_iptables ~]# fdisk /dev/sdc
    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel with disk identifier 0x114bf00d.
    Changes will remain in memory only, until you decide to write them.
    After that, of course, the previous content won't be recoverable.
    
    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
    
    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
             switch off the mode (command 'c') and change display units to
             sectors (command 'u').
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First cylinder (1-130, default 1): 
    Using default value 1
    Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): 
    Using default value 130
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.

    2、创建物理卷

    [root@test_iptables ~]# pvcreate /dev/sdc1
      Physical volume "/dev/sdc1" successfully created

    3、VG扩容

    将新的物理卷加入卷组

    [root@test_iptables ~]# vgextend vg01 /dev/sdc1
      Volume group "vg01" successfully extended

    扩展逻辑卷 并resize2fs加载逻辑卷

    [root@test_iptables ~]# lvextend -l +100%FREE /dev/vg01/data
      Extending logical volume data to 1.98 GiB
      Logical volume data successfully resized
    [root@test_iptables ~]# resize2fs /dev/vg01/data
    resize2fs 1.41.12 (17-May-2010)
    Filesystem at /dev/vg01/data is mounted on /u01; on-line resizing required
    old desc_blocks = 1, new_desc_blocks = 1
    Performing an on-line resize of /dev/vg01/data to 520192 (4k) blocks.
    The filesystem on /dev/vg01/data is now 520192 blocks long.

    至此,以上就是整个流程,成功扩展为2G。

  • 相关阅读:
    .NET之权限管理
    .NET之带星期的日期显示
    ASP.net MVC 同一view或页面使用多个Model或数据集的方法
    ISBN号校检程序(C#与SQL版)
    ASP操作类似多维Cookies
    C# webBrowser自动登陆windows集成验证方法
    JOI 系列乱做
    NOI2021 部分题解
    「NEERC 2015」Jump 题解
    CF/AT 乱做
  • 原文地址:https://www.cnblogs.com/chxmtl/p/12752715.html
Copyright © 2020-2023  润新知