LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 09-22-2019, 08:25 AM   #1
thebiggiantmouse
Member
 
Registered: May 2006
Location: Da Bronx
Distribution: Arch Linux, Sackware, Gentoo
Posts: 255

Rep: Reputation: 31
How to re-size root partition without loosing any data if the root partition is immediately followed by swap partition


I have been getting the root partition low on space alert frequently, and I want to resize my root partition.Now the root partition is immediately followed by swap partition, is there a way I could resize the root partition without losing any of my data.
 
Old 09-22-2019, 08:28 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
A partition manager like gparted should be able to remove swap, resize root then optionally recreate a smaller swap space or swap space elsewhere. When dealing with root and swap, I guess it's best to run it from live media, e.g. gparted live cd.
 
Old 09-22-2019, 08:30 AM   #3
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,345

Rep: Reputation: Disabled
Sure. Just deactivate swap and delete the swap partition, then resize the root partition and create a new swap partition.

Relevant commands: swapoff, mkswap, swapon

Remember to check the swap entry in /etc/fstab afterwards, and update any UUID or LABEL reference to reflect the new partition.
 
Old 09-22-2019, 12:44 PM   #4
thebiggiantmouse
Member
 
Registered: May 2006
Location: Da Bronx
Distribution: Arch Linux, Sackware, Gentoo
Posts: 255

Original Poster
Rep: Reputation: 31
Would deleting the swap partition will not destroy any data or leave the system unbootable?
 
Old 09-22-2019, 01:51 PM   #5
petelq
Member
 
Registered: Aug 2008
Location: Yorkshire
Distribution: openSUSE(Leap and Tumbleweed) and a (not so) regularly changing third and fourth
Posts: 629

Rep: Reputation: Disabled
Quote:
Originally Posted by thebiggiantmouse View Post
Would deleting the swap partition will not destroy any data or leave the system unbootable?
I haven't had a swap partition for years. It was never used so I scrapped it. As far as I'm aware the only use for swap is if you hibernate your system or if you don't have enough ram, which is unlikely these days.
 
Old 09-22-2019, 04:00 PM   #6
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,345

Rep: Reputation: Disabled
Quote:
Originally Posted by thebiggiantmouse View Post
Would deleting the swap partition will not destroy any data or leave the system unbootable?
Nope, you can run perfectly fine without a swap partition as long as you have sufficient RAM. And to see if you do, simply try running swapoff (as root, which would probably translate to sudo swapoff for most distributions).

BTW, you can do all of this from within a running system. You won't even have to reboot, as long as your root filesystem supports online resizing (most do).
 
Old 09-22-2019, 04:46 PM   #7
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by thebiggiantmouse View Post
Would deleting the swap partition will not destroy any data or leave the system unbootable?
The swap partition contains copies of RAM pages during operation.

Ser Olmy suggests swapoff to disable swap. This command will fail if the swap partition is in use. If it succeeds, you have nothing on swap that needs to be kept. If it fails, you can't disable swap. Thus my suggestion to use live media for resizing.
 
Old 09-22-2019, 04:54 PM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,145

Rep: Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124
Quote:
Originally Posted by berndbausch View Post
... swapoff to disable swap. This command will fail if the swap partition is in use.
Not true. Swapoff writes pages back into RAM - if they can't be accommodated, the command fails.
Moving the swap somewhere else is my preferred position - disk is cheap these days. A mis-configured system will certainly cause boot problems - this applies equally to swap.
 
2 members found this post helpful.
Old 09-22-2019, 06:49 PM   #9
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
yeah, swap is a nice saftey net

assuming current swap is /dev/sda3
and you can make a new partition /dev/sda6

Code:
sudo mkswap /dev/sda6
sudo swapon /dev/sda6 && sudo swapoff /dev/sda3
it will only swapoff if swapon works
and if you are short on ram it should use the new swap instead of running oomkiller


edit your /etc/fstab to reflect the move in swap
use lsblk -o name,type,uuid,partuuid if you want to find UUID or PARTUUID


Consider lvm, it is more flexible than traditional partitioning
or if you are really daring , try zfs and forget how all this partition stuff works
 
Old 09-23-2019, 03:09 AM   #10
mrmazda
LQ Guru
 
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 5,852
Blog Entries: 1

Rep: Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074
Quote:
Originally Posted by thebiggiantmouse View Post
is there a way I could resize the root partition without losing any of my data.
The other answers could only go so far, as you don't seem to have fully reported what you have to start with. What else is on that disk? Other partitions? Freespace? Is your /home/ a separate partition? Output from df and fdisk -l or parted -l would help potential helpers help you better.
 
Old 09-24-2019, 03:15 AM   #11
thebiggiantmouse
Member
 
Registered: May 2006
Location: Da Bronx
Distribution: Arch Linux, Sackware, Gentoo
Posts: 255

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by mrmazda View Post
The other answers could only go so far, as you don't seem to have fully reported what you have to start with. What else is on that disk? Other partitions? Freespace? Is your /home/ a separate partition? Output from df and fdisk -l or parted -l would help potential helpers help you better.
Code:
fdisk
Filesystem     1K-blocks      Used Available Use% Mounted on
dev              4074344         0   4074344   0% /dev
run              4081772      1088   4080684   1% /run
/dev/sda3       25671908  24202528    142276 100% /
tmpfs            4081772     68264   4013508   2% /dev/shm
tmpfs            4081772         0   4081772   0% /sys/fs/cgroup
/dev/sda1        4057170     59329   3784086   2% /boot
/dev/sda4      922000820 297936720 577159284  35% /home
tmpfs            4081772     37092   4044680   1% /tmp
tmpfs             816352        32    816320   1% /run/user/1000
I hope this helps you help me.

Last edited by thebiggiantmouse; 09-25-2019 at 11:38 AM.
 
Old 09-24-2019, 03:47 AM   #12
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,547

Rep: Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498
The output of fdisk you posted above does not show any swap partiiion. You also did not post the complete output so do/did you actually have a swap partition and which device was it, sda3? Had you turned swap off or deleted it before running fdisk? Which Linux distribution are you using? You do seem to have a cery large boot partition but that is no immediate help as it is not contiguous with the / partition.
 
Old 09-24-2019, 03:57 AM   #13
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by thebiggiantmouse View Post
fdisk
Code:
Filesystem     1K-blocks      Used Available Use% Mounted on
dev              4074344         0   4074344   0% /dev
run              4081772      1088   4080684   1% /run
/dev/sda3       25671908  24202528    142276 100% /
tmpfs            4081772     68264   4013508   2% /dev/shm
tmpfs            4081772         0   4081772   0% /sys/fs/cgroup
/dev/sda1        4057170     59329   3784086   2% /boot
/dev/sda4      922000820 297936720 577159284  35% /home
tmpfs            4081772     37092   4044680   1% /tmp
tmpfs             816352        32    816320   1% /run/user/1000
I hope this helps you help me.
not really
and please use [code]
paste things like that here
[/code]

Code:
sudo parted /dev/sda print
 
Old 09-24-2019, 04:19 AM   #14
mrmazda
LQ Guru
 
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 5,852
Blog Entries: 1

Rep: Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074
Quote:
Originally Posted by thebiggiantmouse View Post
I hope this helps you help me.
That's only df output. We still need fdisk -l or parted -l. And, as indicated by Firerat, the command itself and the output that follows needs to be enclosed in code tags to preserve the formatting you see when you run a command.
 
Old 09-25-2019, 11:32 AM   #15
thebiggiantmouse
Member
 
Registered: May 2006
Location: Da Bronx
Distribution: Arch Linux, Sackware, Gentoo
Posts: 255

Original Poster
Rep: Reputation: 31
Ok thanks for all your help. Here is the output of fdisk -l
Code:
Disk /dev/sda: 931.53 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: ST31000524AS    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000d5686

Device     Boot    Start        End    Sectors   Size Id Type
/dev/sda1           2048    8388607    8386560     4G 83 Linux
/dev/sda2        8388608   25559039   17170432   8.2G 82 Linux swap / Solaris
/dev/sda3       25559040   77987839   52428800    25G 83 Linux
/dev/sda4       77987840 1953525167 1875537328 894.3G 83 Linux


Disk /dev/sdb: 298.9 GiB, 320072933376 bytes, 625142448 sectors
Disk model: 3AS             
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0x3c048a03

Device     Boot Start       End   Sectors   Size Id Type
/dev/sdb1        2048 625139711 625137664 298.1G  7 HPFS/NTFS/exFAT






Disk /dev/sdc: 14.55 GiB, 15611199488 bytes, 30490624 sectors
Disk model: DataTraveler 2.0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc3072e18

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdc1        8064 30490623 30482560 14.5G  c W95 FAT32 (LBA)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i merge two ext2 linux partition without loosing any data amitkjain_crld Linux - General 6 12-24-2022 01:04 AM
How to resize root partition without loosing data? mukesh_4967 Linux - Newbie 2 06-14-2009 09:05 PM
Howto UNinstall software RAID 1 without loosing data carlosruiz Linux - General 1 05-28-2006 09:10 PM
Can i resize my partition without loosing data? byen Linux - General 4 05-25-2005 07:39 PM
Total partition size - User partition size is not equals to Free partition size navaneethanj Linux - General 5 06-14-2004 12:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 01:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration