給EXSI虛擬機中linux硬盤擴容

給EXSI虛擬機中linux硬盤擴容

 

將硬盤1從6G擴充到10Gnode

 

 

 

查看目前磁盤狀態linux

[root@csvn ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 484M     0  484M   0% /dev
tmpfs                    496M     0  496M   0% /dev/shm
tmpfs                    496M  7.1M  489M   2% /run
tmpfs                    496M     0  496M   0% /sys/fs/cgroup
/dev/mapper/centos-root  4.9G  2.9G  2.1G  59% /
/dev/sdb1                4.8G   21M  4.6G   1% /data
/dev/sda1                497M  154M  344M  31% /boot
tmpfs                    100M     0  100M   0% /run/user/1001
tmpfs                    100M     0  100M   0% /run/user/0
[root@csvn ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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
Disk label type: dos
Disk identifier: 0x000c208b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    12582911     5778432   8e  Linux LVM

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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
Disk label type: dos
Disk identifier: 0xc42fca3d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10485759     5241856   83  Linux

Disk /dev/mapper/centos-root: 5226 MB, 5226102784 bytes, 10207232 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


Disk /dev/mapper/centos-swap: 645 MB, 645922816 bytes, 1261568 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
可看到磁盤/dev/sda大小已經變成10.7GB

開始擴容centos

[root@csvn ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).app

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.tcp


Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (12582912-20971519, default 12582912):
Using default value 12582912
Last sector, +sectors or +size{K,M,G} (12582912-20971519, default 20971519):
Using default value 20971519
Partition 3 of type Linux and of size 4 GiB is setide

Command (m for help): t                                     (修改分區類型爲 Linux LVM, 8e)
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'svn

Command (m for help): wq
The partition table has been altered!工具

Calling ioctl() to re-read partition table.spa

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
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)
Syncing disks.3d

再次查看磁盤狀態,可見新的sda3,表示爲可用狀態

[root@csvn ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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
Disk label type: dos
Disk identifier: 0x000c208b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    12582911     5778432   8e  Linux LVM
/dev/sda3        12582912    20971519     4194304   8e  Linux LVM

用partprobe從新讀取分區信息

ps:使用fdisk工具只是將分區信息寫到磁盤,若是須要mkfs磁盤分區則須要重啓系統,而使用partprobe則可使kernel從新讀取分區信息,從而避免重啓系統.

[root@csvn ~]# partprobe /dev/sda3

建立物理卷及加入組

[root@csvn ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
[root@csvn ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended

查看物理卷狀況

[root@csvn ~]# lvextend
  No command with matching syntax recognised.  Run 'lvextend --help' for more information.
[root@csvn ~]# 
[root@csvn ~]# lvextend /dev/mapper/centos-root 
  No command with matching syntax recognised.  Run 'lvextend --help' for more information.
[root@csvn ~]# 
[root@csvn ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  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               5.50 GiB
  PE Size               4.00 GiB
  Total PE              2433
  Alloc PE / Size       2424 / <9.47 GiB
  Free  PE / Size       9 / 4.00 GiB
  VG UUID               rQ55Rt-cdp0-Z177-4RaC-e5PN-7dU2-WTRCDO
   

擴容

[root@csvn ~]# lvresize -L +4G /dev/mapper/centos-root
  Extending logical volume LogVol00 to  8.9G GB
  Logical volume /centos-root successfully resized

同步文件系統

[root@csvn ~]# xfs_growfs /dev/centos/root 
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=318976 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1275904, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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 1275904 to 2324480

驗證

[root@csvn ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 484M     0  484M   0% /dev
tmpfs                    496M     0  496M   0% /dev/shm
tmpfs                    496M  7.1M  489M   2% /run
tmpfs                    496M     0  496M   0% /sys/fs/cgroup
/dev/mapper/centos-root  8.9G  2.9G  6.1G  33% /
/dev/sdb1                4.8G   21M  4.6G   1% /data
/dev/sda1                497M  154M  344M  31% /boot
tmpfs                    100M     0  100M   0% /run/user/0
tmpfs                    100M     0  100M   0% /run/user/1001

成功擴容

 


報錯

Can't initialize physical volume(沒法初始化的物理量)

[root@csvn ~]# pvcreate /dev/sda3
  Can't initialize physical volume "/dev/sda3" of volume group "centos" without -ff
  /dev/sda3: physical volume not initialized.
[root@csvn ~]#

檢查後得知,以前按照常規流程建立過LVM:/dev/centos/sda3,而沒有卸載掉。

解決方法:

方法一:

按順序前後卸載邏輯卷、卷組(必要時還要卸載物理卷):

 lvremove /dev/...邏輯卷

 vgremove 卷組

 成功卸載後再從新執行sudo pvcreate /dev/cciss/c0d1p1,再也不有錯誤發生。

 接着執行後續動做來建立LVM。

方法二:

pvcreate -ff -y /dev/sda3

由於我是擴充根目錄的,根目錄卷組沒法卸載,因此這個方法不適用。


 

[root@csvn ~]# partprobe 
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

/dev/sr0是你的光驅(CD Drive),由於你運行partprobe時沒有指定設備,因此它會檢查全部的塊設備(block devices),因爲光驅是read-only,因此報上述告警信息,其實避免這個錯誤也很簡單,你只須要使用partprobe檢查、掃描指定設備便可。

[root@csvn ~]# partprobe /dev/sda3

[root@csvn ~]# resize2fs  /dev/mapper/centos-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.
[root@csvn ~]# 

resize2fs

調整ext2\ext3\ext4文件系統的大小,它能夠放大或者縮小沒有掛載的文件系統的大小。若是文件系統已經掛載,它能夠擴大文件系統的大小,前提是內核支持在線調整大小。

擴容/目錄後,df -h查看,卻沒有擴容到。重啓也不行,百度說umout目錄從新擴容試試,但根目錄不可能umout的。

具體再百度發現,(因爲CentOS6和CentOS7在默認根文件系統的文件系統格式存在差別,須要判斷是否爲xfs,若是是xfs則應該使用xfs_growfs而不是一味的使用resize2fs。)

Linux7文件系統格式是xfs,resize2fs命令是讀取不了的。

因此要用xfs_growfs來同步文件系統。

[root@csvn ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 484M     0  484M   0% /dev
tmpfs                    496M     0  496M   0% /dev/shm
tmpfs                    496M  7.1M  489M   2% /run
tmpfs                    496M     0  496M   0% /sys/fs/cgroup
/dev/mapper/centos-root  4.9G  2.9G  2.1G  59% /
/dev/sdb1                4.8G   21M  4.6G   1% /data
/dev/sda1                497M  154M  344M  31% /boot
tmpfs                    100M     0  100M   0% /run/user/0
tmpfs                    100M     0  100M   0% /run/user/1001
[root@csvn ~]# 
[root@csvn ~]# 
[root@csvn ~]# 
[root@csvn ~]# xfs_info /dev/centos/root 
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=318976 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1275904, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@csvn ~]# 

用xfs_growfs來同步文件系

[root@csvn ~]# xfs_growfs /dev/centos/root 
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=318976 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1275904, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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 1275904 to 2324480
[root@csvn ~]# 
[root@csvn ~]# 
[root@csvn ~]# 
[root@csvn ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 484M     0  484M   0% /dev
tmpfs                    496M     0  496M   0% /dev/shm
tmpfs                    496M  7.1M  489M   2% /run
tmpfs                    496M     0  496M   0% /sys/fs/cgroup
/dev/mapper/centos-root  8.9G  2.9G  6.1G  33% /
/dev/sdb1                4.8G   21M  4.6G   1% /data
/dev/sda1                497M  154M  344M  31% /boot
tmpfs                    100M     0  100M   0% /run/user/0
tmpfs                    100M     0  100M   0% /run/user/1001
[root@csvn ~]# 

可看到已成功擴容根目錄。

附錄:

xfs_admin: 調整 xfs 文件系統的各類參數

xfs_copy: 拷貝 xfs 文件系統的內容到一個或多個目標系統(並行方式) 

xfs_db: 調試或檢測 xfs 文件系統(查看文件系統碎片等) 

xfs_check: 檢測 xfs 文件系統的完整性 

xfs_bmap: 查看一個文件的塊映射 

xfs_repair: 嘗試修復受損的 xfs 文件系統 

xfs_fsr: 碎片整理 

xfs_quota: 管理 xfs 文件系統的磁盤配額 

xfs_metadump: 將 xfs 文件系統的元數據 (metadata) 拷貝到一個文件中 

xfs_mdrestore: 從一個文件中將元數據 (metadata) 恢復到 xfs 文件系統 

xfs_growfs: 調整一個 xfs 文件系統大小(只能擴展) 

xfs_freeze    暫停(-f)和恢復(-u)xfs 文件系統

xfs_logprint: 打印xfs文件系統的日誌 

xfs_mkfile: 建立xfs文件系統 

xfs_info: 查詢文件系統詳細信息 

xfs_ncheck: generate pathnames from i-numbers for XFS 

xfs_rtcp: XFS實時拷貝命令 

xfs_io: 調試xfs I/O路徑

相關文章
相關標籤/搜索