温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何给linux添加磁盘并扩展逻辑卷

发布时间:2021-11-08 17:38:03 来源:亿速云 阅读:113 作者:柒染 栏目:建站服务器

如何给linux添加磁盘并扩展逻辑卷,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

给linux添加磁盘并扩展逻辑卷

               ——生产实录

 fdisk -l

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: 0x000e7336

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64        2611    20458496   8e  Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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/mapper/vg_minisite-lv_root: 16.7 GB, 16718495744 bytes

255 heads, 63 sectors/track, 2032 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/mapper/vg_minisite-lv_swap: 4227 MB, 4227858432 bytes

255 heads, 63 sectors/track, 514 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

[root@minisite ~]# 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 0x4cebbd75.

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): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0x4cebbd75

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-1305, default 1): 

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): 

Using default value 1305

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): l

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        

 1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-

 2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-

 3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-

 4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx         

 5  Extended        42  SFS             86  NTFS volume set da  Non-FS data    

 6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .

 7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility   

 8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt         

 9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access     

 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O        

 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor      

 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs        

 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT            

 f  W95 Ext'd (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/

10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b

11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor      

12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor      

14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary  

16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS    

17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 

18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto

1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep        

1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT            

1e  Hidden W95 FAT1

Command (m for help): t

Selected partition 1

Hex code (type L to list codes): 8e

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.

[root@minisite ~]# partx -a /dev/sdb

BLKPG: Device or resource busy

error adding partition 1

[root@minisite ~]# lsblk 

NAME                           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sr0                             11:0    1 1024M  0 rom  

sda                              8:0    0   20G  0 disk 

忖sda1                           8:1    0  500M  0 part /boot

忖sda2                           8:2    0 19.5G  0 part 

  忖vg_minisite-lv_root (dm-0) 253:0    0 15.6G  0 lvm  /

  忖vg_minisite-lv_swap (dm-1) 253:1    0    4G  0 lvm  [SWAP]

sdb                              8:16   0   10G  0 disk 

忖sdb1                           8:17   0   10G  0 part 

[root@minisite ~]# pvcreate /dev/sdb1

  Physical volume "/dev/sdb1" successfully created

[root@minisite ~]# vgdisplay 

  --- Volume group ---

  VG Name               vg_minisite

  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               19.51 GiB

  PE Size               4.00 MiB

  Total PE              4994

  Alloc PE / Size       4994 / 19.51 GiB

  Free  PE / Size       0 / 0   

  VG UUID               8ZwMrO-qNqg-Xdsn-l8SG-ecZf-WFbB-R4Si2z

[root@minisite ~]# lvdisplay 

  --- Logical volume ---

  LV Path                /dev/vg_minisite/lv_root

  LV Name                lv_root

  VG Name                vg_minisite

  LV UUID                owBHOh-LSip-wWFx-CTtU-sezw-6tE9-VzVMHz

  LV Write Access        read/write

  LV Creation host, time minisite, 2013-12-27 18:09:52 +0800

  LV Status              available

  # open                 1

  LV Size                15.57 GiB

  Current LE             3986

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:0

  --- Logical volume ---

  LV Path                /dev/vg_minisite/lv_swap

  LV Name                lv_swap

  VG Name                vg_minisite

  LV UUID                vCCRq7-CdkY-erXQ-ZFPX-3Bi1-yaxi-efTvul

  LV Write Access        read/write

  LV Creation host, time minisite, 2013-12-27 18:09:59 +0800

  LV Status              available

  # open                 1

  LV Size                3.94 GiB

  Current LE             1008

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:1

[root@minisite ~]# vgextend vg_minisite /dev/sdb1

  Volume group "vg_minisite" successfully extended

[root@minisite ~]# vgdisplay 

  --- Volume group ---

  VG Name               vg_minisite

  System ID             

  Format                lvm2

  Metadata Areas        2

  Metadata Sequence No  4

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                2

  Open LV               2

  Max PV                0

  Cur PV                2

  Act PV                2

  VG Size               29.50 GiB

  PE Size               4.00 MiB

  Total PE              7552

  Alloc PE / Size       4994 / 19.51 GiB

  Free  PE / Size       2558 / 9.99 GiB

  VG UUID               8ZwMrO-qNqg-Xdsn-l8SG-ecZf-WFbB-R4Si2z

[root@minisite ~]# lvextend -l +2558 /dev/vg_minisite/lv_root          #-l是按照pe的方式计算,一个PE是4M。

  Extending logical volume lv_root to 25.56 GiB

  Logical volume lv_root successfully resized
注释:上面是用PE来计算的空间,即2558(个)*4M;当然也可以直接加空间大小,这样更方便: lvextend -L+2G /dev/vg_minisite/lv_root 

[root@minisite ~]# resize2fs /dev/vg_minisite/lv_root             #使扩展的逻辑卷生效

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/vg_minisite/lv_root is mounted on /; on-line resizing required

old desc_blocks = 1, new_desc_blocks = 2

Performing an on-line resize of /dev/vg_minisite/lv_root to 6701056 (4k) blocks.

The filesystem on /dev/vg_minisite/lv_root is now 6701056 blocks long.

[root@minisite ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/vg_minisite-lv_root

                       26G  5.2G   19G  22% /

tmpfs                 939M     0  939M   0% /dev/shm

/dev/sda1             485M   37M  423M   9% /boot

看完上述内容,你们掌握如何给linux添加磁盘并扩展逻辑卷的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI