Merging partitions in linux

How can I merge partitions in Linux without losing data?

So, I’m working on a couple VMs for a high-profile site, and they have /home partitioned separately from / (root). The owner has asked me to merge the two partitions so that /home is not partitioned separately. I’m really bad with partitions, and Google has proved pretty useless for this. Doing a df -T on /home, I don’t see anything for the filesystem, but I was told that it’s partitioned separately. Likewise, the filesystem column for df -T / is also empty. We’re using CentOS 6.4. Help would be appreciated.

2 Answers 2

Why won’t you simply create a new drive, copy the current home folders to it, and attach it as the /home partition?

It seems like the immediate solution.

So I talked with the owner about it and we decided that we would add additional space to the server by adding more HDDs, and then we will simply move the entirety of the /home directory onto the other drive, delete the partition it was on, and then move the data back to /home. It’s a shame that data on partitions is deleted when the partition is.

Partition manipulation needs backup before you do things — especially if you talk about a production webserver. Your solution is fine, but keep in mind that you will need to reboot server with either parted magic or some other live distro (in root terminal you could use resize2fs ). This is needed so that you can delete the old /home and extend / to recover space. As for data — think partition is a bottle and data milk — once the bottle is broken milk is gone 😉 — no other way about it. Good info on milk ibm.com/developerworks/library/l-resizing-partitions-1

Источник

How to merge partition with gparted?

enter image description here

How I can merge all of my three unallocated spaces? And i want the bigger one to be under /dev/sda5 . Gparted screenshot:

@mint — can you please edit your Q so that it explains in more details what you actually want? I see in the screenshot that you’ve highlighted the unallocated spaces on 3 partitions. Do you intend to have this space consolidated into a single partition? If so is this a new partition or 1 of the 3? Do you intend to have the 3 partitions merged into a new partition w/ all the data on them still intact? Many Q’s as a potential answerer means the Q is unclear and should be closed.

3 Answers 3

Assuming you’re talking about merging 3 partitions into 1 with all the original data intact

I do not believe you’ll be able to merge these partitions, as they are. There is not enough unused space on any of the partitions that can contain the other partitions’ used space.

