1. 程式人生 > >記一次伺服器擴盤

記一次伺服器擴盤

問題:測試伺服器突然zk掛了,重新啟動後根本起不了,發現報錯:

查詢後發現根分割槽爆滿:

解決問題:

一、在虛擬機器上增加新盤

1、增加盤後將盤分割槽

[[email protected] ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

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


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

Command (m for help): p

Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x000c1368

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   125829119    61864960   8e  Linux LVM

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): 3
Invalid partition type `3'

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

Command (m for help): p

Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x000c1368

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   125829119    61864960   8e  Linux LVM
/dev/sda3       125829120   419430399   146800640   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

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.

問題:此時我們在/dev下查不到sd3檔案

解決辦法:執行[[email protected] ~]# partprobe

格式化盤:

[[email protected] ~]# mkfs.xfs /dev/sda3
meta-data=/dev/sda3              isize=512    agcount=4, agsize=9175040 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=36700160, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=17920, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

查詢到了我們的盤uuid

[[email protected] ~]# blkid
/dev/sda1: UUID="553e6333-e548-4aa9-942d-61f1e56afc9f" TYPE="xfs" 
/dev/sda2: UUID="Z7YLpG-G8XF-lFay-Cc3i-0Z39-qPtN-vAp1lu" TYPE="LVM2_member" 
/dev/mapper/cl-root: UUID="5aca02a1-813b-4b22-b004-905273bcabf7" TYPE="xfs" 
/dev/mapper/cl-swap: UUID="bec18aee-7929-4bef-8f6e-419060bfad80" TYPE="swap" 
/dev/mapper/cl-home: UUID="a1eaa957-ed36-4eb0-9013-4af168b3a438" TYPE="xfs" 
/dev/sda3: UUID="95859c12-86cf-4c44-8408-d04847d595a2" TYPE="xfs" 

二、擴盤

1、建立物理卷

[[email protected] ~]# pvcreate /dev/sda3
WARNING: xfs signature detected on /dev/sda3 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/sda3.
  Physical volume "/dev/sda3" successfully created.
2、建立卷組

查詢我們要擴充盤的卷組,然後將新的分割槽加入到卷組

[[email protected] ~]# lvs
  LV   VG Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home cl -wi-ao---- 18.70g                                                    
  root cl -wi-ao---- 38.30g                                                    
  swap cl -wi-ao----  2.00g    

以上看到卷組名稱是cl

[[email protected] ~]# vgextend cl /dev/sda3
  Couldn't create temporary archive name.

以上問題是盤空間不足導致,我在/tmp目錄清理下,盤空間降下來了

[[email protected] tmp]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   39G   37G  1.7G  96% /
devtmpfs             1.9G     0  1.9G   0% /dev
tmpfs                1.9G     0  1.9G   0% /dev/shm
tmpfs                1.9G  8.6M  1.9G   1% /run
tmpfs                1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1           1014M  139M  876M  14% /boot
/dev/mapper/cl-home   19G  141M   19G   1% /home
tmpfs                378M     0  378M   0% /run/user/0
[[email protected] tmp]# vgextend cl /dev/sda3
  Volume group "cl" successfully extended
3、擴充到我們的邏輯卷

查詢當前的Free  PE / Size的值

[[email protected] tmp]# vgdisplay
  --- Volume group ---
  VG Name               cl
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               198.99 GiB
  PE Size               4.00 MiB
  Total PE              50942
  Alloc PE / Size       15102 / 58.99 GiB
  Free  PE / Size       35840 / 140.00 GiB
  VG UUID               9pLc6R-J6Lw-iqcv-DL8v-iZa7-m9ni-rbskmb

擴盤:

[[email protected] ~]# lvextend -L 100G /dev/mapper/cl-root 
  Size of logical volume cl/root changed from 38.30 GiB (9804 extents) to 100.00 GiB (25600 extents).
  Logical volume cl/root successfully resized.
此時我們df查詢盤情況:

[[email protected] ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   39G   37G  1.7G  96% /
devtmpfs             1.9G     0  1.9G   0% /dev
tmpfs                1.9G     0  1.9G   0% /dev/shm
tmpfs                1.9G  8.6M  1.9G   1% /run
tmpfs                1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1           1014M  139M  876M  14% /boot
/dev/mapper/cl-home   19G  141M   19G   1% /home
tmpfs                378M     0  378M   0% /run/user/0
發現盤還沒有顯示:

重新整理顯示,常用的命令重新整理報錯:因我們的系統既不是ext3也不是ext4,

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

解決辦法:

[[email protected] ~]# xfs_growfs  /dev/mapper/cl-root 
meta-data=/dev/mapper/cl-root    isize=512    agcount=4, agsize=2509824 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=10039296, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4902, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 10039296 to 26214400

再一次查詢發現盤已更新了

[[email protected] ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root  100G   38G   63G  38% /
devtmpfs             1.9G     0  1.9G   0% /dev
tmpfs                1.9G     0  1.9G   0% /dev/shm
tmpfs                1.9G  8.6M  1.9G   1% /run
tmpfs                1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1           1014M  139M  876M  14% /boot
/dev/mapper/cl-home   19G  141M   19G   1% /home
tmpfs                378M     0  378M   0% /run/user/0