Resizing the boot partition in linux (Specially in VMs)
/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.
Note: this document should also work for another Linux distribution like Debian / Gentoo/ OpenSUSE.
you can use fdisk
or parted commands to create another partition. Else you have to add extra storage like vdb or sdc
.
In my situation i have add new storage /deb/vdb
Let’s create partition vdb1 (10GB) on Linux Disk
[root@os-lvm ~]# fdisk /dev/vdb
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): +10G
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@os-lvm ~]#
Create ext4 file system file system on vdb1
[root@osradar-lvm ~]# mkfs.ext4 /dev/vdb1
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/vda1 of=/dev/vdb1 bs=512 conv=noerror,sync status=progress
[root@osradar-lvm ~]# dd if=/dev/vda1 of=/dev/vdb1 bs=20M conv=noerror,sync status=progress
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
e2fsck is used to check the ext2/ext3/ext4
family of file systems.[root@osradar-lvm ~]#e2fsck /dev/vdb1
Now Resize to the full size (10GB) with command resize2fs[root@osradar-lvm ~]#resize2fs /dev/vdb1
Try to mount manually the /dev/vd1b
to /boot
partition OR run following command[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
ENJOY