Linux系统给root扩容

可适用于给其他分区扩容

1,查看分区情况

[root@pxe ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_pxe-lv_root
                       66G   32G   30G  52% /
tmpfs                1004M   76K 1003M   1% /dev/shm
/dev/sda1             477M   41M  411M  10% /boot
/dev/mapper/vg_pxe-lv_home
                       29G   21G  7.2G  74% /home
/dev/sr0              4.1G  4.1G     0 100% /media/Kylin-Server-10

2,我这里是虚拟机,原先硬盘大小是100G,已经满了,直接重新分配为150G.
3, 查看磁盘情况

[root@pxe ~]# fdisk -l

Disk /dev/sda: 161.1 GB, 161061273600 bytes
255 heads, 63 sectors/track, 19581 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: 0x0004d2e5

   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       13055   104344576   8e  Linux LVM

4,首选给新增加的容量,重新分区

[root@pxe ~]# 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)
op^H
Invalid partition number for type `o'
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (13055-19581, default 13055): 13055
Last cylinder, +cylinders or +size{K,M,G} (13055-19581, default 19581): 19581

Command (m for help): p

Disk /dev/sda: 161.1 GB, 161061273600 bytes
255 heads, 63 sectors/track, 19581 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: 0x0004d2e5

   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       13055   104344576   8e  Linux LVM
/dev/sda3           13055       19581    52426782+  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.

5 格式化新分区mkfs.ext4 /dev/sda3

[root@pxe ~]# mkfs.ext4 /dev/sda3
mke2fs 1.41.12 (17-May-2010)

6 创建PV >>>>>这一步没理解是什么意思,我没使用,直接进行的第七步

[root@localhost ~]# pvcreate /dev/sdb1
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdb1.
  Physical volume "/dev/sdb1" successfully created.

7, 查看vgs ,使用vgextend命令,扩展vg

[root@pxe ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  vg_pxe   2   3   0 wz--n- 149.50g 1020.00m
[root@pxe ~]# vgextend vg_pxe /dev/sda3

8 看下lv组, 使用lvextend来扩展lv

[root@pxe ~]# lvs
  LV      VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_home vg_pxe -wi-ao----  29.30g
  lv_root vg_pxe -wi-ao---- 115.27g
  lv_swap vg_pxe -wi-ao----   3.94g
[root@pxe ~]# lvextend -L +50G /dev/mapper/vg_pxe-lv_root

9 ,此时查看分区还没有变化,需要重新读取分区,添加的是xfs系统文件,就使用xfs_growfs(只支持增大) ,如果是ext文件系统,就使用resize2fs(增大和减小都支持),我这边使用的是ext文件,所以使用:

[root@pxe ~]# resize2fs /dev/mapper/vg_pxe-lv_root

10 查看分区状态,df -h.已经扩容完成

[root@pxe ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_pxe-lv_root
                      114G   53G   56G  49% /
tmpfs                1004M  224K 1003M   1% /dev/shm
/dev/sda1             477M   41M  411M  10% /boot
/dev/mapper/vg_pxe-lv_home
                       29G   21G  7.2G  74% /home
/dev/sr0              4.1G  4.1G     0 100% /media/Kylin-Server-10

相关文章

学习编程是顺着互联网的发展潮流,是一件好事。新手如何学习...
IT行业是什么工作做什么?IT行业的工作有:产品策划类、页面...
女生学Java好就业吗?女生适合学Java编程吗?目前有不少女生...
Can’t connect to local MySQL server through socket \'/v...
oracle基本命令 一、登录操作 1.管理员登录 # 管理员登录 ...
一、背景 因为项目中需要通北京网络,所以需要连vpn,但是服...