Linux磁盘扩容

1.系统盘扩容

# 查看当前磁盘情况
[root@ZX ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 3.8G     0  3.8G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G   12M  3.8G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   26G   16G   11G  60% /
/dev/sda1               1014M  149M  866M  15% /boot
tmpfs                    781M     0  781M   0% /run/user/0

# 查看当前磁盘分区情况
[root@ZX ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x0009f020

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

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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-root: 27.9 GB, 27913093120 bytes, 54517760 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: 3221 MB, 3221225472 bytes, 6291456 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

# 查看当前磁盘分区情况 
[root@ZX ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   29G  0 part 
  ├─centos-root 253:0    0   26G  0 lvm  /
  └─centos-swap 253:1    0    3G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk 
sr0              11:0    1  4.4G  0 rom
# 磁盘空间50G,但两块分区合计只有30G,剩余20G为新扩容空间

# 创建新分区
[root@ZX ~]# 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): 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): 
First sector (62914560-104857599, default 62914560): 
Using default value 62914560
Last sector, +sectors or +size{K,M,G} (62914560-104857599, default 104857599): 
Using default value 104857599
Partition 3 of type Linux and of size 20 GiB is set

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.

# 重启服务器
[root@ZX ~]# reboot

# 创建pv
[root@ZX ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.

# 查看pv
[root@ZX ~]# pvs

# 查看vg组
[root@ZX ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  centos   1   2   0 wz--n- <29.00g    0

#  扩展vg
[root@ZX ~]# vgextend centos /dev/sda3 
  Volume group "centos" successfully extended
You have new mail in /var/spool/mail/root

# 查看扩展后的vg组
[root@ZX ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree  
  centos   2   2   0 wz--n- 48.99g <20.00g

# 查看lvs
[root@ZX ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- <26.00g                                                    
  swap centos -wi-ao----   3.00g
# lv大小未发生变化  

# 扩展lv
# 扩展大小 < 新增大小
[root@ZX ~]# lvextend -L +19.8G /dev/mapper/centos-root 
  Rounding size to boundary between physical extents: 19.80 GiB.
  Size of logical volume centos/root changed from <26.00 GiB (6655 extents) to <45.80 GiB (11724 extents).
  Logical volume centos/root successfully resized.

# 查看lvs
[root@ZX ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- <45.80g                                                    
  swap centos -wi-ao----   3.00g  
# lv大小已发生改变

# 查看当前磁盘情况,根目录大小未发生改变
[root@ZX ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 3.8G     0  3.8G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G   12M  3.8G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   26G   16G   11G  60% /
/dev/sda1               1014M  149M  866M  15% /boot
tmpfs                    781M     0  781M   0% /run/user/0

# 系统重新读取大小
# xfs_growfs 由文件夹格式化类型控制,查看文件夹格式化类型:df -Th

[root@ZX ~]# xfs_growfs /dev/mapper/centos-root 
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1703680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=6814720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=3327, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 6814720 to 12005376

# 查看当前磁盘情况,根目录大小发生改变
[root@ZX ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 3.8G     0  3.8G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G   12M  3.8G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   46G   16G   31G  34% /
/dev/sda1               1014M  149M  866M  15% /boot
tmpfs                    781M     0  781M   0% /run/user/0


# 分区信息显示正常
[root@ZX ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x0009f020

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    62914559    30407680   8e  Linux LVM
/dev/sda3        62914560   104857599    20971520   83  Linux

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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-root: 49.2 GB, 49174020096 bytes, 96043008 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: 3221 MB, 3221225472 bytes, 6291456 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



[root@ZX ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   29G  0 part 
│ ├─centos-root 253:0    0 45.8G  0 lvm  /
│ └─centos-swap 253:1    0    3G  0 lvm  [SWAP]
└─sda3            8:3    0   20G  0 part 
  └─centos-root 253:0    0 45.8G  0 lvm  /
sdb               8:16   0   20G  0 disk 
sr0              11:0    1  4.4G  0 rom

2.分区、格式化、挂载

分区、格式化、挂载
[root@ZX ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   29G  0 part 
│ ├─centos-root 253:0    0 45.8G  0 lvm  /
│ └─centos-swap 253:1    0    3G  0 lvm  [SWAP]
└─sda3            8:3    0   20G  0 part 
  └─centos-root 253:0    0 45.8G  0 lvm  /
sdb               8:16   0   20G  0 disk 
sr0              11:0    1  4.4G  0 rom  

2.1 分区

# 1、对磁盘分区
# fdisk /dev/sdh >n(新建)>p(主分区)>1(盘符) t(修改ID) 8e >w(保存退出)

# 2T 以上:
# parted /dev/sd* > mklabel > gpt > yes > p(查看磁盘大小) > mkpart > part1 > 回车 > 1 > *G > toggle 1 lvm > quit(保存退出)

[root@ZX ~]# fdisk /dev/sdb 
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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x47246933.

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

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

Calling ioctl() to re-read partition table.
Syncing disks.

2.2 格式化

[root@ZX ~]# mkfs.xfs /dev/sdb1 
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=1310656 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=5242624, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

2.3 挂载

[root@ZX ~]# mkdir /data
[root@ZX /]# mount /dev/sdb1 data/
[root@ZX /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 3.8G     0  3.8G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G   12M  3.8G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   46G   16G   31G  34% /
/dev/sda1               1014M  149M  866M  15% /boot
tmpfs                    781M     0  781M   0% /run/user/0
/dev/sdb1                 20G   33M   20G   1% /data

# 设置开机自动挂载
echo '/dev/sdb1 /data xfs defaults 0 0' >> /etc/fstab

3.将分区制作成卷

# 查看当前磁盘分区情况
[root@ZX ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   29G  0 part 
│ ├─centos-root 253:0    0 45.8G  0 lvm  /
│ └─centos-swap 253:1    0    3G  0 lvm  [SWAP]
└─sda3            8:3    0   20G  0 part 
  └─centos-root 253:0    0 45.8G  0 lvm  /
sdb               8:16   0   40G  0 disk 
└─sdb1            8:17   0   20G  0 part /data
sr0              11:0    1  4.4G  0 rom

# 新建分区
[root@ZX ~]# fdisk /dev/sdb
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): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): 
Using default response p
Partition number (2-4, default 2): 
First sector (41943040-83886079, default 41943040): 
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-83886079, default 83886079): 
Using default value 83886079
Partition 2 of type Linux and of size 20 GiB is set

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.

# 重启服务器
[root@ZX ~]# reboot

3.1 pv

# 扫描系统PV:pvscan
# 创建pv
[root@ZX ~]# pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created.

# 查看pv
[root@ZX /]# pvdisplay  
  --- Physical volume ---
  PV Name               /dev/sdb2
  VG Name               data1
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               5119
  Allocated PE          0
  PV UUID               ix0iJw-mziL-OUvC-ig8c-YYw5-Lo0r-zLt2iL

3.2 vg

# 扫描系统vg:vgscan
# 创建vg
[root@ZX /]# vgcreate data1 /dev/sdb2 
  Volume group "data1" successfully created
 
# 查看vg
[root@ZX /]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  data1    1   0   0 wz--n- <20.00g <20.00g
  
[root@ZX /]# vgdisplay
  --- Volume group ---
  VG Name               data1
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <20.00 GiB
  PE Size               4.00 MiB
  Total PE              5119
  Alloc PE / Size       0 / 0   
  Free  PE / Size       5119 / <20.00 GiB
  VG UUID               imtNUy-SyFb-h0Hc-DJen-Gkse-dx5g-u0JJRT`

3.3 lv

# 扫描系统lv:lvscan
# 创建lv
lvcreate -l 5119 -n lvdata1 data1 (5119是VG中PE的个数)
[root@ZX /]# lvcreate -l 5119 -n lvdata1 data1
  Logical volume "lvdata1" created.

# 查看lv
[root@ZX /]# lvdisplay    
  --- Logical volume ---
  LV Path                /dev/data1/lvdata1
  LV Name                lvdata1
  VG Name                data1
  LV UUID                m1mkaE-d7mW-kBtj-cySZ-C6fv-deV5-4PFlbU
  LV Write Access        read/write
  LV Creation host, time ZX, 2023-02-13 14:47:57 +0800
  LV Status              available
  # open                 0
  LV Size                <20.00 GiB
  Current LE             5119
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

[root@ZX /]# lvs
  LV      VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lvdata1 data1  -wi-a----- <20.00g

# 格式化刚刚创建的LV
[root@ZX /]# mkfs -t xfs /dev/data1/lvdata1 
meta-data=/dev/data1/lvdata1     isize=512    agcount=4, agsize=1310464 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=5241856, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

# 设置开机自动挂载
echo '/dev/data1/lvdata1 /data xfs defaults 0 0' >> /etc/fstab

4.压缩home,扩容root

# 安装 xfsdump 对 xfs 文件系统进行备份和还原
[root@db ~]# yum -y install xfsdump
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.ustc.edu.cn
 * updates: mirrors.bfsu.edu.cn
base                                                                                              | 3.6 kB  00:00:00     
extras                                                                                            | 2.9 kB  00:00:00     
updates                                                                                           | 2.9 kB  00:00:00     
updates/7/x86_64/primary_db                                                                       |  19 MB  00:00:02     
Resolving Dependencies
--> Running transaction check
---> Package xfsdump.x86_64 0:3.1.7-2.el7_9 will be installed
--> Processing Dependency: attr >= 2.0.0 for package: xfsdump-3.1.7-2.el7_9.x86_64
--> Running transaction check
---> Package attr.x86_64 0:2.4.46-13.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================
 Package                    Arch                      Version                           Repository                  Size
============================================================================================
Installing:
 xfsdump                    x86_64                    3.1.7-2.el7_9                     updates                    308 k
Installing for dependencies:
 attr                       x86_64                    2.4.46-13.el7                     base                        66 k
Transaction Summary
============================================================================================
Install  1 Package (+1 Dependent package)
Total download size: 374 k
Installed size: 1.1 M
Downloading packages:
(1/2): attr-2.4.46-13.el7.x86_64.rpm                                                              |  66 kB  00:00:00     
(2/2): xfsdump-3.1.7-2.el7_9.x86_64.rpm                                                           | 308 kB  00:00:00     
--------------------------------------------------------------------------------------------
Total                                                                                    1.0 MB/s | 374 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : attr-2.4.46-13.el7.x86_64                                                                             1/2 
  Installing : xfsdump-3.1.7-2.el7_9.x86_64                                                                          2/2 
  Verifying  : attr-2.4.46-13.el7.x86_64                                                                             1/2 
  Verifying  : xfsdump-3.1.7-2.el7_9.x86_64                                                                          2/2
Installed:
  xfsdump.x86_64 0:3.1.7-2.el7_9                                                             
Dependency Installed:
  attr.x86_64 0:2.4.46-13.el7                                                               
Complete!

# 查询当前磁盘情况
[root@db ~]# df -h
Filesystem                  Size  Used Avail Use% Mounted on
devtmpfs                    3.8G     0  3.8G   0% /dev
tmpfs                       3.9G     0  3.9G   0% /dev/shm
tmpfs                       3.9G   12M  3.8G   1% /run
tmpfs                       3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/centos_db-root   36G   17G   20G  47% /
/dev/sda1                  1014M  151M  864M  15% /boot
/dev/mapper/centos_db-home   18G   33M   18G   1% /home
tmpfs                       781M     0  781M   0% /run/user/0

# 查询home下是否存在文件
[root@db ~]# cd /home
[root@db home]# ls
db  oracle

# 查询home下是否存在进程
[root@db home]# ps -ef | grep /home
root       9633   9263  0 10:52 pts/0    00:00:00 grep --color=auto /home

# 备份/home到根目录下
[root@db home]#  cd
[root@db ~]# xfsdump -f /home_bak.xfsdump /home
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
 ============================= dump label dialog ==============================
please enter label for this dump session (timeout in 300 sec)
 -> home bak
session label entered: "home bak"
 --------------------------------- end dialog ---------------------------------
xfsdump: level 0 dump of db:/home
xfsdump: dump date: Tue Feb 14 10:51:37 2023
xfsdump: session id: 9f07954a-345e-45ae-b645-03a5eab69663
xfsdump: session label: "home bak"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 52672 bytes
xfsdump: /var/lib/xfsdump/inventory created
 ============================= media label dialog =============================
please enter label for media in drive 0 (timeout in 300 sec)
 -> bak  
media label entered: "bak"
 --------------------------------- end dialog ---------------------------------
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 30184 bytes
xfsdump: dump size (non-dir files) : 4320 bytes
xfsdump: dump complete: 11 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /home_bak.xfsdump OK (success)
xfsdump: Dump Status: SUCCESS

# 切换至根目录,取消home挂载
[root@db home]# cd /
[root@db /]# umount /home

# 为home指定新的磁盘大小(数值表示预留大小,不是缩减大小)
[root@db /]# lvreduce -L 10G /dev/mapper/centos_db-home 
  WARNING: Reducing active logical volume to 10.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce centos_db/home? [y/n]: y
  Size of logical volume centos_db/home changed from <17.39 GiB (4451 extents) to 10.00 GiB (2560 extents).
  Logical volume centos_db/home successfully resized.
 
# 将压缩的空间全部分配给root
[root@db /]# lvextend -l +100%FREE /dev/mapper/centos_db-root 
  Size of logical volume centos_db/root changed from <35.61 GiB (9116 extents) to <43.00 GiB (11007 extents).
  Logical volume centos_db/root successfully resized.

# 延展xfs空间
[root@db /]# xfs_growfs /dev/mapper/centos_db-root 
meta-data=/dev/mapper/centos_db-root isize=512    agcount=4, agsize=2333696 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=9334784, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4558, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 9334784 to 11271168

# 格式化home
[root@db /]# mkfs.xfs -f /dev/mapper/centos_db-home 
meta-data=/dev/mapper/centos_db-home isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2621440, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

# 挂载home
[root@db /]# mount /dev/mapper/centos_db-home /home

# 还原home
[root@db /]# xfsrestore -f /home_bak.xfsdump /home
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.7 (dump format 3.0) - type for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: dump description: 
xfsrestore: hostname: db
xfsrestore: mount point: /home
xfsrestore: volume: /dev/mapper/centos_db-home
xfsrestore: session time: Tue Feb 14 10:51:37 2023
xfsrestore: level: 0
xfsrestore: session label: "home bak"
xfsrestore: media label: "bak"
xfsrestore: file system id: 338bbebf-3fec-414f-b504-9e34a5c2923f
xfsrestore: session id: 9f07954a-345e-45ae-b645-03a5eab69663
xfsrestore: media id: dd6d9d25-bf19-42e4-a797-dd316c10ba05
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 4 directories and 10 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore:   stream 0 /home_bak.xfsdump OK (success)
xfsrestore: Restore Status: SUCCESS

# 查看磁盘情况
[root@db /]# df -h
Filesystem                  Size  Used Avail Use% Mounted on
devtmpfs                    3.8G     0  3.8G   0% /dev
tmpfs                       3.9G     0  3.9G   0% /dev/shm
tmpfs                       3.9G   12M  3.8G   1% /run
tmpfs                       3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/centos_db-root   43G   17G   27G  39% /
/dev/sda1                  1014M  151M  864M  15% /boot
tmpfs                       781M     0  781M   0% /run/user/0
/dev/mapper/centos_db-home   10G   33M   10G   1% /home

# 查看数据情况
[root@db /]# cd /home
[root@db home]# ls
db  oracle

你可能感兴趣的:(虚拟机,linux,运维,服务器)