申請新硬盤擴(kuò)容已經(jīng)存在分區(qū)

一、申請新硬盤

1. 申請?zhí)砑佑脖P
2. 成功后需要重啟機(jī)器,才能看到硬盤

二、使用命令fdisk -l 確定新硬盤

    sudo fdisk -l 

回顯:

    磁盤 /dev/sdc:214.7 GB, 214748364800 字節(jié),419430400 個扇區(qū)
    Units = 扇區(qū) of 1 * 512 = 512 bytes
    扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
    I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)置文件系統(tǒng)格


    磁盤 /dev/sda:53.7 GB, 53687091200 字節(jié),104857600 個扇區(qū)
    Units = 扇區(qū) of 1 * 512 = 512 bytes
    扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
    I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
    磁盤標(biāo)簽類型:dos
    磁盤標(biāo)識符:0x000a860e

       設(shè)備 Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048      616447      307200   83  Linux
    /dev/sda2          616448   104857599    52120576   8e  Linux LVM
    WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

    磁盤 /dev/sdb:161.1 GB, 161061273600 字節(jié),314572800 個扇區(qū)
    Units = 扇區(qū) of 1 * 512 = 512 bytes
    扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
    I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
    磁盤標(biāo)簽類型:gpt
    Disk identifier: 7CB95C4D-482B-4572-94E0-76B6321D8E51


    #         Start          End    Size  Type            Name
     1           34    314572766    150G  Microsoft basic primary

    磁盤 /dev/mapper/Vol-root:21.5 GB, 21474836480 字節(jié),41943040 個扇區(qū)
    Units = 扇區(qū) of 1 * 512 = 512 bytes
    扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
    I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)


    磁盤 /dev/mapper/Vol-swap:2147 MB, 2147483648 字節(jié),4194304 個扇區(qū)
    Units = 扇區(qū) of 1 * 512 = 512 bytes
    扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
    I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)


    磁盤 /dev/mapper/Vol-home:12.6 GB, 12561940480 字節(jié),24535040 個扇區(qū)
    Units = 扇區(qū) of 1 * 512 = 512 bytes
    扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
    I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)


    磁盤 /dev/mapper/Vol-tmp:10.7 GB, 10737418240 字節(jié),20971520 個扇區(qū)
    Units = 扇區(qū) of 1 * 512 = 512 bytes
    扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
    I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)


    磁盤 /dev/mapper/Vol-var:166.4 GB, 166429982720 字節(jié),325058560 個扇區(qū)
    Units = 扇區(qū) of 1 * 512 = 512 bytes
    扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
    I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)

對比發(fā)現(xiàn)第一塊硬盤/dev/sdc是新加的

    磁盤 /dev/sdc:214.7 GB, 214748364800 字節(jié),419430400 個扇區(qū)
    Units = 扇區(qū) of 1 * 512 = 512 bytes
    扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
    I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)

三、使用fdisk對/dev/sdc分區(qū)

    fdisk /dev/sdc

回顯:

    歡迎使用 fdisk (util-linux 2.23.2)。

    更改將停留在內(nèi)存中,直到您決定將更改寫入磁盤。
    使用寫入命令前請三思。

    Device does not contain a recognized partition table
    使用磁盤標(biāo)識符 0xcb30a938 創(chuàng)建新的 DOS 磁盤標(biāo)簽。

    命令(輸入 m 獲取幫助):

輸入m查看常用指令及意義:

命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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)

輸入n,在當(dāng)前硬盤中新建一個分區(qū):

    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p):

p是主分區(qū),e是擴(kuò)展分區(qū),輸入p,創(chuàng)建一個主分區(qū):

分區(qū)號 (1-4,默認(rèn) 1):

硬盤全新,直接輸入回車,創(chuàng)建分區(qū)一:

起始 扇區(qū) (2048-419430399,默認(rèn)為 2048):

回車,使用默認(rèn)起始扇區(qū)

Last 扇區(qū), +扇區(qū) or +size{K,M,G} (2048-419430399,默認(rèn)為 419430399):

回車,使用默認(rèn)終止扇區(qū)

將使用默認(rèn)值 419430399
分區(qū) 1 已設(shè)置為 Linux 類型,大小設(shè)為 200 GiB

此時的更改還在內(nèi)存中,輸入p確認(rèn)分區(qū)數(shù)據(jù)是否正確:

磁盤 /dev/sdc:214.7 GB, 214748364800 字節(jié),419430400 個扇區(qū)
Units = 扇區(qū) of 1 * 512 = 512 bytes
扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
磁盤標(biāo)簽類型:dos
磁盤標(biāo)識符:0xcb30a938

   設(shè)備 Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048   419430399   209714176   83  Linux

確認(rèn)沒有問題后輸入w,改動落盤:

The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盤。

此時在硬盤/dev/sdc上創(chuàng)建了分區(qū)sdc1,

四、將硬盤修改同步到系統(tǒng)內(nèi)核

partprobe /dev/sdc

五、查看物理卷、邏輯卷

pvdisplay查看物理卷:

  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               Vol
  PV Size               <49.71 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              12724
  Free PE               0
  Allocated PE          12724
  PV UUID               jGxa54-5Z5P-6TEz-YF2V-3dHP-fNCG-31v9rD
   
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               Vol
  PV Size               <150.00 GiB / not usable <3.97 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              38399
  Free PE               256
  Allocated PE          38143
  PV UUID               qZ4NuA-vZof-zAAN-N9rN-VK6K-z0yc-0gNZGs

lvdiskplay查看邏輯卷

  --- Logical volume ---
  LV Path                /dev/Vol/home
  LV Name                home
  VG Name                Vol
  LV UUID                N18K2u-LOSG-3HRy-mUAA-eOQA-7mgi-F1Ko9F
  LV Write Access        read/write
  LV Creation host, time localhost, 2022-08-09 01:07:38 +0800
  LV Status              available
  # open                 1
  LV Size                <11.70 GiB
  Current LE             2995
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/Vol/tmp
  LV Name                tmp
  VG Name                Vol
  LV UUID                lIaK7n-GCcr-49G2-qTIY-hwLH-ZpRv-pqKl2I
  LV Write Access        read/write
  LV Creation host, time localhost, 2022-08-09 01:07:38 +0800
  LV Status              available
  # open                 1
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3
   
  --- Logical volume ---
  LV Path                /dev/Vol/var
  LV Name                var
  VG Name                Vol
  LV UUID                Ap6gbh-luh5-5pcj-WehD-Bx8w-9HD7-Xj04MR
  LV Write Access        read/write
  LV Creation host, time localhost, 2022-08-09 01:07:38 +0800
  LV Status              available
  # open                 1
  LV Size                155.00 GiB
  Current LE             39680
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:4
   
  --- Logical volume ---
  LV Path                /dev/Vol/root
  LV Name                root
  VG Name                Vol
  LV UUID                4IfOQk-31cm-Fcx1-eanG-jeBf-lw0R-2yVTXM
  LV Write Access        read/write
  LV Creation host, time localhost, 2022-08-09 01:07:38 +0800
  LV Status              available
  # open                 1
  LV Size                20.00 GiB
  Current LE             5120
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/Vol/swap
  LV Name                swap
  VG Name                Vol
  LV UUID                77QaRH-sadM-yEii-HX5f-TvOT-64PY-EKJpXw
  LV Write Access        read/write
  LV Creation host, time localhost, 2022-08-09 01:07:38 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

我們的目標(biāo)是使用新硬盤對/dev/Vol/var邏輯卷進(jìn)行擴(kuò)容:

  --- Logical volume ---
  LV Path                /dev/Vol/var
  LV Name                var
  VG Name                Vol
  LV UUID                Ap6gbh-luh5-5pcj-WehD-Bx8w-9HD7-Xj04MR
  LV Write Access        read/write
  LV Creation host, time localhost, 2022-08-09 01:07:38 +0800
  LV Status              available
  # open                 1
  LV Size                155.00 GiB
  Current LE             39680
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:4

使用pvcreate /dev/sdc1創(chuàng)建物理卷:

  Physical volume "/dev/sdc1" successfully created.

使用pvdisplay查看發(fā)現(xiàn)多了/dev/sdc1這個物理卷

  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               Vol
  PV Size               <49.71 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              12724
  Free PE               0
  Allocated PE          12724
  PV UUID               jGxa54-5Z5P-6TEz-YF2V-3dHP-fNCG-31v9rD
   
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               Vol
  PV Size               <150.00 GiB / not usable <3.97 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              38399
  Free PE               256
  Allocated PE          38143
  PV UUID               qZ4NuA-vZof-zAAN-N9rN-VK6K-z0yc-0gNZGs
   
  "/dev/sdc1" is a new physical volume of "<200.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc1
  VG Name               
  PV Size               <200.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               jloLZ4-TS9y-O5c8-TIQ9-yeCj-cecT-jwN6no

六、將sdc硬盤的分區(qū)sdc1上創(chuàng)建的物理卷加入卷組

使用vgdisplay查看卷組

 --- Volume group ---
  VG Name               Vol
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  8
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                5
  Open LV               5
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               <199.70 GiB
  PE Size               4.00 MiB
  Total PE              51123
  Alloc PE / Size       50867 / <198.70 GiB
  Free  PE / Size       256 / 1.00 GiB
  VG UUID               J0mnNe-UHlF-jIcJ-1LEk-edeo-1tqJ-sN2ubw

使用命令 vgextend Vol /dev/sdc1 添加物理卷/dev/sdc1到卷組 Vol中
(Vol是卷組的名稱,該命令添加一個或多個物理卷到卷組,用來擴(kuò)容卷組中的邏輯卷)

  Volume group "Vol" successfully extended

再使用vgdisplay查看卷組

  --- Volume group ---
  VG Name               Vol
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  9
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                5
  Open LV               5
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               <399.70 GiB
  PE Size               4.00 MiB
  Total PE              102322
  Alloc PE / Size       50867 / <198.70 GiB
  Free  PE / Size       51455 / <201.00 GiB
  VG UUID               J0mnNe-UHlF-jIcJ-1LEk-edeo-1tqJ-sN2ubw

發(fā)現(xiàn)變動行:

Free  PE / Size       51455 / <201.00 GiB

七、擴(kuò)展邏輯卷,擴(kuò)展xfs分區(qū)大小

使用命令lvextend -l +100%FREE /dev/Vol/var擴(kuò)展邏輯卷大小
* -l 選項表示后面的參數(shù)是要擴(kuò)展的邏輯卷的大小。
* +100%FREE 指定要將邏輯卷擴(kuò)展到空閑空間的最大百分比。這里的 100%FREE 表示使用所有可用的空閑空間來擴(kuò)展邏輯卷。
* /dev/Vol/var 是lvdisplay中的LV Path

  Size of logical volume Vol/var changed from 155.00 GiB (39680 extents) to <356.00 GiB (91135 extents).
  Logical volume Vol/var successfully resized.

使用sudo xfs_growfs /dev/Vol/var對xfs分區(qū)擴(kuò)展空間

meta-data=/dev/mapper/Vol-var    isize=512    agcount=104, agsize=393216 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=40632320, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               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 40632320 to 93322240

最后使用df命令查看硬盤分區(qū),發(fā)現(xiàn)/var分區(qū)已經(jīng)擴(kuò)容了

/dev/mapper/Vol-root   20G  1.3G   19G    7% /
devtmpfs              7.8G     0  7.8G    0% /dev
tmpfs                 7.8G     0  7.8G    0% /dev/shm
tmpfs                 7.8G  8.5M  7.8G    1% /run
tmpfs                 7.8G     0  7.8G    0% /sys/fs/cgroup
/dev/sda1             297M  125M  172M   43% /boot
/dev/mapper/Vol-var   356G  300M  356G    1% /var
/dev/mapper/Vol-tmp    10G   33M   10G    1% /tmp
/dev/mapper/Vol-home   12G   33M   12G    1% /home
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容