Transfer /boot from a main partition to a separate partition

Today, I’ll give an example of moving /boot from a shared partition to a separate partition.
For the test, you can connect a new disk or use the first partition on any disk, for example, with a size of 512MB.

Let’s look at the information about the disks:

sudo fdisk -l
sudo ls -l /boot
sudo du -hs /boot

Suppose we have connected a new unmapped disk /dev/sdb, we create on it the first partition for boot with a size of 512 MB:

sudo fdisk /dev/sdb
n
p
1
2048
1052000
w

Create an ext2 table:

sudo mkfs.ext2 /dev/sdb1

Make the partition active:

sudo fdisk /dev/sdb
a
w

We copy the data /boot/ from the shared partition to a separate partition:

sudo mount /dev/sdb1 /mnt/
sudo cp -p -r /boot/* /mnt/

Make sure that the data is copied and clean the /boot/ folder on the main partition:

sudo ls -l /mnt
sudo rm -r -f /boot/*

Let’s see the UUID of the new partition with /boot/:

lsblk -o NAME,UUID

We will specify it in the file /etc/fstab for automatic mounting:

sudo nano /etc/fstab
UUID=085d1d30-fa19-4144-a146-2e88821e75ff /boot ext2 defaults 0 1

Mount the new partition in /boot/:

sudo umount /mnt/
sudo mount /dev/sdb1 /boot/

Update the GRUB:

sudo grub-install /dev/sdb
sudo update-grub

Now you can turn off the server:

sudo poweroff

We change disks in places, that is we connect a new disk first that it became /dev/sdа, we include the server, the system should boot through the loader on the first section.
If there is free space left on the disk, you can partition it to fit your needs using fdisk and mkfs.ext4.
I recommend storing /boot/ on a shared partition and using a raid.

See also my articles:
Recovering GRUB Linux
Configuring Software RAID1 on a Running Ubuntu System
Transferring a running Ubuntu system to another disk
Transfer /boot from a separate partition to a main partition

Leave a comment

Leave a Reply

Discover more from IT Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading