expand /boot partition help please

Latest response

Here is my lsblk

lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1.8T 0 disk
├─sda1 8:1 0 349.5M 0 part
├─sda2 8:2 0 5G 0 part
├─sda3 8:3 0 200M 0 part /boot
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 1.8T 0 part
├─VolGroup00-LogVol01 253:0 0 11.7G 0 lvm [SWAP]
├─VolGroup00-LogVol00 253:1 0 101G 0 lvm /
├─VolGroup00-LogVol02 253:2 0 20G 0 lvm /usr
├─VolGroup00-LogVol05 253:3 0 102G 0 lvm /home
├─VolGroup00-LogVol04 253:4 0 16G 0 lvm /var
└─VolGroup00-LogVol03 253:5 0 512M 0 lvm /tmp
sdb 8:16 0 19.3G 0 disk
sr0 11:0 1 1024M 0 rom

I need to expand the size of my /boot partition due to a kernel upgrade.

I have resized the LVMs using command line but I'm not sure how to resize /dev/sda3 which is /boot

or remove unused files:
boot]# ll
total 158020
-rw-r--r--. 1 root root 122059 May 5 2014 config-3.10.0-123.el7.x86_64
-rw-r--r-- 1 root root 137701 Feb 19 23:48 config-3.10.0-514.10.2.el7.x86_64
-rw-r--r-- 1 root root 137701 Mar 10 10:30 config-3.10.0-514.16.1.el7.x86_64
drwx------. 6 root root 4096 Apr 12 16:54 grub2
-rw-r--r--. 1 root root 15723655 Apr 1 2015 initramfs-0-rescue-95830f31d3db445aaf0ade5cde6bd352.img
-rw------- 1 root root 24194692 Mar 15 09:12 initramfs-3.10.0-123.el7.x86_64.img
-rw------- 1 root root 25201972 Mar 15 09:13 initramfs-3.10.0-514.10.2.el7.x86_64.img
-rw------- 1 root root 18507746 Mar 15 15:06 initramfs-3.10.0-514.10.2.el7.x86_64kdump.img
-rw------- 1 root root 24374722 Apr 12 16:54 initramfs-3.10.0-514.16.1.el7.x86_64.img
-rw------- 1 root root 18504904 Apr 29 09:22 initramfs-3.10.0-514.16.1.el7.x86_64kdump.img
-rw-r--r--. 1 root root 4438970 Mar 15 09:12 initrd-plymouth.img
-rw-r--r--. 1 root root 228562 May 5 2014 symvers-3.10.0-123.el7.x86_64.gz
-rw-r--r-- 1 root root 277969 Feb 19 23:51 symvers-3.10.0-514.10.2.el7.x86_64.gz
-rw-r--r-- 1 root root 277943 Mar 10 10:35 symvers-3.10.0-514.16.1.el7.x86_64.gz
-rw-------. 1 root root 2840084 May 5 2014 System.map-3.10.0-123.el7.x86_64
-rw------- 1 root root 3112473 Feb 19 23:48 System.map-3.10.0-514.10.2.el7.x86_64
-rw------- 1 root root 3113648 Mar 10 10:30 System.map-3.10.0-514.16.1.el7.x86_64
-rwxr-xr-x. 1 root root 4902000 Apr 1 2015 vmlinuz-0-rescue-95830f31d3db445aaf0ade5cde6bd352
-rwxr-xr-x. 1 root root 4902000 May 5 2014 vmlinuz-3.10.0-123.el7.x86_64
-rwxr-xr-x 1 root root 5391456 Feb 19 23:48 vmlinuz-3.10.0-514.10.2.el7.x86_64
-rwxr-xr-x 1 root root 5394272 Mar 10 10:30 vmlinuz-3.10.0-514.16.1.el7.x86_64

Thanks
cwc

Responses

It's technically possible, but there is NO supported method to do this, and the unsupported method is very risky and can create instability in the disk. This is because in order to resize the boot partition, you need to move the other partitions further away from the boot partition on the disk, so that the boot partition has room to expand. You can do this with something like gparted, but I do not recommend it and, again, it is NOT SUPPORTED.

