Friday, April 26, 2024
51
rated 0 times [  51] [ 0]  / answers: 1 / hits: 492330  / 2 Years ago, fri, june 3, 2022, 5:24:07

I only have access to the server via a terminal and I can't use graphical tools such as GParted!

I want to create a new partition from a part of the root (about 768mb) for swap.



# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda 20G 1.3G 18G 7% /
udev 10M 0 10M 0% /dev
tmpfs 199M 4.9M 194M 3% /run
tmpfs 100M 12K 100M 1% /run/user
tmpfs 5.0M 4.0K 5.0M 1% /run/lock

More From » command-line

 Answers
4

You cannot shrink/edit a partition if any of the partition on the storage device is mounted. So in order to unmount and edit the root filesystem, the OS need to be shutdown. Then boot into a live system and edit the partition as described in other answers.



Alternative solution : swap file



As an alternative to creating an entire partition, a swap file offers the ability to vary its size on-the-fly, and is more easily removed altogether. Swap file can be hot plugable. i.e can be added and removed without unmounting/turning off the OS.




  1. Create a 512 MB file called /swapfile. This will be our swap file.



    fallocate -l 512M /swapfile  


    OR



    dd if=/dev/zero of=/swapfile bs=1M count=512

  2. Set the right permissions (because a world-readable swap file is a huge local vulnerability):



    chmod 600 /swapfile

  3. After creating the correctly sized file, format it to swap:



    mkswap /swapfile

  4. Activate the swap file:



    swapon /swapfile

  5. Edit /etc/fstab and add an entry for the swap file:



    /swapfile none swap defaults 0 0



More details at arch linux wiki.


[#27973] Sunday, June 5, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kneducator

Total Points: 226
Total Questions: 111
Total Answers: 108

Location: Mexico
Member since Sun, Jul 25, 2021
3 Years ago
;