hey assistent, I am on localhost on recovery mode for my opensuse distro. I accidentaly deleted my swap parition and now It won't boot. How to create one and mount it from here?
Assistant
If you're in recovery mode on an openSUSE system and need to recreate your swap partition, you can follow these steps. Please note that you should proceed with caution to avoid data loss, and backup any important data if possible.
Step 1: Identify Disk Partitions
First, identify which disk and partition you want to use for swap:
Open a terminal in recovery mode.
Run the following command to list your partitions:
User
I have 2 pairtions /dev/nvme0n1p1 and nvme0n1p2
Assistant
If you have two partitions, /dev/nvme0n1p1 and /dev/nvme0n1p2, and you need to create a new swap partition, you may need to shrink one of these partitions to make space, or utilize any existing unallocated space on your disk.
Step-by-Step Guide
Back Up Data: Before you modify partitions, ensure you back up important data. Modifying partitions can result in data loss if something goes wrong.
User
nvvme0n1p2 hase 850GB how to resize 60?
Assistant
To resize a partition safely and create a new swap partition, you can use the parted command-line tool or a graphical tool like . Since you're in recovery mode and may not have access to a graphical interface, I'll guide you through using . This example will assume you want to reduce by 60GB and create a new swap partition in the freed space.
fdisk -l
Identify the disk where you want to create the swap partition. For example, if it's /dev/sda, you will work on this device.
Step 2: Create a New Swap Partition
Use fdisk or gdisk to create a new partition:
fdisk /dev/sda
Inside fdisk, type n to create a new partition.
Choose p for a primary partition.
Select the partition number (likely the next available number).
Specify the start and end sectors. You can leave this as default if it fits your needs.
Change the partition type to swap by typing t, followed by the swap type, which is generally 82.
Type w to write and save the changes.
Step 3: Format the Swap Partition
Format the newly created partition as swap:
mkswap /dev/sdaX
Replace /dev/sdaX with the path to your new swap partition.
Step 4: Activate the Swap Partition
Activate the swap space immediately:
swapon /dev/sdaX
Step 5: Update /etc/fstab
To make this swap partition persistent across reboots, edit your /etc/fstab file:
Open /etc/fstab with your text editor:
nano /etc/fstab
Add a line for the swap partition:
/dev/sdaX swap swap defaults 0 0
Replace /dev/sdaX with your specific swap partition.
Save and exit the text editor (Ctrl + O, Enter, and Ctrl + X for nano).
Step 6: Reboot the System
Reboot your system to see if the problem is resolved:
reboot
If everything is configured correctly, your system should boot up normally with the new swap partition in place.
Check Current Partition Usage:
Use a tool like lsblk or df to see current disk usage:
lsblk
Consider Shrinking a Partition:
If one of the partitions (/dev/nvme0n1p1 or /dev/nvme0n1p2) has room to spare, consider shrinking it to create space for a new swap partition. This can be done using a tool like gparted (graphical interface) or parted (command line).
Using parted:
parted /dev/nvme0n1
In parted, use:
print to see existing partitions.
resizepart to shrink a partition.
mkpart to create a new partition in the free space.
Create the Swap Partition:
Once you've created space (either by freeing space or using unallocated space), create a new partition for swap. Assuming it's /dev/nvme0n1p3, format it as swap:
mkswap /dev/nvme0n1p3
Activate and Add Swap Partition to /etc/fstab:
Activate the swap:
swapon /dev/nvme0n1p3
Edit /etc/fstab to make the swap persistent:
nano /etc/fstab
Add this line:
/dev/nvme0n1p3 swap swap defaults 0 0
Save the file and exit.
Reboot and Verify:
Reboot the system:
reboot
After rebooting, verify swap is active with:
swapon --show
This approach provides a solution to utilize the existing space on your disk for a new swap partition. If you run into any difficulties or have specific constraints, please let me know!
gparted
parted
/dev/nvme0n1p2
Step 1: Install Parted (if not already installed)
Make sure parted is installed:
zypper install parted
Step 2: Resize the Existing Partition
Open parted on your disk:
parted /dev/nvme0n1
Check Partitions:
Inside the parted prompt, check the existing partitions:
print
Resize the Partition:
To resize /dev/nvme0n1p2 and reduce it by 60GB, calculate the new end size. If it currently ends at around 850GB, you want to set it to end at 790GB:
resizepart 2 790GB
Confirm the resize when prompted.
Step 3: Create a New Partition for Swap
Create a New Partition:
Use the freed space to create a new partition. Assuming the free space starts around 790GB, proceed as follows:
mkpart primary linux-swap 790GB 850GB
Exit Parted:
Finish and exit:
quit
Step 4: Format and Activate the New Swap Partition
Format the New Partition as Swap:
Assuming the new partition is /dev/nvme0n1p3, format it:
mkswap /dev/nvme0n1p3
Activate the Swap Partition:
swapon /dev/nvme0n1p3
Step 5: Update /etc/fstab for Persistence
Edit /etc/fstab:
Open the fstab file with an editor:
nano /etc/fstab
Add the New Swap Entry:
Add this line at the end:
/dev/nvme0n1p3 swap swap defaults 0 0
Save and Exit:
Save changes and exit the editor (Ctrl + O, Enter, Ctrl + X for nano).
Step 6: Reboot and Verify
Reboot the System:
reboot
Verify Swap:
Check if the swap is active:
swapon --show
This procedure should help you resize your partition to create a new swap space. Make sure you understand each step and the implications of resizing partitions, as this can affect your data if not done correctly. If you're uncertain, additional backup of data might be prudent before proceeding.