CentOS磁盘在根目录下扩容(无卷组情况下)【转】

两大步:一、sda2扩容;二、sda3移到最后,重设交换分区

一、扩容

查看磁盘分区情况,sda2挂载在根目录下,新扩容增加的sda5挂在在/data下

[root@centos7 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   30G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0   10G  0 part /
├─sda3   8:3    0    4G  0 part [SWAP]
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0   15G  0 part /data
sr0     11:0    1  4.4G  0 rom  
现在想把sda5同样挂载在根目录下
解决方法:

删除sda2,再重建sda2(注意:删除后不要退出,紧接着重建,注意重建后的起始位置)

删除sda2然后重建

[root@centos7 ~]# fdisk /dev/sda
 
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
 
Command (m for help): p
 
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000a4420
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    23070719    10485760   83  Linux
/dev/sda3        23070720    31459327     4194304   82  Linux swap / Solaris
/dev/sda4        31459328    62914559    15727616    5  Extended
/dev/sda5        31461376    62914559    15726592   83  Linux
 
Command (m for help): d
Partition number (1-5, default 5): 5
Partition 5 is deleted
 
Command (m for help): d
Partition number (1-4, default 4): 4
Partition 4 is deleted
 
Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 is deleted
 
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted
 
Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2099200-62914559, default 2099200): 
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-62914559, default 62914559): 54525951
Partition 2 of type Linux and of size 25 GiB is set
 
Command (m for help): p
 
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000a4420
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    54525951    26213376   83  Linux
 
Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (54525952-62914559, default 54525952): 
Using default value 54525952
Last sector, +sectors or +size{K,M,G} (54525952-62914559, default 62914559): 
Using default value 62914559
Partition 3 of type Linux and of size 4 GiB is set
 
Command (m for help): p
 
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000a4420
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    54525951    26213376   83  Linux
/dev/sda3        54525952    62914559     4194304   83  Linux
 
Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'
 
Command (m for help): p
 
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000a4420
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    54525951    26213376   83  Linux
/dev/sda3        54525952    62914559     4194304   82  Linux swap / Solaris
 
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.
编辑fstab文件夹vi /etc/fstab
删除之前挂载的 /data 与swap
meta-data=/dev/sda2              isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=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               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 2621440 to 6553344
执行前后对比,扩容成功
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   30G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0   25G  0 part /
└─sda3   8:3    0    4G  0 part 
sr0     11:0    1  4.4G  0 rom  
二、重设交换分区

1.删除所有SWAP分区

swapoff -a

2.使用fdisk创建交换分区

使用 mkswap 设置交换分区(假设是 /dev/sda3):

mkswap /dev/sdb2

如果没有重启系统,需要先执行partprobe命令

3.启用交换分区:

swapon /dev/sda3

4.添加开机启动 vi/etc/fstab:

/dev/sdb2 swap swap defaults 0 0

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值