2

I recently removed Windows from my computer which left me with a lot of unallocated space (which I later formatted to ext4). So I was wondering if it is possible to "copy" the /home partition from sda11 to sda5 as shown in the image here from Gparted. Partitions on my computer

I am very new to this, so if someone can give me a detailed procedure to follow, or point me to where I could find one, I will be extremely grateful.

2

3 Answers 3

2

In general it would be a good idea not to use sda5 directly but make it an LVM PV (pvcreate), create an LVM VG for it (vgcreate) and create an LVM LV home in that VG (lvreate). That makes later changes in size much easier and has advatages for backups.

However you do it:

  • Mount the formatted target block device somewhere, e.g. /mnt/tmp
  • Abort all processes which use /home (to be on the safe side you can run umount /home && mount /home)
  • copy the data from the old filesystem to the new: cp -a /home/. /mnt/tmp
  • change the entry for /home in /etc/fstab from the old to the new block device (or UUID, see blkid)
  • unmount the old filesystem: umount /home
  • mount the new filesystem: mount /home
  • check that it worked: df -h /home
4
  • LVM is a major change and is more advanced use of Volumes. While offering some advantages, you really need to do it as a new install & restore all data from backups.
    – oldfred
    Aug 8, 2020 at 18:17
  • I saw a few other sources (including other answers) which asked me to use rsync and not cp. Do both do the job?
    – VBtheHun
    Aug 9, 2020 at 6:12
  • @VBtheHun rsync was made for comparing two directories or directory trees and eliminate the differences (or some of them). It was especially made for doing this over a network. In that case it does a much better job than scp/cp. But in case of an empty target directory none of the rsync features is relevant (unless the procedure is interrupted). So in your case rsync is at least not better than cp. Aug 9, 2020 at 16:32
  • @HaukeLaging can confirm that using cp in lieu of rsync worked absolutely fine. Thanks!
    – VBtheHun
    Aug 10, 2020 at 19:43
0

If you can delete /dev/sda5 (it seems empty/unused?)

If that is true, then there's a quite simple way to do it with the Gparted UI:

  1. delete /dev/sda5
  2. Move the neighbouring /dev/sda8 to the front (where sda5 was located)
  3. move+enlarge /dev/sda11 as you please

The system will have to physically move the ~27GB of sda5 (/) and possibly also the 55GB of sda11 (/home), so depending on your disk that might take some hours.

Otherwise

You'd need a terminal to do the trick. Either copy the whole sda11 partition over sda5 with a dd like this:

dd if=/dev/sda11 of=/dev/sda5 bs=1M

... or assign /dev/sda5 some mountpoint and copy the data with rsync or whatever file manager you prefer (just be careful to use rsync's -an option to keep access rights). When done, change remove sda11's mountpoint and change sda5 to /home .

3
  • Do not use dd on gpt partitions, only on a full drive. And dd generally not best tool. The cp -a or rsync with various parameters are better options if copying data. See post #12 by author of gdisk. ubuntuforums.org/showthread.php?t=1680929&page=2
    – oldfred
    Aug 8, 2020 at 22:54
  • @oldfred "Do not use dd on gpt partitions, only on a full drive." What gave you that strange idea...? Aug 10, 2020 at 20:22
  • The author of gdisk years ago said not to use dd on a gpt partition. Do not use dd to copy partition with gpt due to unique guids & UUIDs post #12 ubuntuforums.org/showthread.php?t=1680929 The GUID is stored in the primary partition table, backup partition table & partition. It may be possible to fix GUID with gdisk. You can use dd to copy an entrire drive, but generally dd is not the safest (nickname Data Destroyer) or best tool (copies empty space).
    – oldfred
    Aug 10, 2020 at 20:52
0

Before anything major like this, make sure your backups are up to date.

To move /home uses rsync- Be sure to use parameters to preserve ownership & permissions.

help.ubuntu.com/community/Partitioning/Home/Moving

But you also can use it as a data partition. I keep /home inside / (root) and /home is about 3GB, but have all data in linked folders from a data partition. Does not have to be a second drive as these examples show. Just any other partition.

https://askubuntu.com/questions/1013677/storing-data-on-second-hdd-mounting

https://askubuntu.com/questions/1058756/installing-all-applications-on-a-ssd-disk-and-putting-all-files-on-hdd-disk

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .