📜 ⬆️ ⬇️

Problem solution: how to fix a “broken” VPS on Linux

Our contest “how to fix a broken VPS on a Linux server ” ended. The task of the participants was to fix the "broken" VPS server on linux. Only two contestants were able to cope with the task. The winner coped with the task in 17 hours.

»A member with mail farst***@gmail.com receives the main prize - a VPS server (5x2.6 GHz, 5 GB RAM, 50 GB SSD) for a year.
»A participant with non7*****@gmail.com mail takes the second place - we give him a lifetime discount of 70% on virtual servers RUVDS and our company mug. Well, the solution is under the cut.



To all other participants in the competition, we give a 10% discount on virtual servers from RUVDS . To get the discount write a letter to support@ruvds.com enter your login .
')
So, lay out the solution to the problem.

Decision


1. Use emergency mode, connect as user administrator.

2. Mount root fs with write permissions (the file system is mounted in this mode, since the file / etc / fstab was renamed to / etc / fstab_backup

sudo mount -o remount,rw /dev/sda3 / sudo mv /etc/fstab_backup /etc/fstab 

3. We allow incoming connections to ports 80 and 22:

 sudo ufw allow 80 sudo ufw allow 22 

4. Disable swap:

 sudo swapoff -a 

In fstab, we comment on the appropriate line:

 sudo vim /etc/fstab #UUID=1dc65039-4ac4-xxxxx-xxx-4xxxxf96xxxx none swap sw 0 0 

5. Format swap to xfs (or to any other file system), for example using the utility mkfs -t xfs

6. Remove the unnecessary from the current installation so that it can be copied to the / dev / sda2 section

 sudo apt-get autoremove sudo apt-get remove name-of-package --purge #   sudo rm -rf /var/log sudo rm -rf /tmp/* 

7. Mount / dev / sda2 to / mnt and copy the necessary files from the root section and the contest files.

 sudo mount /dev/sda2 /mnt cp -dpRx / /mnt 

8. Get uuid / dev / sda2:

 sudo blkid /dev/sda2 

9. Specify the new value for root, update uuid in /etc/grub/grub.cfg

10. Boot under the new root partition.

 shutdown -r now 

11. Remove (xfs does not support shrink) partition / dev / sda3 and divide it into 2 (/ dev / sda3 and / dev / sda4) in accordance with the conditions of the problem. This can be done with fdisk.

12. Format new partitions in xfs (mkfs -t xfs utility)

13. Mount the partition / dev / sda3 and copy the files there the necessary files of the root partition.

14. Mount the / dev / sda4 partition and copy the contest files there

15. Again, edit /etc/grub/grub.cfg and write a new uuid (new partition / dev / sda3) and device there.

16. Rule fstab and reboot.

17. Mark the / dev / sda2 section again as a swap (uncomment the entry in fstab, set the identifier swap through fdisk and execute swapon)

18. Restart your VPS , set up the site in nginx and open the browser, and see our site, the problem is solved:

Source: https://habr.com/ru/post/308348/


All Articles