21.7 C
Texas
Melhttp://www.osradar.com
Guru Unix /Linux and GNU supporter

Resizing the boot partition in linux

Last weeks I was confronted with resizing the boot partitioning issues on my server, I want to explain to you how to resize boot partition in Linux.

/boot partition cannot be an LVM devices is because when the system boots, it first searches for /boot/vmlinuz, and at this time, lvm cannot be recognized because there is no module for lvm loaded at this time. So, the /boot partition can not be a lvm partition. ( redhat)

How to resize the boot partition in Centos / Redhat 7/8 ?

Note: this document should also work for another Linux distribution like Debian / Gentoo/ OpenSUSE.

I’m testing this solution in my VM.

- Advertisement -

My boot partition is 1Gb. Let’s do an example how to expand this partition to 2 GB for example.

You can use fdisk or parted commands to create another partition. Else you have to add extra storage like sdb or sdc.

In my situation i have add new storage /deb/sdb

Below is the command that you need to run to scan the host devices so it will show the new hard disk connected.

#echo "- - -" >> /sys/class/scsi_host/host_$i/scan
#fdisk  -l   | grep  dev
Disk /dev/sdb: 3 GiB, 3221225472 bytes, 6291456 sectors
Disk /dev/sda: 14.1 GiB, 15157231616 bytes, 29603968 sectors
/dev/sda1  *       2048  2099199  2097152    1G 83 Linux
/dev/sda2       2099200 29603839 27504640 13.1G 8e Linux LVM
Disk /dev/mapper/cl-root: 9.1 GiB, 9726590976 bytes, 18997248 sectors
Disk /dev/mapper/cl-swap: 1.4 GiB, 1518338048 bytes, 2965504 sectors

Lets create partition sdb1 (2GB) on Linux Disk

[root@osradar-lvm ~]# fdisk   /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (1-4, default 1):
First sector (2048-6291455, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-6291455, default 6291455): +2G

Created a new partition 1 of type 'Linux' and of size 2 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@osradar-lvm ~]#

Create ext4 file system file system on sdb1

[root@osradar-lvm ~]# mkfs.ext4 /dev/sdb1 
mke2fs 1.44.6 (5-Mar-2019) Creating filesystem with 524288 4k blocks and 131072 inodes Filesystem UUID: 3303ecb2-d97c-4dae-b6f6-157bc82c9b96 Superblock backups stored on blocks:         32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done 
[root@osradar-lvm ~]# 

So, open terminal or shell prompt and type the following dd command:

[root@osradar-lvm ~]# dd if=/dev/sda1 of=/dev/sdb1 bs=512 conv=noerror,sync
[root@osradar-lvm ~]# dd if=/dev/sda1 of=/dev/sdb1 bs=20M conv=noerror,sync
51+1 records in
52+0 records out
1090519040 bytes (1.1 GB, 1.0 GiB) copied, 6.22216 s, 175 MB/s

The disk sda1 will be cloned to disk 2 even the size 2 will be the same size (don’t panic)

[root@osradar-lvm ~]# umount  /boot #( don't worry,  nothing will hapen to your system even your server is ON) 
[root@osradar-lvm ~]# umount  /boot 

Check the file system ext4 on /deb/sdb1

e2fsck is used to check the ext2/ext3/ext4 family of file systems. For ext3 and ext4 filesystems that use a journal, if the system has been shut down uncleanly without any errors, normally, after replaying the committed transactions in the journal, the file system should be marked as clean

Resize to the full size (2GB) with command resize2fs

Try to mount manually the /dev/sdb2 to /boot partition

[root@osradar-lvm ~]# mount -t ext4 /dev/sdb1 /boot

Very fine. Now add the line to /etc/fstab to make this permanent with next reboot.

[root@osradar-lvm ~]# vi  /etc/fstab

Normally you are Done no need to reboot but if u still have some doubts you may reboot your server or machine

Reboot your server

[root@osradar-lvm ~]# reboot

Cheers!!

Please join our Telegram Channel and share this post.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article