新安装的Linux centos 7配置网络和合并分区


新安装的centos,默认会划分两个分区,且网络是关闭状态的,这个镜像有点坑,因为Centos Basic默认版本网络非开机自启动,需要配置网络网关,还有合并分区:

配置网络

编辑网卡(ifcfg-*看你具体的网卡)

vi /etc/sysconfig/network-scripts/ifcfg-enp3s0

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
IPV6_PRIVACY=no
NAME=enp2s0
UUID=07286cf2-e2c5-4210-af21-28a3e6e9a344
DEVICE=enp2s0
ONBOOT=yes
IPADDR=192.168.1.7
GATEWAY=192.168.1.252
NETMASK=255.255.255.0

其它都可以不动,主要就是动IP获取方式DHCP、开启启动为yes,设置静态IP,网关、子网掩码即可;
域名解析DNS配置在/etc/resolv.conf,一般会由路由自动获取即可;

/etc/init.d/network restartservice network restart重启网络

合并home分区到root根分区

默认的分区

[root@apollodev ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 3.8G     0  3.8G   0% /dev
tmpfs                    3.8G     0  3.8G   0% /dev/shm
tmpfs                    3.8G  9.3M  3.8G   1% /run
tmpfs                    3.8G     0  3.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root   50G  1.9G   49G   4% /
/dev/sda1               1014M  163M  852M  17% /boot
/dev/mapper/centos-home  165G   33M  165G   1% /home
tmpfs                    770M     0  770M   0% /run/user/0

解除挂载(强行)

umount /home(强行umount -l /home

删除分区(强行)

lvremove -f /dev/mapper/centos-home(强行lvremove -f /dev/mapper/centos-home

如果不行就重启重复上面解除挂载和删除分区,还不行就在/etc/fstab把默认的home注释后重启;

拓展分区

lvextend -r -l +100%FREE /dev/mapper/centos-root

重新划分/root分区的磁盘空间

xfs_growfs /dev/mapper/centos-root

重要重要重要

重要重要重要:去掉/dev/mapper/centos-home的挂载,在/etc/fstab注释掉该行不存在的分区挂载,否则重启会进入紧急模式无法远程,又得搬显示器去输密码调试删除改行;

重新查看磁盘和挂载情况

[root@apollodev ~]# fdisk -l

Disk /dev/sda: 240.1 GB, 240065183744 bytes, 468877312 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: 0x000a770b

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

Disk /dev/mapper/centos-root: 230.7 GB, 230665748480 bytes, 450519040 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: 8321 MB, 8321499136 bytes, 16252928 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@apollodev ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 3.8G     0  3.8G   0% /dev
tmpfs                    3.8G     0  3.8G   0% /dev/shm
tmpfs                    3.8G  9.1M  3.8G   1% /run
tmpfs                    3.8G     0  3.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root  215G  1.5G  214G   1% /
/dev/sda1               1014M  198M  817M  20% /boot
tmpfs                    770M     0  770M   0% /run/user/0

打完收工


原文链接:https://blog.yongit.com/note/1448797.html