linux根分区扩容

[root@localhost:~/Desktop] # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_test01-lv_root
                       16G  3.8G   11G  26% /
tmpfs                1000M  100K 1000M   1% /dev/shm
/dev/sda1             485M   30M  430M   7% /boot
/dev/sr0              3.2G  3.2G     0 100% /mnt
[root@localhost:~/Desktop] # vim /root/.bash_profile
[root@localhost:~/Desktop] # source /root/.bash_profile

[root@localhost:~/Desktop] # ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda4

[root@localhost:~/Desktop] # fdisk /dev/sda

[root@localhost:~/Desktop] # fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)

Command action
   e   extended
   p   primary partition (1-4)
p
Selected partition 3
First cylinder (3264-3916, default 3264): 3
Value out of range.
First cylinder (3264-3916, default 3264):
Using default value 3264
Last cylinder, +cylinders or +size{K,M,G} (3264-3916, default 3916):
Using default value 3916

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

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@localhost:~/Desktop] # partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

[root@localhost:~/Desktop] # fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000289b5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM
/dev/sda3            3264        3916     5245222+  8e  Linux LVM
/dev/sda4            2611        3263     5238527+  83  Linux

Partition table entries are not in disk order

Disk /dev/dm-0: 16.8 GB, 16752050176 bytes
255 heads, 63 sectors/track, 2036 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 4194 MB, 4194304000 bytes
255 heads, 63 sectors/track, 509 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/dm-1 doesn't contain a valid partition table

[root@localhost:~/Desktop] # partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

reboot

[root@localhost:~/Desktop] # ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sda4
[root@localhost:~/Desktop] # pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created

[root@localhost:~/Desktop] # vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  vg_test01   1   2   0 wz--n- 19.51g    0

[root@localhost:~/Desktop] # ls /dev/mapper/
control  vg_test01-lv_root  vg_test01-lv_swap


[root@localhost:~/Desktop] # vgextend vg_test01 /dev/sda3
  Volume group "vg_test01" successfully extended
查看可分区为/root分区的lvm的大小

[root@localhost:~/Desktop] # vgdisplay
  --- Volume group ---
  VG Name               vg_test01
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  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               24.51 GiB
  PE Size               4.00 MiB
  Total PE              6274
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       1280 / 5.00 GiB               //LVM大小
  VG UUID               hXjcbq-GvXZ-6WYg-gs0E-oL3G-5e6t-LRZ2li

[root@localhost:~/Desktop] # lvextend -L +4G /dev/mapper/vg_test01-lv_root
  Extending logical volume lv_root to 19.60 GiB
  Logical volume lv_root successfully resized


[root@localhost:~/Desktop] # resize2fs -p /dev/mapper/vg_test01-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_test01-lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/mapper/vg_test01-lv_root to 5138432 (4k) blocks.
The filesystem on /dev/mapper/vg_test01-lv_root is now 5138432 blocks long.


[root@localhost:~/Desktop] # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_test01-lv_root
                       20G  3.8G   15G  21% /
tmpfs                1000M  260K 1000M   1% /dev/shm
/dev/sda1             485M   30M  430M   7% /boot
/dev/sr0              3.2G  3.2G     0 100% /mnt


对比
[root@localhost:~/Desktop] # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_test01-lv_root
                       16G  3.8G   11G  26% /


[root@localhost:~/Desktop] # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_test01-lv_root
                       20G  3.8G   15G  21% /

注意
[root@localhost:~/Desktop] # blkid
/dev/sda1: UUID="7ecaf3b6-0c3d-4513-9a4f-53985a29c3ce" TYPE="ext4"
/dev/sda2: UUID="s0rAen-envt-EC8c-1gLS-DHRE-k0LF-GmIBPM" TYPE="LVM2_member"
/dev/mapper/vg_test01-lv_root: UUID="9945e0de-553b-44d8-bc62-9ed34cab635d" TYPE="ext4"
/dev/mapper/vg_test01-lv_swap: UUID="5abfcee6-754b-4901-a05b-429cda74960e" TYPE="swap"
/dev/sda4: UUID="aae08456-9cb2-4a36-b384-8bc711925116" TYPE="ext4"
/dev/sda3: UUID="m4ZUS4-ZqIm-ldlW-O7lM-1N2z-E6OT-rkCdCk" TYPE="LVM2_member"


格式化分区时
ext4文件格式用resize2fs  -p  
xfs文件格式用xfs_growfs

猜你喜欢

转载自blog.csdn.net/weixin_40018205/article/details/87626152