zoukankan      html  css  js  c++  java
  • 逻辑卷建增删移

    创建逻辑卷:
     #用sdb1和sdd组合创建逻辑卷:
        [root@localhost ~]#lsblk
        NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
        sda      8:0    0  200G  0 disk
        ├─sda1   8:1    0    1G  0 part /boot
        ├─sda2   8:2    0  100G  0 part /
        ├─sda3   8:3    0   50G  0 part /data
        ├─sda4   8:4    0    1K  0 part
        └─sda5   8:5    0    4G  0 part [SWAP]
        sdb      8:16   0   20G  0 disk
        └─sdb1   8:17   0    8G  0 part
        sdc      8:32   0   30G  0 disk
        sdd      8:48   0    2G  0 disk
        sr0     11:0    1  6.7G  0 rom  /run/media/root/CentOS-8-BaseOS-x86_64
        1.在新的硬盘创建主分区
        [root@localhost ~]#fdisk /dev/sdb

        Welcome to fdisk (util-linux 2.32.1).
        Changes will remain in memory only, until you decide to write them.
        Be careful before using the write command.

        Device does not contain a recognized partition table.
        Created a new DOS disklabel with disk identifier 0x5b571c7b.

        Command (m for help): n
        Partition type
        p   primary (0 primary, 0 extended, 4 free)
        e   extended (container for logical partitions)
        Select (default p): p
        Partition number (1-4, default 1):
        First sector (2048-41943039, default 2048):
        Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +8G

        Created a new partition 1 of type 'Linux' and of size 8 GiB.

        Command (m for help): w
        The partition table has been altered.
        Calling ioctl() to re-read partition table.
        Syncing disks.

     2.修改新建分区类型:改正8eLVM逻辑卷管理器
        [root@localhost ~]#fdisk /dev/sdb

        Welcome to fdisk (util-linux 2.32.1).
        Changes will remain in memory only, until you decide to write them.
        Be careful before using the write command.

        Command (m for help): t
        Selected partition 1
        Hex code (type L to list all codes): l

        0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
        1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
        2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
        3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden or  c6  DRDOS/sec (FAT-
        4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
        5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
        6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
        7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
        8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
        9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
        a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
        b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
        c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi ea  Rufus alignment
        e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         eb  BeOS fs        
        f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ee  GPT            
        10  OPUS            55  EZ-Drive        a7  NeXTSTEP        ef  EFI (FAT-12/16/
        11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f0  Linux/PA-RISC b
        12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f1  SpeedStor      
        14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f4  SpeedStor      
        16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      f2  DOS secondary  
        17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fb  VMware VMFS    
        18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fc  VMware VMKCORE
        1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fd  Linux raid auto
        1c  Hidden W95 FAT3 75  PC/IX           bc  Acronis FAT32 L fe  LANstep        
        1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot    ff  BBT            
        Hex code (type L to list all codes): 8e
        Changed type of partition 'Linux' to 'Linux LVM'.

        Command (m for help): p
        Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
        Units: sectors of 1 * 512 = 512 bytes
        Sector size (logical/physical): 512 bytes / 512 bytes
        I/O size (minimum/optimal): 512 bytes / 512 bytes
        Disklabel type: dos
        Disk identifier: 0x5b571c7b

        Device     Boot Start      End  Sectors Size Id Type
        /dev/sdb1        2048 16779263 16777216   8G 8e Linux LVM

        Command (m for help): w
        The partition table has been altered.
        Syncing disks.

     3.查询修改结果:
        [root@localhost ~]#fdisk -l /dev/sdb
        Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
        Units: sectors of 1 * 512 = 512 bytes
        Sector size (logical/physical): 512 bytes / 512 bytes
        I/O size (minimum/optimal): 512 bytes / 512 bytes
        Disklabel type: dos
        Disk identifier: 0x5b571c7b

        Device     Boot Start      End  Sectors Size Id Type
        /dev/sdb1        2048 16779263 16777216   8G 8e Linux LVM

     4.查询当前是否有物理卷(2个命令皆可查):
        [root@localhost ~]#pvs
        [root@localhost ~]#pvdisplay

     5.创建物理卷:
        [root@localhost ~]#pvcreate /dev/sdb1 /dev/sdd
        Physical volume "/dev/sdb1" successfully created.
        Physical volume "/dev/sdd" successfully created.

     6.查询创建结果
        [root@localhost ~]#pvs
        PV         VG Fmt  Attr PSize PFree
        /dev/sdb1     lvm2 ---  8.00g 8.00g
        /dev/sdd      lvm2 ---  2.00g 2.00g

     7.查询逻辑卷组
        [root@localhost ~]#vgs

     8.创建逻辑卷组:设置PE大小,命名,物理卷组合(成员)
        [root@localhost ~]#vgcreate -s 16M vg0 /dev/sd{b1,d}
        Volume group "vg0" successfully created

     9.查询创建结果
        [root@localhost ~]#pvs
        PV         VG  Fmt  Attr PSize PFree
        /dev/sdb1  vg0 lvm2 a--  7.98g 7.98g
        /dev/sdd   vg0 lvm2 a--  1.98g 1.98g

     10.卷组信息
        [root@localhost ~]#pvdisplay
        --- Physical volume ---
        PV Name               /dev/sdb1
        VG Name               vg0
        PV Size               8.00 GiB / not usable 16.00 MiB
        Allocatable           yes
        PE Size               16.00 MiB
        Total PE              511
        Free PE               511
        Allocated PE          0
        PV UUID               BdyFU4-vdBF-Dnnl-5HN9-69xe-LPwt-9I30Yj
        
        --- Physical volume ---
        PV Name               /dev/sdd
        VG Name               vg0
        PV Size               2.00 GiB / not usable 16.00 MiB
        Allocatable           yes
        PE Size               16.00 MiB
        Total PE              127
        Free PE               127
        Allocated PE          0
        PV UUID               e798Og-LfUf-tFp4-nRhW-8nzf-snLV-OY0fRJ

     11.创建逻辑卷,命名,大小(不能超过物理卷总容量),那个卷组,
        [root@localhost ~]#lvcreate -n mysql -L 9G vg0
        Logical volume "mysql" created.
        [root@localhost ~]#lsblk
        NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
        sda             8:0    0  200G  0 disk
        ├─sda1          8:1    0    1G  0 part /boot
        ├─sda2          8:2    0  100G  0 part /
        ├─sda3          8:3    0   50G  0 part /data
        ├─sda4          8:4    0    1K  0 part
        └─sda5          8:5    0    4G  0 part [SWAP]
        sdb             8:16   0   20G  0 disk
        └─sdb1          8:17   0    8G  0 part
        └─vg0-mysql 253:0    0    9G  0 lvm  
        sdc             8:32   0   30G  0 disk
        sdd             8:48   0    2G  0 disk
        └─vg0-mysql   253:0    0    9G  0 lvm  
        sr0            11:0    1  6.7G  0 rom  /run/media/root/CentOS-8-BaseOS-x86_64

     12.查询逻辑卷组信息
        [root@localhost ~]#lvs
        LV    VG  Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
        mysql vg0 -wi-a----- 9.00g  

     13.创建文件系统:
       [root@localhost ~]#mkfs.ext4 /dev/vg0/mysql
       mke2fs 1.44.3 (10-July-2018)
       Creating filesystem with 2359296 4k blocks and 589824 inodes
       Filesystem UUID: 8ea3d17f-a1ff-4ba2-9175-84fc53d37739
       Superblock backups stored on blocks:
          32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

       Allocating group tables: done                            
       Writing inode tables: done                            
       Creating journal (16384 blocks): done
       Writing superblocks and filesystem accounting information: done

       [root@localhost ~]#blkid
       /dev/sda1: UUID="70654bd2-8b84-4718-86da-a46fc5534b4b" TYPE="ext4" PARTUUID="9a414237-01"
       /dev/sda2: UUID="df86e679-8d53-41a5-bd87-81d2b39fca58" TYPE="xfs" PARTUUID="9a414237-02"
       /dev/sda3: UUID="e734b75b-ce88-4daf-821f-7863e3b91e48" TYPE="xfs" PARTUUID="9a414237-03"
       /dev/sda5: UUID="039fbe3a-117b-4998-9d95-cfba038fe9f2" TYPE="swap" PARTUUID="9a414237-05"
       /dev/sr0: UUID="2019-08-15-21-52-52-00" LABEL="CentOS-8-BaseOS-x86_64" TYPE="iso9660" PTUUID="3e04f576" PTTYPE="dos"
       /dev/sdb1: UUID="BdyFU4-vdBF-Dnnl-5HN9-69xe-LPwt-9I30Yj" TYPE="LVM2_member" PARTUUID="5b571c7b-01"
       /dev/sdd: UUID="e798Og-LfUf-tFp4-nRhW-8nzf-snLV-OY0fRJ" TYPE="LVM2_member"
       /dev/mapper/vg0-mysql: UUID="8ea3d17f-a1ff-4ba2-9175-84fc53d37739" TYPE="ext4"

    挂载逻辑卷
       [root@localhost ~]#vim /etc/fstab
       # /etc/fstab
       # Created by anaconda on Sun Oct  6 00:18:58 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.
       #
       # After editing this file, run 'systemctl daemon-reload' to update systemd
       # units generated from this file.
       #
       UUID=df86e679-8d53-41a5-bd87-81d2b39fca58 /                       xfs     defaults        0 0
       UUID=70654bd2-8b84-4718-86da-a46fc5534b4b /boot                   ext4    defaults        1 2
       UUID=e734b75b-ce88-4daf-821f-7863e3b91e48 /data                   xfs     defaults        0 0
       UUID=039fbe3a-117b-4998-9d95-cfba038fe9f2 swap                    swap    defaults        0 0
       UUID=8ea3d17f-a1ff-4ba2-9175-84fc53d37739 /mnt/mysql              ext4    defaults        0 0

       更新挂载:
       [root@localhost mnt]#mount -a

       查询挂载结果:
       [root@localhost mnt]#df -T
       Filesystem            Type     1K-blocks    Used Available Use% Mounted on
       devtmpfs              devtmpfs    992140       0    992140   0% /dev
       tmpfs                 tmpfs      1006652       0   1006652   0% /dev/shm
       tmpfs                 tmpfs      1006652    9816    996836   1% /run
       tmpfs                 tmpfs      1006652       0   1006652   0% /sys/fs/cgroup
       /dev/sda2             xfs      104806400 4670984 100135416   5% /
       /dev/sda3             xfs       52403200  398576  52004624   1% /data
       /dev/sda1             ext4        999320  115952    814556  13% /boot
       tmpfs                 tmpfs       201328      28    201300   1% /run/user/42
       tmpfs                 tmpfs       201328    2348    198980   2% /run/user/0
       /dev/sr0              iso9660    6967726 6967726         0 100% /run/media/root/CentOS-8-BaseOS-x86_64
       /dev/mapper/vg0-mysql ext4       9223508   36888   8698380   1% /mnt/mysql

    扩展逻辑卷(ext4分区格式):

       查看逻辑卷剩余空间(Free PE/Szie):
       [root@localhost ~]#vgdisplay
       --- Volume group ---
       VG Name               vg0
       System ID             
       Format                lvm2
       Metadata Areas        2
       Metadata Sequence No  2
       VG Access             read/write
       VG Status             resizable
       MAX LV                0
       Cur LV                1
       Open LV               1
       Max PV                0
       Cur PV                2
       Act PV                2
       VG Size               <9.97 GiB
       PE Size               16.00 MiB
       Total PE              638
       Alloc PE / Size       576 / 9.00 GiB
       Free  PE / Size       62 / 992.00 MiB
       VG UUID               daKx15-jO4l-DkhK-Dwo5-UHGe-EkYo-EpPJgA

       添加逻辑卷:
       [root@localhost ~]#lvextend -l +100%free /dev/vg0/mysql
       Size of logical volume vg0/mysql changed from 9.00 GiB (576 extents) to <9.97 GiB (638 extents).
       Logical volume vg0/mysql successfully resized.
       [root@localhost ~]#lvs
       LV    VG  Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
       mysql vg0 -wi-ao---- <9.97g

       同步新增空间与原始空间的文件系统(ext4):
       [root@localhost ~]#resize2fs /dev/vg0/mysql
       resize2fs 1.44.3 (10-July-2018)
       Filesystem at /dev/vg0/mysql is mounted on /mnt/mysql; on-line resizing required
       old_desc_blocks = 2, new_desc_blocks = 2
       The filesystem on /dev/vg0/mysql is now 2613248 (4k) blocks long.

       同步新增空间与原始空间的文件系统(xfs):
       [root@localhost ~]#xfs_growfs /mnt/binlog/
       meta-data=/dev/mapper/vg0-binlog isize=512    agcount=4, agsize=983040 blks
                =                       sectsz=512   attr=2, projid32bit=1
                =                       crc=1        finobt=1, sparse=1, rmapbt=0
                =                       reflink=1
       data     =                       bsize=4096   blocks=3932160, imaxpct=25
                =                       sunit=0      swidth=0 blks
       naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
       log      =internal log           bsize=4096   blocks=2560, version=2
                =                       sectsz=512   sunit=0 blks, lazy-count=1
       realtime =none                   extsz=4096   blocks=0, rtextents=0
       data blocks changed from 3932160 to 4341760

    硬盘分区ext4/xfs文件系统扩展(一步到位):
       [root@localhost ~]#lvextend -L +1G -r /dev/vg0/mysql
       Size of logical volume vg0/mysql changed from <9.97 GiB (638 extents) to <10.97 GiB (702 extents).
       Logical volume vg0/mysql successfully resized.
       resize2fs 1.44.3 (10-July-2018)
       Filesystem at /dev/mapper/vg0-mysql is mounted on /mnt/mysql; on-line resizing required
       old_desc_blocks = 2, new_desc_blocks = 2
       The filesystem on /dev/mapper/vg0-mysql is now 2875392 (4k) blocks long.

    缩减逻辑卷(不能超过逻辑卷已存文件大小):
       
       取消挂载前,确保挂载分区无用户登录(相关查询命令):
       [root@localhost ~]#fuser -v /mnt/sdb1
                             USER        PID ACCESS COMMAND
        /mnt/sdb1:           root     kernel mount /mnt/sdb1
      或:[root@localhost ~]#lsof /mnt/sdb1
          COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
          bash    3130 admin  cwd    DIR   8,17       21  128 /mnt/sdb1
        踢出所有在使用该挂载点的用户:
        1.[root@localhost ~]#fuser -km /mnt/sdb1
        /mnt/sdb1:            3130c
        2.[root@localhost ~]#findmnt /mnt/sdb1
        TARGET    SOURCE    FSTYPE OPTIONS
        /mnt/sdb1 /dev/sdb1 ext4   ro,relatime,seclabel

        取消挂载的分区ext:
        umount /mnt/mysql

        修复:
        fsck -f /dev/vg0/mysql

        缩减文件系统:
        resize2fs /dev/vg0/mysql 6G

        缩减分区空间:
        lvreduce -L 6G /dev/vg0/mysql

        重新挂载分区:
        mount /dev/vg0/mysql /mnt/mysql
    删除LV中硬盘:
       搬出sdd内已用PE
       pvmove /dev/sdd
       删除逻辑卷
       vgreduce vg0 /dev/sdd
       移除硬盘
       pvremove /dev/sdd

  • 相关阅读:
    Java模拟ATM运行过程(第一版)
    双色Hanoi塔问题及判断指令
    一点编程风格
    游戏程序员养成计划
    OGRE编译
    Python学习收藏
    case 语句注意
    [c、c++]宏中"#"和"##"的用法(zz)
    网络代码平台tortoise svn+google code
    使用delegate进行解耦
  • 原文地址:https://www.cnblogs.com/joker-apologize/p/11705790.html
Copyright © 2011-2022 走看看