linux根分区扩容教程,Linux扩容/根分区(vmware)

Linux扩容/根分区(vmware)

早上发现开发测试构建失败,如图

谷歌一下磁盘不够啦,小问题,删了一些没用的,释放后欧了,原来/分区是38G,然后我打算扩容到100G,无奈看了下剩余不够,就到70吧.

1.查看现有的分区大小

[root@jenkins ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 38G 15G 24G 38% /

devtmpfs 2.0G 0 2.0G 0% /dev

tmpfs 2.0G 0 2.0G 0% /dev/shm

tmpfs 2.0G 12M 2.0G 1% /run

tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup

/dev/sda1 1014M 127M 888M 13% /boot

tmpfs 394M 0 394M 0% /run/user/0

2.关机增加磁盘大小为70G

3.查看磁盘扩容后的状态

[root@jenkins ~]# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 70G 0 disk

├─sda1 8:1 0 1G 0 part /boot

├─sda2 8:2 0 1G 0 part [SWAP]

└─sda3 8:3 0 68G 0 part /

sr0 11:0 1 4.3G 0 rom

[root@jenkins ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 38G 15G 24G 38% /

devtmpfs 2.0G 0 2.0G 0% /dev

tmpfs 2.0G 0 2.0G 0% /dev/shm

tmpfs 2.0G 12M 2.0G 1% /run

tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup

/dev/sda1 1014M 127M 888M 13% /boot

tmpfs 394M 0 394M 0% /run/user/0

#现在磁盘总大小为70G,/分区为38G

4.进行分区扩展磁盘,记住根分区起始位置和结束位置(start是默认),删除分区

[root@jenkins ~]# fdisk /dev/sda

Welcome to fdisk (util-linux 2.23.2).

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: 75.2 GB, 75161927680 bytes, 146800640 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: 0x000a9eca

Device Boot Start End Blocks Id System

/dev/sda1 * 2048 2099199 1048576 83 Linux

/dev/sda2 2099200 4196351 1048576 82 Linux swap / Solaris

/dev/sda3 4196352 83886079 39844864 83 Linux

Command (m for help): d #删除分区,但不删除数据

Partition number (1-3, default 3): 1

Partition 1 is deleted

Command (m for help): d

Partition number (2,3, default 3): 2

Partition 2 is deleted

Command (m for help): d

Selected partition 3

Partition 3 is deleted

Command (m for help): p

Disk /dev/sda: 75.2 GB, 75161927680 bytes, 146800640 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: 0x000a9eca

Device Boot Start End Blocks Id System

5.创建原来的3个分区(start是默认的)

Command (m for help): n

Partition type:

p primary (0 primary, 0 extended, 4 free)

e extended

Select (default p): p

Partition number (1-4, default 1): 1

First sector (2048-146800639, default 2048): #Enter

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-146800639, default 146800639): +1G #分区大小

Partition 1 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sda: 75.2 GB, 75161927680 bytes, 146800640 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: 0x000a9eca

Device Boot Start End Blocks Id System

/dev/sda1 2048 2099199 1048576 83 Linux

Command (m for help): p

Disk /dev/sda: 75.2 GB, 75161927680 bytes, 146800640 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: 0x000a9eca

Device Boot Start End Blocks Id System

/dev/sda1 2048 2099199 1048576 83 Linux

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-146800639, default 2099200):

Using default value 2099200

Last sector, +sectors or +size{K,M,G} (2099200-146800639, default 146800639): +1G

Partition 2 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sda: 75.2 GB, 75161927680 bytes, 146800640 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: 0x000a9eca

Device Boot Start End Blocks Id System

/dev/sda1 2048 2099199 1048576 83 Linux

/dev/sda2 2099200 4196351 1048576 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 (4196352-146800639, default 4196352):

Using default value 4196352

Last sector, +sectors or +size{K,M,G} (4196352-146800639, default 146800639):

Using default value 146800639

Partition 3 of type Linux and of size 68 GiB is set

Command (m for help): p

Disk /dev/sda: 75.2 GB, 75161927680 bytes, 146800640 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: 0x000a9eca

Device Boot Start End Blocks Id System

/dev/sda1 2048 2099199 1048576 83 Linux

/dev/sda2 2099200 4196351 1048576 83 Linux

/dev/sda3 4196352 146800639 71302144 83 Linux

Command (m for help): wq

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.

#这步操作后,不要reboot,否则就起不来了

6.刷新分区并查看分区状态

[root@jenkins ~]# partprobe /dev/sda

[root@jenkins ~]# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 70G 0 disk

├─sda1 8:1 0 1G 0 part /boot

├─sda2 8:2 0 1G 0 part [SWAP]

└─sda3 8:3 0 68G 0 part /

sr0 11:0 1 4.3G 0 rom

[root@jenkins ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 38G 15G 24G 38% /

devtmpfs 2.0G 0 2.0G 0% /dev

tmpfs 2.0G 0 2.0G 0% /dev/shm

tmpfs 2.0G 12M 2.0G 1% /run

tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup

/dev/sda1 1014M 127M 888M 13% /boot

tmpfs 394M 0 394M 0% /run/user/0

7.刷新/分区并查看状态

这里先查看自己的文件系统(cat /etc/fstab)

xfs_growfs 针对的文件系统xfs

resize2fs 针对文件系统ext2 ext3 ext4

[root@jenkins ~]# xfs_growfs /dev/sda3

meta-data=/dev/sda3 isize=512 agcount=4, agsize=2490304 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0 spinodes=0

data = bsize=4096 blocks=9961216, imaxpct=25

= sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1

log =internal bsize=4096 blocks=4863, version=2

= sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

data blocks changed from 9961216 to 17825536

[root@jenkins ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 68G 15G 54G 21% /

devtmpfs 2.0G 0 2.0G 0% /dev

tmpfs 2.0G 0 2.0G 0% /dev/shm

tmpfs 2.0G 12M 2.0G 1% /run

tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup

/dev/sda1 1014M 127M 888M 13% /boot

tmpfs 394M 0 394M 0% /run/user/0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值