天天看點

玩轉虛拟機VirtualBox- centos 磁盤擴容詳細操作步驟

玩轉虛拟機VirtualBox

[root@master01 ~]# fdisk -l

磁盤 /dev/sda:21.5 GB, 21474836480 位元組,41943040 個扇區

Units = 扇區 of 1 * 512 = 512 bytes

扇區大小(邏輯/實體):512 位元組 / 512 位元組

I/O 大小(最小/最佳):512 位元組 / 512 位元組

磁盤标簽類型:dos

磁盤辨別符:0x000c9b48

   裝置 Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     2099199     1048576   83  Linux

/dev/sda2         2099200    16777215     7339008   8e  Linux LVM

磁盤 /dev/mapper/centos-root:6652 MB, 6652166144 位元組,12992512 個扇區

Units = 扇區 of 1 * 512 = 512 bytes

扇區大小(邏輯/實體):512 位元組 / 512 位元組

I/O 大小(最小/最佳):512 位元組 / 512 位元組

磁盤 /dev/mapper/centos-swap:859 MB, 859832320 位元組,1679360 個扇區

Units = 扇區 of 1 * 512 = 512 bytes

扇區大小(邏輯/實體):512 位元組 / 512 位元組

I/O 大小(最小/最佳):512 位元組 / 512 位元組

[root@master01 ~]# fdisk /dev/sda

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

更改将停留在記憶體中,直到您決定将更改寫入磁盤。

使用寫入指令前請三思。

指令(輸入 m 擷取幫助):n

Partition type:

   p   primary (2 primary, 0 extended, 2 free)

   e   extended

Select (default p): p

分區号 (3,4,預設 3):3

起始 扇區 (16777216-41943039,預設為 16777216):

将使用預設值 16777216

Last 扇區, +扇區 or +size{K,M,G} (16777216-41943039,預設為 41943039):

将使用預設值 41943039

分區 3 已設定為 Linux 類型,大小設為 12 GiB

指令(輸入 m 擷取幫助):w

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 裝置或資源忙.

The 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)

正在同步磁盤。

reboot

[root@master01 ~]# vgextend centos /dev/sda3

  Volume group "centos" successfully extended

[root@master01 ~]# sudo lvextend /dev/centos/root /dev/sda3

  Size of logical volume centos/root changed from <6.20 GiB (1586 extents) to 18.19 GiB (4657 extents).

  Logical volume centos/root successfully resized.

[root@master01 ~]# lvdisplay

  --- Logical volume ---

  LV Path                /dev/centos/swap

  LV Name                swap

  VG Name                centos

  LV UUID                KMOpgG-i5qR-Ge74-gdiE-YQDD-IYcF-2MwJTA

  LV Write Access        read/write

  LV Creation host, time localhost, 2021-02-09 10:58:09 -0500

  LV Status              available

  # open                 0

  LV Size                820.00 MiB

  Current LE             205

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:1

  --- Logical volume ---

  LV Path                /dev/centos/root

  LV Name                root

  VG Name                centos

  LV UUID                9GmQug-sB4F-CExG-9mS2-Y1kQ-T0kc-eCiIzI

  LV Write Access        read/write

  LV Creation host, time localhost, 2021-02-09 10:58:10 -0500

  LV Status              available

  # open                 1

  LV Size                18.19 GiB

  Current LE             4657

  Segments               2

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:0

[root@master01 ~]# resize2fs /dev/centos/root

resize2fs 1.42.9 (28-Dec-2013)

resize2fs: Bad magic number in super-block 當嘗試打開 /dev/centos/root 時

找不到有效的檔案系統超級塊.

[root@master01 ~]# df -h

檔案系統                 容量  已用  可用 已用% 挂載點

devtmpfs                 484M     0  484M    0% /dev

tmpfs                    496M     0  496M    0% /dev/shm

tmpfs                    496M  6.8M  489M    2% /run

tmpfs                    496M     0  496M    0% /sys/fs/cgroup

/dev/mapper/centos-root  6.2G  6.2G   76M   99% /

/dev/sda1               1014M  151M  864M   15% /boot

tmpfs                    100M     0  100M    0% /run/user/0

[root@master01 ~]# xfs_growfs /dev/centos/root

meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=406016 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=1        finobt=0 spinodes=0

data     =                       bsize=4096   blocks=1624064, 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 1624064 to 4768768

[root@master01 ~]# resize2fs /dev/centos/root

resize2fs 1.42.9 (28-Dec-2013)

resize2fs: Bad magic number in super-block 當嘗試打開 /dev/centos/root 時

找不到有效的檔案系統超級塊.

[root@master01 ~]# resize2fs /dev/mapper/centos-root

resize2fs 1.42.9 (28-Dec-2013)

resize2fs: Bad magic number in super-block 當嘗試打開 /dev/mapper/centos-root 時

找不到有效的檔案系統超級塊.

[root@master01 ~]# df -h

檔案系統                 容量  已用  可用 已用% 挂載點

devtmpfs                 484M     0  484M    0% /dev

tmpfs                    496M     0  496M    0% /dev/shm

tmpfs                    496M  6.8M  489M    2% /run

tmpfs                    496M     0  496M    0% /sys/fs/cgroup

/dev/mapper/centos-root   19G  6.2G   13G   34% /

/dev/sda1               1014M  151M  864M   15% /boot

tmpfs                    100M     0  100M    0% /run/user/0

指令記錄

繼續閱讀