What I'd recommend instead would be taking a backup of your system and configuring a larger boot partition as you do a fresh install. Much, much safer. Just make sure you test that your backup works before you wipe anything. :)

I removed the old kernels. package-cleanup --oldkernels --count=1 and I was able to perform an update.

"What I'd recommend instead would be taking a backup of your system and configuring a larger boot partition as you do a fresh install."

Personally I would prefer a standard old school xfs install /boot swap / /home the use my second drive for a back.

If I install a fresh system will I be able to use my existing registration?

Thanks for the post.

That looks okay, still your /boot file system size is very small. Red Hat recommends at least 1GB of space for /boot. https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Installation_Guide/sect-disk-partitioning-setup-x86.html

Yes, you may need to delete old profile and re-register it, check out this KB https://access.redhat.com/solutions/8036

Thank you! That's what I am going to do. Reinstall Redhat es7 with the the following: /dev/sda /boot 2gb xfs or ext4 swap 40gb ( I have 24gb installed) / 400gib xfs /home 500gb xfs /dev/sdb /data xfs

I plan on mirroring debiab 8

Yes, re-sizing partitions is highly risky and sophisticated. Again, could be resized from the partition end not from the beginning provided there is empty space in the specified partition layout.

Check out this KB https://access.redhat.com/solutions/356753

But I notice that there is /dev/sda2 with size of 5GB which I guess un-used, why don't you make this as boot device if this not targed to be used for anything else.

I had tested this by moving boot partition from /dev/sda1 to /dev/sda2 which worked fine on my virtual machine running with RHEL 6.5, but ran into some error initially "file not found" which I was able to replicate later properly without much hiccups. If you wish to get this done then you may refer the below steps (risky and Red Hat would not recommend this...)

- Make a backup of boot and it's partition layouts. 

- Create a new file system on /dev/sda2.

    #mkfs.ext4 /dev/sda2

- Copy all files from /dev/sda3 to /dev/sda2 

    #mount /dev/sda2 /test
    #cp -arv /boot/. /test/

- Edit /etc/fstab and add new entry of /dev/sda2 and comment out old boot entry.

- Install the required boot files (stage2..) on /dev/sda2

 #grub --device-map=/test/grub/device.map

  Now, inside grub prompt run the below commands:

  grub> root (hd0,1)                      

  grub> setup (hd0)             ------> this would setup bootloader on the required partition

- Once this is successful quit from grub prompt.

- Edit grub.conf file on the /dev/sda2 partition so that it points to correct splash image and root directory as shown below:

  splashimage=(hd0,1)/grub/splash.xpm.gz

  root (hd0,1)

- After this toggle the boot flag so that /dev/sda2 would be marked as bootable and mask boot flag on /dev/sda3 using fdisk command.

- Reboot the system and check if system boots up fine & /boot is on /dev/sda2 partition, if so then you are all set & done. Now, you can install new kernel packages as required. 

On my test systems, I had formatted /dev/sda1 by creating new file system layout (mkfs.ex4 /dev/sda1). Rebooted the system again and tested that it boots fine from /dev/sda2 and rest of file systems being LVMs.

All the best...

Incidentally, you can GROW an XFS file system (LVM), but you can --not-- shrink an XFS file system. so if you had to rob from one partition to go to the other, you'd find you can't shrink XFS through its failures to shrink. Recommend what Laura Bailey said above.

It's overkill, but just today I found myself making /boot 2GB instead of my usual 1GB. Overkill? yes.
UPDATE I make my /boot partitions over 5GB, yes, I enjoy the overkill.

RJ Hinton , Can you share your steps.

Thanks Ahmad

help full comments.

Reply to Sahibzada Ahmad

Please see the extreme cautions cited above from Red-Hatter Laura Bailey above. In principle, the steps to grow an XFS file system are at this link. I seriously recommend you heed her cautions.

Sahibzada Ahmad, Please re-read the cautions from Laura Baily above, really, --thanks.

Regards,
RJ

Hello, since this has been a tricky task i had to do, i might as well share my experience to make it easier for you. This is how i did it within our AWS enviroment to increase /boot partition on AMI. It's for Centos but RHEL should be the same.

Note: since you’re working on partitions from which currently operating system is running, it’s recommended to reboot the machine each time you do any changes to partitions.

Attach second disk to the instance the size at least the same as current OS volume and create LVM type partition on it.

ip-10-233-187-70 ~ # lsblk
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda              202:0    0   30G  0 disk
├─xvda1           202:1    0  243M  0 part /boot
└─xvda2           202:2    0 29.8G  0 part
  ├─rootvg-lvroot 253:0    0    2G  0 lvm  /
  ├─rootvg-lvvar  253:1    0    1G  0 lvm  /var
  └─rootvg-lvusr  253:2    0    3G  0 lvm  /usr
xvdf              202:80   0   30G  0 disk
ip-10-233-187-70 ~ # fdisk /dev/xvdf
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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x9111fda4.

Command (m for help): p

Disk /dev/xvdf: 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: 0x9111fda4

    Device Boot      Start         End      Blocks   Id  System

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-62914559, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559):
Using default value 62914559
Partition 1 of type Linux and of size 30 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Create LVM volume and extend rootvg with this volume.

ip-10-233-187-70 ~ # pvcreate /dev/xvdf1
  Physical volume "/dev/xvdf1" successfully created.
ip-10-233-187-70 ~ # pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/xvda2 rootvg lvm2 a--  <29.76g <23.76g
  /dev/xvdf1        lvm2 ---  <30.00g <30.00g
ip-10-233-187-70 ~ # vgextend rootvg /dev/xvdf1
  Volume group "rootvg" successfully extended
ip-10-233-187-70 ~ # pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/xvda2 rootvg lvm2 a--  <29.76g <23.76g
  /dev/xvdf1 rootvg lvm2 a--  <30.00g <30.00g

Move contents of /dev/xvda2 to /dev/xvdf1.

ip-10-233-187-70 ~ # pvmove /dev/xvda2 /dev/xvdf1
  /dev/xvda2: Moved: 0.07%
  /dev/xvda2: Moved: 11.13%
  /dev/xvda2: Moved: 25.59%
  /dev/xvda2: Moved: 33.33%
  /dev/xvda2: Moved: 45.83%
  /dev/xvda2: Moved: 50.00%
  /dev/xvda2: Moved: 62.30%
  /dev/xvda2: Moved: 73.11%
  /dev/xvda2: Moved: 83.46%
  /dev/xvda2: Moved: 94.86%
  /dev/xvda2: Moved: 100.00%

Remove /dev/xvda2 from LVM and delete the partition.

ip-10-233-187-70 ~ # vgreduce rootvg /dev/xvda2
  Removed "/dev/xvda2" from volume group "rootvg"
ip-10-233-187-70 ~ # pvremove /dev/xvda2
  Labels on physical volume "/dev/xvda2" successfully wiped.
ip-10-233-187-70 ~ # pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/xvdf1 rootvg lvm2 a--  <30.00g <24.00g
ip-10-233-187-70 ~ # fdisk /dev/xvda
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/xvda: 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: 0x0002ed94

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048      499711      248832   83  Linux
/dev/xvda2          499712    62914559    31207424   8e  Linux LVM

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted

Command (m for help): p

Disk /dev/xvda: 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: 0x0002ed94

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048      499711      248832   83  Linux

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.

After reboot it’s time to resize the /dev/xvda1 partition with /boot fs on it. Don’t use fdisk as it can’t resize the partition and you have to delete and create new one. This process will not work, the resulting increased partition will be unbootable. Use parted and its resizepart command.

ip-10-233-187-70 ~ # parted /dev/xvda
GNU Parted 3.1
Using /dev/xvda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) resizepart 1 2099199
Error: The location 2099199 is outside of the device /dev/xvda.
(parted) print
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  256MB  255MB  primary  ext4         boot

(parted) resizepart 1 1024MB
(parted) print
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  1024MB  1023MB  primary  ext4         boot

(parted) quit
Information: You may need to update /etc/fstab.

After another reboot, resize the filesystem for /boot and create back the partition for rootvg.

ip-10-233-187-70 ~ # resize2fs /dev/xvda1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/xvda1 is mounted on /boot; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 8
The filesystem on /dev/xvda1 is now 998976 blocks long.

ip-10-233-187-70 ~ # df -h
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                   465M     0  465M   0% /dev
tmpfs                      742M     0  742M   0% /dev/shm
tmpfs                      495M   13M  482M   3% /run
tmpfs                      495M     0  495M   0% /sys/fs/cgroup
/dev/mapper/rootvg-lvroot  2.0G   44M  1.9G   3% /
/dev/mapper/rootvg-lvusr   2.9G  1.5G  1.5G  50% /usr
/dev/mapper/rootvg-lvvar   976M  279M  682M  30% /var
/dev/xvda1                 942M  142M  755M  16% /boot
tmpfs                       99M     0   99M   0% /run/user/0

ip-10-233-187-70 ~ # fdisk /dev/xvda
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/xvda: 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: 0x0002ed94

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048     2000000      998976+  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 (2000001-62914559, default 2000896): 2000001
Last sector, +sectors or +size{K,M,G} (2000001-62914559, default 62914559):
Using default value 62914559
Partition 2 of type Linux and of size 29 GiB is set

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

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.

Create back the LVM volume, extend the VG with it and move data to it.

ip-10-233-187-70 ~ # lsblk
NAME              MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
xvda              202:0    0    30G  0 disk
├─xvda1           202:1    0 975.6M  0 part /boot
└─xvda2           202:2    0    29G  0 part
xvdf              202:80   0    30G  0 disk
└─xvdf1           202:81   0    30G  0 part
  ├─rootvg-lvroot 253:0    0     2G  0 lvm  /
  ├─rootvg-lvvar  253:1    0     1G  0 lvm  /var
  └─rootvg-lvusr  253:2    0     3G  0 lvm  /usr
ip-10-233-187-70 ~ # pvcreate /dev/xvda2
  Physical volume "/dev/xvda2" successfully created.
ip-10-233-187-70 ~ # vgextend rootvg /dev/xvda2
  Volume group "rootvg" successfully extended
ip-10-233-187-70 ~ # pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/xvda2 rootvg lvm2 a--   29.04g  29.04g
  /dev/xvdf1 rootvg lvm2 a--  <30.00g <24.00g
ip-10-233-187-70 ~ # pvmove /dev/xvdf1 /dev/xvda2
  /dev/xvdf1: Moved: 0.07%
  /dev/xvdf1: Moved: 15.95%
  /dev/xvdf1: Moved: 30.79%
  /dev/xvdf1: Moved: 33.33%
  /dev/xvdf1: Moved: 49.15%
  /dev/xvdf1: Moved: 50.00%
  /dev/xvdf1: Moved: 65.43%
  /dev/xvdf1: Moved: 80.34%
  /dev/xvdf1: Moved: 95.25%
  /dev/xvdf1: Moved: 100.00%

After move you can remove the second volume from VG, remove it from LVM and detach the disk from instance. Create new image and that’s it.

ip-10-233-187-70 ~ # vgreduce rootvg /dev/xvdf1
  Removed "/dev/xvdf1" from volume group "rootvg"
ip-10-233-187-70 ~ # pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/xvda2 rootvg lvm2 a--   29.04g  23.04g
  /dev/xvdf1        lvm2 ---  <30.00g <30.00g
ip-10-233-187-70 ~ # pvremove /dev/xvdf1
  Labels on physical volume "/dev/xvdf1" successfully wiped.

Hi JB,

This is a great way to do it, but still the disclaimer applies.

Please see the extreme cautions cited above from Red-Hatter Laura Bailey above.

So have a good and tested backup before doing it.

Regards,

Jan Gerrit

Indeed, backups are a must, i had to restore volumes from snapshot at least 10 times until i figured it out :)