You could shuffle them around and maximize the free space so that it’s on 1 of the 3 partitions. With the free space consolidated (on say partition #1), you could then effect the change of moving the data from say partition #2 to partition #1. Then deleting #2 and repeating the steps of consolidating #2’s space into #1. This whole dance would have to be repeated to consolidate #3’s used space into #1’s as well.

Читайте также:  Восстановление grub astra linux uefi

Doing the above will require you to enter GParted, make the shuffling changes and then go back to your OS to do the actual file copies that will consolidate the data from partitions #2 and #3 to #1. In between these activities you’ll have to go back to GParted to perform additional reshufflings.

Looking at your situation I would consider getting another HDD to execute this operation, the steps are a bit too involved and you’ll likely corrupt your data if any are not carried out correctly.

Источник

How to merge two partitions in Linux

screenshot of gparted

Quick question: I just looked at the other question again and the person who asked the question is using the liveboot gparted, I just have it regular. could this be my problem? Since the one I am trying to merge to is currently in use does this cause the problem I am having? Not allowing it to modify an in-use partition. ? I am trying to merge two partitions on my Linux machine, but can’t seem to figure out how. The closest thing that I found to my problem/answer was this question: How to merge unallocated partition to linux partition I’ve tried both of the things given for the answer, but neither worked. is there anything else I can try? My partitions look nearly the same as in the question. just one other ext4 partition in the extended partition. The highlighted unallocated partition is the one that I am trying to merge with the last partition listed (the ext4 mounted at /home) It would also be nice to merge the other unallocated partition (the 2.72 GB one, I took it out of my swap partition) with the partition mounted at / Thank you to anyone who is able to help me!

1 Answer 1

I can see a number of problems here:

  • There’s a key icon next to all of your Linux partitions (some OS themes use a padlock). It means that your partition is in use and thus locked. Most filesystems don’t support operating on them live. This issue is solved by booting a live OS which runs from external media, leaving partitions unlocked. I like Ubuntu for its simplicity, Grml is also nice if you prefer something more lightweight at the cost of user-friendliness.
  • Your swap partition is in the way. You can’t merge non-adjacent partitions without LVM and you’re not using LVM. This means you’ll have to create a new swap or move it into a file on / .
  • When merging partitions, data from all except the first one is lost. You have to make sure to move contents of your /home partition into /home on the root partition beforehand. It won’t fit there though, you have 85 GB of /home data and just 6.5 GB free on / . You’ll need some extra disk space.

Before working on partitions make sure that your backups are up to date and restorable. Making a full disk image is highly recommended. (Clonezilla is a nice Linux-based tool for this, it’s available in Ubuntu for download and included in Grml’s full version.)

The action plan would look something like this:

  1. Make a full disk image to external disk.
  2. Boot your Linux OS. Disable swap and remove it from fstab. Delete swap partition. Reboot to make sure system is functional and swap is disabled.
  3. Boot from USB/DVD/whatever.
  4. If you want to use unallocated space for / :
    1. Move / partition to the beginning of extended partition.
    2. Resize / partition to fill unallocated space.
    3. Mount / and /home partitions. Copy contents of /home partition to /home directory on / . Remember to preserve ownership information (eg. rsync -a ).
    4. Unmount both partitions. Delete /home partition.
    5. If you don’t want to use file-based swap, create the swap partition at the end of extended partition.
    6. Resize / again.
    7. Mount / partition. Remove /home entry from fstab.
    1. Create a temporary ext4 partition in unallocated space. We’ll use it to store /home contents before resizing / .
    2. Mount /home partition. Copy contents of /home partition to temporary partition. Remember to preserve ownership information (eg. rsync -a or partclone it).
    3. Unmount both partitions. Delete /home partition.
    4. If you don’t want to use file-based swap, create the swap partition at the end of extended partition.
    5. Resize / partition to fill unallocated space.
    6. Mount / partition. Copy contents of /home from temporary partition to /home directory on / . Remember to preserve ownership information (eg. rsync -a ).
    7. Delete temporary partition.
    8. Remove /home entry from fstab.

    Источник

    How to merge my partitions?

    enter image description here

    I Want to merge my /sda1 and /dev/sda6 . I have Ubuntu in both /sda1 and /dev/sda6 . But just now I have formatted /dev/sda1 , now I want to merge it with /dev/sda6 (it has Ubuntu). Please suggest me step wise using gparted .

    This is a complete guide to gparted, read it out in whatever pace you can, try to understand the terminology and consider editing your question with more details if you get into any issues Gparted Manual

    sda1 and sda2 are Windows in the image. Not linux. So either the image is wrong or what you want is impossible with this setup.

    no sda1 and sda2 are now just partitions. they don’t have any OS in them. I want to merge sda1 and sda6

    Can’t you just remove sda1, move partitions sda2 — sda5 to the left, and then expand sda6 to fit the empty area ? Note that execution might take a while on operations like that.

    1 Answer 1

    There are at least three problems with your question:

    • You cannot directly merge two partitions using common Linux tools. You can expand a partition into adjacent unpartitioned space, but merging partitions (which implies saving the contents of both partitions) is not supported by any Linux tools of which I am aware.
    • Your /dev/sda1 and /dev/sda6 are not adjacent to one another — two other partitions exist in-between them. Also, /dev/sda1 is a primary partition and /dev/sda6 is a logical partition. Thus, even if you found some obscure tool to merge two partitions, it would be useless in this context, because a partition must be a continuous set of sectors, like sectors A to D, not A to B and C to D, with other partitions occupying sectors B to C.
    • Your /dev/sda1 is NTFS and /dev/sda6 is ext4fs. Thus, even if you found a tool to merge two partitions, and if they were adjacent to one another, you couldn’t do it because they’re different filesystem types.

    All that said, I suspect that your /dev/sda1 is empty, and you simply want to expand the size of /dev/sda6 , using the space of /dev/sda1 . That task can be done, but it requires some intermediate tasks:

    1. Delete /dev/sda1 .
    2. Move /dev/sda2 to the left. This will have the effect of moving the free space now occupied by /dev/sda1 to the right of /dev/sda2 .
    3. Move /dev/sda3 to the left. Again, this has the effect of moving the free space to the right of /dev/sda3 .
    4. Resize the extended partition, /dev/sda4 , so that its start point is as far to the left as possible. It should now encompass the free space. (Note that an extended partition is a sort of placeholder that itself contains logical partitions. Thus, although the free space is within the extended partition, it’s still available to logical partitions and so remains free, in some sense.)
    5. Resize /dev/sda6 to the left, so that it now consumes the free space.

    This procedure carries some significant caveats:

    • You’ll need to perform the last two of those operations from an emergency boot (like an Ubuntu installer in «try before installing» mode).
    • The partition-move operations and resizing the Ubuntu partition to the left are likely to be time-consuming. Precisely how time-consuming depends on the speed of your disk — maybe just a few minutes, but maybe over an hour for each of them.
    • The partition-move and resizing operations carry some risk of damage to your partitions. Note that «damage to your partitions» could mean loss of important files. Thus, it’s imperative that you back up anything important on these partitions before you begin.
    • This operation might render OS(es) on the partition(s) unbootable. Thus, you should be prepared to run Boot Repair to fix Ubuntu. Windows repair is likely to require running specialized Windows tools, and is beyond my expertise. Repairing Windows is beyond the scope of this forum, too. You may want to research this topic before beginning, and ask for help on a Windows forum if you need it.
    • DO NOT try to operate on this disk using the standard Windows tools. Although it might do a better job of keeping Windows bootable, the standard Windows partitioning tools are known to wreak havoc when dealing with disks, like yours, that have extended and logical partitions.

    As an alternative to this procedure, you might consider using your existing /dev/sda1 more-or-less as-is. This question and answer, for instance, describe how to add a partition as a separate /home partition. You’d need to create a fresh ext4fs (or other Linux native) filesystem on the partition, but this approach bypasses all of the preceding caveats. OTOH, your current Ubuntu root ( / ) partition is tiny (16.28 GiB), so unless you want to increase its size for more user storage space, you might not free up enough space by using /dev/sda1 as /home . Maybe moving /var or something else to the new partition would work better, but that creates its own inflexibility. Moving the entire installation to /dev/sda1 , which is 53.61 GiB, might be a better approach. See here for some discussions on this approach.

    Источник

Оцените статью
Adblock
detector