侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

通过LVM 扩容挂载硬盘

2023-12-02 星期六 / 0 评论 / 0 点赞 / 96 阅读 / 9879 字

需求: VM下 在原来挂载硬盘的基础上,通过LVM扩容此硬盘。 不需要额外挂载硬盘1、显示硬盘及所属分区情况[root@localhost ~]# fdisk -lDisk /dev/sda: 60

需求: VM下 在原来挂载硬盘的基础上,通过LVM扩容此硬盘。  不需要额外挂载硬盘1、显示硬盘及所属分区情况[root@localhost ~]# fdisk -lDisk /dev/sda: 60 GiB, 64424509440 bytes, 125829120 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x8d75991aDevice     Boot     Start       End   Sectors Size Id Type/dev/sda1  *         2048 121634815 121632768  58G 83 Linux/dev/sda2       121636862 125827071   4190210   2G  5 Extended/dev/sda5       121636864 125827071   4190208   2G 82 Linux swap / SolarisDisk /dev/sdb: 19 GiB, 41875931136 bytes, 81788928 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x0cbd968b2、分区:[root@localhost ~]# fdisk /dev/sdbWARNING: 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): pDisk /dev/sdb: 19 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x44817895   Device Boot      Start         End      Blocks   Id  System增加三个分区的操作/dev/sdb1Command (m for help): nCommand action   e   extended   p   primary partition (1-4)p ##分区类型Partition number (1-4): 1 First cylinder (1-6527, default 1):Using default value 1     ##起始块Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527):  回车Command (m for help): tPartition number (1-4): 1Hex code (type L to list codes): 8eChanged system type of partition 3 to 8e (Linux LVM)Command (m for help): pDisk /dev/sdb: 19 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x44817895   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1        1306    10490413+  8e  Linux LVMCommand (m for help): w                      ##最后记得保存,写入分区表The partition table has been altered!3、创建物理卷PV[root@localhost ~]# pvcreate /dev/sdb1    Physical volume "/dev/sdb1" successfully created  #创建成物理卷4、创建卷组VG创建卷组vg_server1 将物理卷/dev/sdb1 加入卷组vg_server1 [root@localhost ~]# vgcreate vg_server1 /dev/sdb1  Volume group "vg_server1" successfully created[root@localhost ~]#5、创建逻辑卷lV分在卷组vg_server1创建逻辑卷[root@localhost ~]# lvcreate -L 19G -n vg_server1_lvm1 vg_server1    # -L指定卷大小,-n 指定逻辑卷名  Logical volume "vg_server1_lvm1" created.                                        #指定跟卷组名[root@localhost ~]#[root@localhost ~]# lvdisplay  #查看生成的逻辑卷  --- Logical volume ---  LV Path                /dev/vg_server1/vg_server1_lvm1  LV Name                vg_server1_lvm1  VG Name                vg_server1  LV UUID                j4UX2E-LuRf-WKgW-9KGH-dBb3-RvAK-PXcORB  LV Write Access        read/write  LV Creation host, time localhost.localdomain, 2016-04-14 00:20:54 +0800  LV Status              available  # open                 0  LV Size                19.00 GiB  Current LE             3840  Segments               1  Allocation             inherit  Read ahead sectors     auto  - currently set to     256  Block device           253:06、格式化[root@localhost ~]# mke2fs -t ext4 /dev/vg_server1/vg_server1_lvm1mke2fs 1.41.12 (17-May-2010)文件系统标签=操作系统:Linux块大小=4096 (log=2)分块大小=4096 (log=2)Stride=0 blocks, Stripe width=0 blocksinodes, 3932160 blocksblocks (5.00%) reserved for the super user第一个数据块=0Maximum filesystem blocks=4026531840block groupsblocks per group, 32768 fragments per groupinodes per groupSuperblock backups stored on blocks:        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208正在写入inode表: 完成Creating journal (32768 blocks): 完成Writing superblocks and filesystem accounting information: 完成This filesystem will be automatically checked every 20 mounts ordays, whichever comes first.  Use tune2fs -c or -i to override.7 创建目录/mnt/lvm1挂载生成逻辑卷[root@localhost vg_server1]# mount /dev/vg_server1/vg_server1_lvm1 /mnt/lvm18、LVM 扩容VM下载硬盘里从19G改为29G然后进行分区 root@ubuntu:~# root@ubuntu:~# fdisk -lDisk /dev/sda: 60 GiB, 64424509440 bytes, 125829120 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x8d75991aDevice     Boot     Start       End   Sectors Size Id Type/dev/sda1  *         2048 121634815 121632768  58G 83 Linux/dev/sda2       121636862 125827071   4190210   2G  5 Extended/dev/sda5       121636864 125827071   4190208   2G 82 Linux swap / SolarisDisk /dev/sdb: 39 GiB, 41875931136 bytes, 81788928 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x0cbd968bDevice     Boot Start      End  Sectors Size Id Type/dev/sdb1        2048 39845887 39843840  19G 8e Linux LVMDisk /dev/mapper/vg_server1-vg_server1_lvm1: 18 GiB, 19327352832 bytes, 37748736 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes#######################################################################################################root@ubuntu:~# fdisk /dev/sdb Welcome to fdisk (util-linux 2.25.1).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Command (m for help): pDisk /dev/sdb: 39 GiB, 41875931136 bytes, 81788928 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x0cbd968bDevice     Boot Start      End  Sectors Size Id Type/dev/sdb1        2048 39845887 39843840  19G 8e Linux LVMCommand (m for help): nPartition type   p   primary (1 primary, 0 extended, 3 free)   e   extended (container for logical partitions)Select (default p): pPartition number (2-4, default 2): 2First sector (39845888-81788927, default 39845888): Last sector, +sectors or +size{K,M,G,T,P} (39845888-81788927, default 81788927): Created a new partition 2 of type 'Linux' and of size 20 GiB.Command (m for help): tPartition number (1,2, default 2): 2Hex code (type L to list all codes): 8eChanged type of partition 'Linux' to 'Linux LVM'.Command (m for help): wThe partition table has been altered.Calling ioctl() to re-read partition table.Re-reading the partition table failed.: Device or resource busyThe kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).#############################################################################################################root@ubuntu:~# fdisk -lDisk /dev/sda: 60 GiB, 64424509440 bytes, 125829120 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x8d75991aDevice     Boot     Start       End   Sectors Size Id Type/dev/sda1  *         2048 121634815 121632768  58G 83 Linux/dev/sda2       121636862 125827071   4190210   2G  5 Extended/dev/sda5       121636864 125827071   4190208   2G 82 Linux swap / SolarisDisk /dev/sdb: 39 GiB, 41875931136 bytes, 81788928 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x0cbd968bDevice     Boot    Start      End  Sectors Size Id Type/dev/sdb1           2048 39845887 39843840  19G 8e Linux LVM/dev/sdb2       39845888 81788927 41943040  20G 8e Linux LVM分完区后 执行下面命令, 不然识别不到新分的去root@ubuntu:~# partprobe#将分区/dev/sdb2创建为物理卷root@ubuntu:~# pvcreate /dev/sdb2  Physical volume "/dev/sdb2" successfully createdroot@ubuntu:~# vgextend vg_server1 /dev/sdb2     #将物理卷/dev/sdb2 加入卷组vg_server1  Volume group "vg_server1" successfully extended扩容/dev/vg_server1/vg_server1_lvm1逻辑卷,其中-L指定大小,#+5G 容量增加5G ,如果没有”+“ 表示扩展到多少root@ubuntu:~# lvextend -L +10G /dev/vg_server1/vg_server1_lvm1 /dev/sdb2   Extending logical volume vg_server1_lvm1 to 28.00 GiB  Logical volume vg_server1_lvm1 successfully resized  [root@localhost lvm1]# /sbin/resize2fs /dev/vg_server1/vg_server1_lvm1                                   #最后记得用命令resize 扩展逻辑大小  df查看root@ubuntu:~# df -hFilesystem                              Size  Used Avail Use% Mounted on/dev/sda1                                57G  6.6G   48G  13% /none                                    4.0K     0  4.0K   0% /sys/fs/cgroupudev                                    988M  4.0K  988M   1% /devtmpfs                                   201M  500K  200M   1% /runnone                                    5.0M     0  5.0M   0% /run/locknone                                   1001M     0 1001M   0% /run/shmnone                                    100M     0  100M   0% /run/user/dev/mapper/vg_server1-vg_server1_lvm1   28G   44M   26G   1% /opt

 

广告 广告

评论区