0

Disclaimer: I'm not an expert in Linux systems, my main experience is Windows.

A some time ago I've found out that on my work PC partitions are separated not in the way I would like to. I have super-small root partition (20G), swap and then the rest of the space. I just wanted to improve it with the simplest (as I thought) way - add some space from "localdisk" to root partition. Under Windows it's super trivial task which almost every partition manager can do:

My disk

  • Run your favorite partition manager tool from Windows;
  • Cut some volume from "top" of localdisk;
  • Move swap to the bottom to have newly created free space adjacent to root; (actually, I would like to move swap just to the very end of the disk to avoid issues with moving swap in the future: to make root and localdisk adjacent)
  • Extend root to include the free space;
  • Commit operations and they will be performed during reboot.
  • And that's it. It will move everything keeping all the data in place, nothing will be broken after it.

Nothing exceptional to do on Windows.

But on Linux it turns out I can't modify partitions that are currently in use (mounted) even with reboot, and most of advice from the Net recommend to use LiveCD as the best option. But on Windows all the tools know how to do it during reboot. So, my questions are:

  • Is there a tool which allows you to do whatever and which performs all the operations after reboot, without requiring additional LiveCD ?
  • If no - why? I mean, it's very routine action, why is it so harmful?
  • May I ask why you want to resize your /? It might be simpler to just move whatever is taking up your space to /localdisk. It sounds like your cache is getting long in the tooth. – terdon Jul 4 '17 at 13:40
  • In this exact case I had /opt folder where my stuff is supposed to be installed. So 20G is super small amount for it. As a workaround, right now I just made /opt symlink to /localdisk and it worked for me, but I easily can imagine use case when it won't be so simple: i.e. if one has installed a lot of software and just needs ~5-20 Gb more. When the space is really required for root partition. – The Godfather Jul 4 '17 at 13:54
  • Oh, yes, it's a perfectly valid question in general. That's why I only left a comment. I usually have my / at 20G and that's always been enough. If I have to, I symlink /var/cache to somewhere else but you can usually clear that and that's what often takes up the most space. – terdon Jul 4 '17 at 14:45
1

I imagine there is a tool somewhere that does what you’re after (not well-known obviously).

However, on Linux and modern Unix-style systems, storage is managed using a volume manager, LVM typically on Linux. Once that’s set up, and most Linux installers know how to do so, you can resize volumes at run-time without needing a reboot. Since volume management is so straightforward with LVM, there’s not much point spending time and effort on other approaches...

  • serverfault.com/questions/424678/… i.e. there they say that I cannot cut a partition online. It seems pretty obvious that shrinking and extending are two operations you 99% perform at the same time. Cut one partition and put this space to another one. – The Godfather Jul 4 '17 at 14:12
  • Right, but it’s rather unusual to have to reduce a partition which can’t be unmounted, and lvresize -r handles things for you. Admittedly it’s not perfect, I’ll give you that, but there’s still generally no need to actually reboot. – Stephen Kitt Jul 4 '17 at 14:27
  • So you cannot even consider a case when I need to cut my root partition of some reasons (same reasons, actually - it was initially too big, or some space needed for swap - anything), right? – The Godfather Jul 4 '17 at 14:36
  • I can consider such a case, yes, and I have resized root partitions (including shrinking them) in the past, without rebooting, manually (on top of a RAID1 which helps). But I do think needing to reduce root is rather unusual, apart from needing to enlarge swap on a system with a single big partition (but then you could use a swap file instead). – Stephen Kitt Jul 4 '17 at 14:43
1

You can't shrink active partition even in Windows. How ever in Windows there is a key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SetupExecute which is executed by session manager (Some analogue of unix init). Tool can install some command there and it will be launched before everything using poqexec ( Primitive Operations Queue Executor).

This is how you can resize active partition in Windows.

There is no such API on Linux. Technically you can add this command to initramfs but it is always better to boot to initramfs or single mode and do what ever you like.

  • As from user's point of view on Windows I "commit" operations on my disk, including boot partition, then do a reboot (which is absolutely not an issue as long as I understand that reboot is required for changes on root partition), and at some stage during boot partition manager do the changes. Most probably you're right, there is some queue of actions, but it's internal stuff I don't really want to care about. So I can do everything from OS, reboot and it will be fine. Why cannot I do the same in Linux? – The Godfather Jul 4 '17 at 14:15
  • 1
    I believe that is because in linux there are myriad of options you may boot your OS. You may have LILO or Grub or SYSLINUX. You may have init or systemd. You may have initrams initrd or boot kernel directly. So, there is no place for such API. – user996142 Jul 4 '17 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.