Jump to content

How to clone a 500GB Debian boot disk with plenty of free space to a 256GB SSD?

GameRetro
Hi, I have Debian on a tiny PC used as a home server, running Debian.
 
I wanna swap the 500GB disk for a 256GB SSD but not lose the bootability and any of the setup I've made.
 
So far I've only managed to shrink the volume on the 500GB disk down to 180GB using an ubuntu live bootable disk and attaching both drives to my main PC (windows machine). There is also an extended partition of 975M on the disk, and there's something called Swap underneath it.
 
I tried various guides but no luck. I tried some dd commands that broke the mbr record for the destination disk... I have very little knowledge of Linux so please bear with me.
 
Here's screenshots of the current GPARTED, gdisk -l and fdisk -l info of the disks:
( 500GB SOURCE DISK is /dev/sdd | 256GB destination disk is /dev/sdc )
 
Thanks in advance! I'll be online and available to try whatever you might suggest, and reply as quickly as possible.
Link to comment
Share on other sites

Link to post
Share on other sites

Gparted should let you move that swap partition to the end of the main partition. Trhn clone the disk over to the ssd, then move the swap partition again and expand the main paerition.

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, Electronics Wizardy said:

Gparted should let you move that swap partition to the end of the main partition. Trhn clone the disk over to the ssd, then move the swap partition again and expand the main paerition.

Alredy thought of that and tried doing it - can't be moved.

 

EDIT: Just tried again. It' stuck to the end. I can expand it all the way but I can't then reduce the right side.

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, GameRetro said:

Alredy thought of that and tried doing it - can't be moved.

Are you booted from the the system your editing? You normally need to be booted from a live disk to do this,

 

You can also disable the swap file in /etc/fstab, then delete it and clone.

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, Electronics Wizardy said:

Are you booted from the the system your editing? You normally need to be booted from a live disk to do this,

 

You can also disable the swap file in /etc/fstab, then delete it and clone.

 

I am pretty much a noob for most of this so you'd have to give me clearer instructions on how disabling a swap file is to be done and how then to actually clone.

 

I am not booted from the same system (thus dev/sdd and dev/sdc) - I already mentioned I am using a live ubuntu thumb drive on my main windows PC. The drives (source and destination) are both connected via USB to SATA adapters.

 

I presume /etc/fstab is some configuration file, so I can probably edit that via any text editor even when not booted from that drive. Do I lose anything from not having a swap file? I would like to avoid deleting things - is there a way to clone just the first partition and then disable the settings in the fstab on the destination drive so it's not looking for a swap file, and then create a new swap file on that drive?

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, GameRetro said:

 

I am pretty much a noob for most of this so you'd have to give me clearer instructions on how disabling a swap file is to be done and how then to actually clone.

 

I am not booted from the same system (thus dev/sdd and dev/sdc) - I already mentioned I am using a live ubuntu thumb drive on my main windows PC. The drives (source and destination) are both connected via USB to SATA adapters.

Opps missed you were booted from it.

 

You can open /etc/fstab in a text editor, then commen out the line that has swap in it(so put a # in the beggining).

 

Then you can delete the partition and it should boot up fine.

Link to comment
Share on other sites

Link to post
Share on other sites

So to get this straight - I would first clone THE DEV/SDD1 PARTITION on to SDC drive, then edit the config file on dev/sdc1/etc/fstab and comment out the swap file line and it would boot?

 

can I then also create that swap partition when booted from SDC? is there any benefit to swap file?

 

---

 

EDIT - googled it and yes I can use DD to clone just the partition - used this command and doing it now (forgot to use a pipe command for progress though lol 😞 )

 

 

dd if=/dev/sdd1  of=/dev/sdc1 
Link to comment
Share on other sites

Link to post
Share on other sites

Okay after much trouble, and many weird errors when the drive was even completely blank space (creating partition showed insuficient space in the created partition, or it would have unallocated space inside the ext4 partition), a ton of commands tried...

 

I finally gave up and booted windows and tried Macrium Reflect once again (had encountered it in some guides for windows cloning). While it doesn't have any linux specific options, once I had resized the original partition on the source drive I could clone both the EXT4 and SWAP partitions to the new drive using advanced options for direct sector to sector cloning, and it even had an option to float the SWAP partition to the end.

 

This completed successfully with slight variations in the swap file size, and unallocated space after it. It even stated in the progress that it was copying and setting up the MBR. This gave me hope so I booted ubuntu live again and just resized the EXT and SWAP partitions to fill out any unallocated space in gparted.

 

Then I installed the 256GB drive in the ThinkCentre and wouldn't you know it - IT BOOTED WITHOUT ISSUES!!!

 

Now when I tried to apt-get upgrade it gave me a blue screen with some text and options saying that the drive GRUB was installed on is no longer present and I had to select dev/sda to reinstall/rebuild GRUB. I think after cloning the partitions I should have either manually reinstalled GRUB through ubuntu live, or I could have even cloned the MBR using DD exactly (which again would probably have resulted in me messing something up)... so since I am not that knowledgeable I am happy that debian has detected and fixed this issue on it's own!! YAY.

 

I rebooted with success after that.

 

So still testing but I would consider this mostly a success!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×