0

I have remote server with ubuntu 20.04 I can't use livecd or VM console

I want to migrate my root partiton from /dev/sda2 to /dev/sda5

my disk configuration is:

root@app-server:~$ lsblk

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   119G  0 disk
├─sda1   8:1    0  1007K  0 part
├─sda2   8:2    0  79,9G  0 part /
├─sda5   8:5    0    28G  0 part /app
├─sda6   8:6    0   4,7G  0 part /home
├─sda7   8:7    0   953M  0 part /srv
├─sda8   8:8    0   1,9G  0 part /tmp
└─sda9   8:9    0   3,7G  0 part /var

root@app-server:~# blkid

/dev/sda2: UUID="bda07617-0a2a-44cc-97fa-ff72d1bf45d2" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="45957f98-6bfd-4add-ad05-0b5a604c2423"
/dev/sda1: PARTLABEL="BIOS boot partition" PARTUUID="b33941c4-552c-4ff6-9c95-e7824e7a8102"
/dev/sda5: UUID="e0e56bbd-c2c2-4be5-91c8-02b50fc2f183" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="954341b7-1527-4eb2-ad39-04cb6c84ec72"
/dev/sda6: UUID="db1efe11-5dcf-4f03-a85e-ad379406d484" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="01f1ae61-03ec-405b-8b8a-7732baa74b3f"
/dev/sda7: UUID="2914d504-e0af-4acd-84d8-03e1c7e70136" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="d09bbe8c-5c39-4fdf-8503-fdfcdeb5e4d7"
/dev/sda8: UUID="0e8b5591-df05-4d38-82ca-9e395c098133" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="ae393080-4312-40fc-ba95-c7afc6770a12"
/dev/sda9: UUID="1be50204-6b50-48ec-9da9-cca8a88738eb" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="3e53f06f-764c-42ca-9c77-1c056472eee6"

root@app-server:~$ df -Th

Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  932M     0  932M   0% /dev
tmpfs          tmpfs     195M  1,7M  193M   1% /run
/dev/sda2      ext4       79G  6,3G   68G   9% /
tmpfs          tmpfs     971M     0  971M   0% /dev/shm
tmpfs          tmpfs     5,0M  4,0K  5,0M   1% /run/lock
tmpfs          tmpfs     971M     0  971M   0% /sys/fs/cgroup
/dev/sda6      ext4      4,6G   87M  4,2G   2% /home
/dev/sda9      ext4      3,6G  2,7G  792M  78% /var
/dev/sda8      ext4      1,8G  148K  1,7G   1% /tmp
/dev/loop0     squashfs   56M   56M     0 100% /snap/core18/2128
/dev/loop1     squashfs  128K  128K     0 100% /snap/bare/5
/dev/sda5      ext4       28G   34M   26G   1% /app
/dev/loop2     squashfs   56M   56M     0 100% /snap/core18/2714
/dev/loop3     squashfs   64M   64M     0 100% /snap/core20/1852
/dev/sda7      ext4      920M   24K  856M   1% /srv
/dev/loop6     squashfs   92M   92M     0 100% /snap/gtk-common-themes/1535
/dev/loop5     squashfs  219M  219M     0 100% /snap/gnome-3-34-1804/72
/dev/loop7     squashfs   66M   66M     0 100% /snap/gtk-common-themes/1515
/dev/loop8     squashfs   51M   51M     0 100% /snap/snap-store/547
/dev/loop9     squashfs   50M   50M     0 100% /snap/snapd/18596
tmpfs          tmpfs     195M   28K  195M   1% /run/user/1000
/dev/loop10    squashfs  219M  219M     0 100% /snap/gnome-3-34-1804/77
/dev/loop11    squashfs   46M   46M     0 100% /snap/snap-store/638
/dev/loop12    squashfs  347M  347M     0 100% /snap/gnome-3-38-2004/119

I stopped all my application service to avoid disk change
delete all application data from /dev/sda5, unmount it
and copy all '/' to new mount point

root@app-server:~# rm -rf /app/*
root@app-server:~# umount /app
root@app-server:~# mkdir /mnt/newroot
root@app-server:~# mount /dev/sda2 /mnt/newroot
root@kzp-test-gpt:~# ll /mnt/newroot

root@app-server:~# rsync -aAXv / /mnt/newroot --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/app/*,/home/*,/var/*}

I know i have to modyfy grub config and /etc/fstab

when i changed UUID in /mnt/newroot/etc/fstab there is no effect

How to configure grub to mount /dev/sda5 as root partition
i searched sda and UUID of currnet root partition but nothing

root@app-server:/mnt/newroot/etc/grub.d# grep -ri 'sda' /mnt/newroot/etc/grub.d/
root@app-server:/mnt/newroot/etc/grub.d# grep -ri 'bda07617-0a2a-44cc-97fa-ff72d1bf45d2' /mnt/newroot/etc/grub.d/

root@app-server:/mnt/newroot/etc/grub.d# grep -ri 'sda' /mnt/newroot/etc/default/grub
root@app-server:/mnt/newroot/etc/grub.d# grep -ri 'bda07617-0a2a-44cc-97fa-ff72d1bf45d2' /mnt/newroot/etc/default/grub

my grub file looks like:

root@app-server:/mnt/newroot/etc/grub.d# cat /mnt/newroot/etc/default/grub

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

How to make changes in grub and what config should i change

old root in / or new /mnt/newroot/ the same with fstab ? any help please

supportth
  • 1
  • 1

1 Answers1

0

Finally i found a solution:
After we run command
rsync -aAXv / /mnt/newroot --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/app/*,/home/*,/var/*}

We have to edit new fstab /mnt/newroot/etc/fstab
Delete the line with old root UUID and change the line with path from /app to /

Then change UUID in /boot/grub/grub.cfg
sed -i 's/<OLD_ROOT>/<NEW_ROOT>/g' /boot/grub/grub.cfg
We will fix grub late
Reboot and VM will boot from new root partition
Check it df -h /

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda5        28G   12G   15G  45% /

Next delete old root partition via fstab
and update grub
grub-install /dev/sda
update-grub
reboot now

supportth
  • 1
  • 1