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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
09-22-2019, 08:25 AM
|
#1
|
Member
Registered: May 2006
Location: Da Bronx
Distribution: Arch Linux, Sackware, Gentoo
Posts: 255
Rep:
|
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.
|
|
|
09-22-2019, 08:28 AM
|
#2
|
LQ Addict
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316
|
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.
|
|
|
09-22-2019, 08:30 AM
|
#3
|
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 3,349
Rep: 
|
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.
|
|
|
09-22-2019, 12:44 PM
|
#4
|
Member
Registered: May 2006
Location: Da Bronx
Distribution: Arch Linux, Sackware, Gentoo
Posts: 255
Original Poster
Rep:
|
Would deleting the swap partition will not destroy any data or leave the system unbootable?
|
|
|
09-22-2019, 01:51 PM
|
#5
|
Member
Registered: Aug 2008
Location: Yorkshire
Distribution: openSUSE(Leap and Tumbleweed) and a (not so) regularly changing third and fourth
Posts: 629
Rep: 
|
Quote:
Originally Posted by thebiggiantmouse
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.
|
|
|
09-22-2019, 04:00 PM
|
#6
|
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 3,349
Rep: 
|
Quote:
Originally Posted by thebiggiantmouse
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).
|
|
|
09-22-2019, 04:46 PM
|
#7
|
LQ Addict
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316
|
Quote:
Originally Posted by thebiggiantmouse
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.
|
|
|
09-22-2019, 04:54 PM
|
#8
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,389
|
Quote:
Originally Posted by berndbausch
... 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.
|
09-22-2019, 06:49 PM
|
#9
|
Senior Member
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683
|
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 
|
|
|
09-23-2019, 03:09 AM
|
#10
|
LQ Guru
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, OS/2, others
Posts: 6,522
|
Quote:
Originally Posted by thebiggiantmouse
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.
|
|
|
09-24-2019, 03:15 AM
|
#11
|
Member
Registered: May 2006
Location: Da Bronx
Distribution: Arch Linux, Sackware, Gentoo
Posts: 255
Original Poster
Rep:
|
Quote:
Originally Posted by mrmazda
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.
|
|
|
09-24-2019, 03:47 AM
|
#12
|
LQ Guru
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 11,403
|
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.
|
|
|
09-24-2019, 03:57 AM
|
#13
|
Senior Member
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683
|
Quote:
Originally Posted by thebiggiantmouse
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
|
|
|
09-24-2019, 04:19 AM
|
#14
|
LQ Guru
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, OS/2, others
Posts: 6,522
|
Quote:
Originally Posted by thebiggiantmouse
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.
|
|
|
09-25-2019, 11:32 AM
|
#15
|
Member
Registered: May 2006
Location: Da Bronx
Distribution: Arch Linux, Sackware, Gentoo
Posts: 255
Original Poster
Rep:
|
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)
|
|
|
All times are GMT -5. The time now is 02:53 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|