LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-25-2014, 06:10 PM   #1
cilbuper
Member
 
Registered: Mar 2008
Posts: 140

Rep: Reputation: 0
Question Cloning bootable USB flash drive onto larger flash drive - best method?


I have a server running on a USB flash drive and I need to move it to a larger drive. I'd like to keep the server up and running if it is possible, at least until the new drive is ready and all I have to do is reboot.

I know how to use ddrescue and already gave this a try. I copied the original 8gb drive to a 32gb drive. It has 2 primary partitions (sda1, sda2) and an extended partition (sda5 - swap) - both were partitioned to 4gb. I expanded sda2 to take up the rest of the drive so it ended at the end of the drive, moved the data so that sda5 started at about 24GB mark, giving it 8GB space, then moved the beginning of sda2 to the beginning point of sda5 (leaving a large open space between the 2 primary partitions. I then resized sda1 to end at the 24GB mark (where sda2 starts) taking up all the remaining free space in the middle. So now the whole drive is in use



When I try to boot from the larger drive I get the screen where I choose which installed version of Linux to run, run recovery mode, memtests, etc. When I select any of the linux options it says that there isn't enough room or space.

I really need to get the new drive working and can shut down the server if I have to but would like to know if it is possible to do it while it is still running.

Anyone have any ideas on how to do this?
 
Old 02-25-2014, 08:29 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,513

Rep: Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133
Not much to go on. What linux distribution/version are you running?
What did you use to resize the partitions/filesystems? gparted?
When during the boot phase did you see this message?

swap does not contain data when it isn't in use so you could delete sda2(sda5) and extend/resize sda1 as desired. Then recreate sda2 (extended partition) and sda5 (swap). Reformat swap using the same UUID as the original swap. Look the fstab file to see if your OS is using UUIDs.
 
1 members found this post helpful.
Old 02-25-2014, 08:55 PM   #3
sgosnell
Senior Member
 
Registered: Jan 2008
Location: Baja Oklahoma
Distribution: Debian
Posts: 1,054

Rep: Reputation: 281Reputation: 281Reputation: 281
Yes, just delete the partitions with swap, extend the root parition as you need, and leave space at the end for swap. You can put swap into an extended partition or not, it doesn't really matter. Swap is just swap, not formatted, and nothing is stored there when the system is not running. AFAIK you can't do this while the system is running.
 
1 members found this post helpful.
Old 02-25-2014, 08:55 PM   #4
sgosnell
Senior Member
 
Registered: Jan 2008
Location: Baja Oklahoma
Distribution: Debian
Posts: 1,054

Rep: Reputation: 281Reputation: 281Reputation: 281
Yes, just delete the partitions with swap, extend the root parition as you need, and leave space at the end for swap. You can put swap into an extended partition or not, it doesn't really matter. Swap is just swap, not formatted, and nothing is stored there when the system is not running. AFAIK you can't do this while the system is running.
 
1 members found this post helpful.
Old 02-26-2014, 02:58 AM   #5
cilbuper
Member
 
Registered: Mar 2008
Posts: 140

Original Poster
Rep: Reputation: 0
I used gparted to resize them, in another linux box. I used ddrescue to do a bit for bit copy of the original to the new drive then moved the drive to a new machine to resize. I'm running ubuntu 12.04.

I got the message about not enough room or space immediately after selecting the version of linux I wanted the bootloader to load (this is the screen that also gives the option for selecting memtest86+ and such). It doesn't get very far, maybe spits out 3-4 lines but they are all similar messages about not loading or to reboot or retry with more space.
 
Old 02-26-2014, 04:43 AM   #6
cilbuper
Member
 
Registered: Mar 2008
Posts: 140

Original Poster
Rep: Reputation: 0
Well I though I understood what I needed to do but I'm not seeing the new primary partition as needing to be resized but it says there is no space left.

I deleted the MBR of the new USB drive. I then fdisk'd the new drive, created a primary partition and used 75% of the sectors (~22GB). I then created sda2 as an extened partition using the remaining sectors. I then created a logical partition - sda5 - using the same sectors as sda2 - taking up all the remaining room on the drive. I then changed the partition type from 83 Linux to 82 swap on sda5. Then wrote the changes.

Now that I thought the partitions were set up I did dd rescue: ddrescue -d -f -r3 /dev/sdb1 /dev/sda1 -- ( old primary partition copied to new primary partition on larger drive). Completed successfully. mounted the new partition in /mnt/temp and ran "df" to see how much space was left on the partition. It shows the same results as the original smaller drive - 97% used.

Moved new drive to other linux box and ran gparted on it thinking I had to resize the partition (Maybe I misunderstand this part) because it was showing 97% used.

I also was trying to find out how to change the UUID of the swap but could only find how to generate a new random one.

Sorry for not getting this right the first time, but thank you for the help!
 
Old 02-26-2014, 10:51 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,513

Rep: Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133Reputation: 3133
The option should be available with 12.04.
sudo mkswap -U uuid /dev/sdx5 (Make sure you get the sda vs sdb correct...) (where uuid is the old swap UUID)

I'm not sure at the moment what generates the out of space message. Hopefully others will chime in.
Another method would be to create the desired partitions and instead of using the dd command, format the partition then mount your new / to /mnt/new_drive (as an example) and then use the cp command to copy everything over i.e.

sudo cp -pr /*.* /mnt/new_drive

Copy the bootloader via dd i.e.
sudo dd if=/dev/sdx of=/dev/sdy bs=446 count=1

Be very careful to make sure the source and destination drives are correct. To be safe do you have a backup?

Be sure to format swap.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bootable USB flash drive muhamed.ahmovic Linux - Newbie 2 10-17-2012 02:07 AM
Make bootable usb Flash drive hunzak Linux - Newbie 5 10-11-2010 02:42 PM
Bootable USB Flash Drive saurabhchokshi Linux - Newbie 1 07-15-2009 08:42 PM
Can't make bootable USB flash drive sheine Linux - Software 12 04-30-2009 04:32 PM
How to create bootable USB flash drive EStester Linux - Enterprise 7 05-19-2005 07:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration