麒麟Linux系统根目录与单目录扩容详解,适用于大多数的centeros系统

最近有不少在linux如何在根目录进行扩容找不到有效资料,经过不懈努力,找到了一种对centeros类型(kylin系统)行而有效的扩容方式。
1、先查看磁盘空间大小,使用df -h 命令,查看挂载根目录节点(/)的/dev/mapper/kylin-root的容量

root@/# df -h
文件系统            容量 已用 可用 已用% 挂载点
/dev/mapper/kylin-root  28G  23G 3.3G  88% /
none              4.0K   0 4.0K  0% /sys/fs/cgroup
udev              3.9G 4.0K 3.9G  1% /dev
tmpfs             799M 384K 799M  1% /run
none              5.0M   0 5.0M  0% /run/lock
none              3.9G   0 3.9G  0% /run/shm
none              100M   0 100M  0% /run/user
/dev/vda1           236M  37M 188M  17% /boot

2、增加磁盘空间,可采用VM虚拟机增加方式或其他方式,为其增加容量
3、使用fdisk -l命令查看磁盘信息。当看到第一行Disk /dev/xvda与实际df -h显示内容不符时,说明增加磁盘成功了。

root@/# fdisk -l
 
Disk /dev/xvda: 161.1 GB, 161061273600 bytes
16 heads, 63 sectors/track, 312076 cylinders, total 314572800 sectors
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001a023
 
  设备 启动   起点     终点   块数  Id 系统
/dev/xvda1  *    2048   499711   248832  83 Linux
/dev/xvda2     501758  62912511  31205377  5 扩展
/dev/xvda3     501760  62912511  31205376  83 Linux
 
Disk /dev/mapper/kylin-root: 29.8 GB, 29804724224 bytes
255 heads, 63 sectors/track, 3623 cylinders, total 58212352 sectors
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
 
Disk /dev/mapper/kylin-root doesn't contain a valid partition table
 
Disk /dev/mapper/kylin-swap_1: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
 
Disk /dev/mapper/kylin-swap_1 doesn't contain a valid partition table```

4.使用fdisk /dev/xvda, 创建新分区

```bash
root@ / # fdisk /dev/xvda
 
命令(输入 m 获取帮助): m
命令操作
  a  toggle a bootable flag
  b  edit bsd disklabel
  c  toggle the dos compatibility flag
  d  delete a partition
  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)
 
命令(输入 m 获取帮助): n #new 新分区
Partition type:
  p  primary (1 primary, 1 extended, 2 free)
  l  logical (numbered from 3)
Select (default p): p  #选择主分区
分区号 (1-4,默认为 3): 3 #分区序号
起始 sector (499712-314572799,默认为 499712): #分区开始回车默认
将使用默认值 499712
Last sector, +扇区 or +size{K,M,G} (499712-501757,默认为 501757): 
将使用默认值 501757
 
命令(输入 m 获取帮助): t  #修改分区格式
分区号 (1-5): 3  #修改分区号
Hex code (type L to list codes): 8e #格式选择8e  linux LVM
Changed system type of partition 4 to 8e (Linux LVM)
 
命令(输入 m 获取帮助): p #显示分区信息
 
Disk /dev/xvda: 161.1 GB, 161061273600 bytes
16 heads, 63 sectors/track, 312076 cylinders, total 314572800 sectors
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001a023
 
  设备 启动   起点     终点   块数  Id 系统
/dev/xvda1  *    2048   499711   248832  83 Linux
/dev/xvda2     501758  62912511  31205377  5 扩展
/dev/xvda3    62912512  314572799  125830144  8e Linux LVM
Partition table entries are not in disk order
命令(输入 m 获取帮助): w #保存信息
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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.`

注意事项:一定要改变分区方式,即t修改分区格式,在linux扩容中,只有LVM(8e格式)可以被添加进根目录中,否则不生效
5. 重启Linux操作系统,使用reboot命令。
6. 创建物理卷,使用pvcreate /dev/xvda3命令。

root@/:~# pvcreate /dev/xvda3
 Physical volume "/dev/xvda3" successfully created

7.查看新建的物理卷和大小,使用pvdisplay命令。

root@ubuntu14:~# pvdisplay
 --- Physical volume ---
 PV Name        kylin
 PV Size        29.76 GiB / not usable 2.00 MiB
 Allocatable      yes (but full)
 PE Size        4.00 MiB
 Total PE       7618
 Free PE        0
 Allocated PE     7618
 PV UUID        XR32TY-aRQC-IQC6-oCx7-aa9X-KdJe-bHmaBd
 "/dev/xvda3"        /dev/mapper/kylin-root
 VG Name is a new physical volume of "120.00 GiB"
 --- NEW Physical volume ---
 PV Name        /dev/xvda3
 VG Name        
 PV Size        120.00 GiB
 Allocatable      NO
 PE Size        0  
 Total PE       0
 Free PE        0
 Allocated PE     0
 PV UUID        MVK0IT-LDgP-eWwZ-fzQM-tdyY-kRQ-nbk122
  1. 将添加新的物理卷,加载到kylin卷组,使用vgextend kylin /dev/xvda3命令。
root@ubuntu14:~# vgextend kylin /dev/xvda3
Volume group "kylin" successfully extended```

9. 查看卷组信息,使用vgdisplay命令。

```bash
root@ubuntu14:~# vgdisplay         
 --- Volume group ---
 VG Name        kylin
 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        149.76 GiB
 PE Size        4.00 MiB
 Total PE       38338
 Alloc PE / Size    7618 / 29.76 GiB
 Free PE / Size    30720 / 120.00 GiB
 VG UUID        cq2Z6G-P6j1-S2gM-mibz-d63V-NjkS-dHYe7D

10.增加kylin大小,增加120G。使用lvresize -L +120G /dev/mapper/kylin-root命令。

root@/:~# lvresize -L +120G /dev/mapper/kylin-root
 Extending logical volume root to 147.76 GiB
 Logical volume root successfully resized
  1. 重新识别kylin大小,使用resize2fs /dev/mapper/kylin–vg-root命令。
root@/:~# xfs_growfs /dev/mapper/kylin-root 
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1113856 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4455424, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
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 4455424 to 30668800

注意事项:此处kylin系统可能未包含lvresize命令,我们采用其他方式(xfs_growfs)进行重新读取
12.查看扩容后的大小 ,使用df -h命令。

root@ubuntu14:~# df -h
文件系统            容量 已用 可用 已用% 挂载点
/dev/mapper/kylin--vg-root 146G  23G 117G  17% /
none              4.0K   0 4.0K  0% /sys/fs/cgroup
udev              3.9G 4.0K 3.9G  1% /dev
tmpfs             799M 388K 799M  1% /run
none              5.0M   0 5.0M  0% /run/lock
none              3.9G   0 3.9G  0% /run/shm
none              100M   0 100M  0% /run/user
/dev/xvda1           236M  37M 188M  17% /boot

由于一些原因无法展示真实的文件数据,但大体思路与步骤是没有问题的,欢迎指教。其余根目录扩容方式与该方式相同,无非就是xvda换成了其他的文件系统命名,像sdb、vda等等,依次类同就不一一叙述了。

如果我们不想对根目录进行扩容,仅对单目录进行扩容,应该如何操作呢?
前接第五步,reboot重启,为表示区别,在对应序号后添加.1的编号
6.1 mkfs.ext2 /dev/xvda3 格式化
7.1 在根目录下创建 disk文件夹
8.1 在vim中修改/etc/fstab文件,加入
/dev/xvda3 /disk default 0 0
一行,并保存,实现开机自动mount
9.1 至此,新加载的磁盘空间将在该文件夹下进行体现
注意事项:尽量不使用存在的文件夹作为加载对象,因为加载后文件夹会清空,采用该方式切记做好备份

参考网址:Linux系统扩容根目录磁盘空间的操作方法

linux系统根目录扩容

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值