[SOLVED] Format external hdd as ext4 without losing data?
Linux - HardwareThis forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a 300 external usb drive which I have got when using windows and so is using a fat32 filesystem. I have since moved to linux only and am mounting the drive as vfat however I think I may as well convert it to ext4 if possible for (amongst others) performance and security reasons. The problem is I don't have a separate drive which would hold the 250gb of data temporarily whilst I changed the filesystem of the drive so I am hoping there is a way to format as ext4 whilst retaining the files?
I know partition magic on windows allowed you to change between filesystems whilst keeping the data but does anything similar (and free! ) exist for linux?
I know you can move from Fat32 to NTFS easily in Windows. In Linux you can have the same from ext3 to ext4 as far as I know (maybe even to other Linux native types). But I seriously doubt that you'll be able to reformat your fat32 to ext4 without losing your data. As far as I know the only way is to copy the data to another location, format the drive and copy the files to the new filesystem. Since you don't have that possibility I don't think you have another option than to stay with fat32.
I hope someone will contradict me and give you a solution.
Interesting situation. I believe EricTra is correct on both: I know of no way to "reformat while retaining the data", but you *can* use tune2fs to 'upgrade' from a lesser Ext Linux filesystem, to a newer one.
As for the free version of Partition Magic, that would be "Gparted".
My suggestion for you (which I admit is not pretty), is to shrink the FAT partition as small as you can (to the upper limit of the data on it) using gparted, then in the empty space created on the disk, make a new Ext partition, and move as much data as you can, onto the new partition.
Then delete that data from the FAT partition, and shrink it again..
Then, move the new partition down again into the NEW new space, and stretch it again... See where this is going?
REPEAT: Not pretty. And also, before undertaking such an endeavor, it's always wise to make a backup of all your data before proceeding. Err-- wait now lol. Kidding.
Hi,
Thatnks for the replies - it was not what I was hoping for, but what I was expecting. My issue is the drive is only 300GB and I'm using over 200GB already. I'm not too keen on doing something which might risk me losing everything!
I thought about backing up to DVD but there's a lot of data and it would also take forever arranging which folders are to go on which disc.
What I might do is wait until someone I know is in the market for a new drive, ask if I ca borrow it before they even use it and then copy everything over, wipe mine and re-format and then copy back over.
With it being FAT, will it suffer from fragmentation problems? I could plug it into my work laptop I guess (running windows) and defrag it now and again, but ultimately I'd rather just get it over to a proper filesystem!
With it being FAT, will it suffer from fragmentation problems?
Possibly... It depends mostly on how much you manipulate the data. i.e. spreadsheets and databases that are updated frequently could become quite fragmented. However, I'd be concerned with using a Windows defragmenter with Linux files; MS has always warned against using older versions on newer Windows files. If someone else knows better, feel free to correct me, but for now I'd say don't do it.
It's mainly an archive, ie, files written to once, and the maybe accessed but not over-written, replaced, deleted etc.
'd still of course rather move over to a better filesystem - it might be a "project for the future" though!
That'd be worth the trouble. The biggest flaw in the FAT32 FS (and why MS moved away from it) was the waste of drive space. The smallest allocatable block was 32k, so effectively and realistically, a 1k file used 32k of space, a 33k file used 64k of space, etc., etc., etc. Depending on how many files you have and their actual sizes, you may regain a substantial amount of free space on the drive by switching.
First, move the drive to a M$ based system and do the de-fragmentation since that would be the easiest and safest method.
Then do a backup to the media of choice before you do anything.
If you have the space on your resident OS you could create a smaller backup partition. Then use your parted LiveCD to shrink the FAT filesystem partition since you have about 50GB available. Then create a new 'ext' formatted partition on that space. Then on the M$ drive that you could move a portion of files over to the new ext formatted partition. After that move temporarily another portion of files to the previous created space on the Host filesystem. Once this is done go ahead an shrink the FAT again to extend or create another partition for the ext filesystem on the M$ drive. Repeat the operation until you have the drive converted. Note you will need to have the means to tag what is moved. Not pretty but doable.
You could 'tar' or 'zip' the files for a successful move but then you would be sure to test the archive.
Devnull,
Please compare cost of lost data to cost of having a separate archive. I have paid that cost more than twice. I hope you avoid the data loss troubles I have caused me.
Surely having a separate archive is better than having the data stored on your os drive? Wouldn't there be less chance of anything going wrong with a drive which is accessed only now and again vs one which is in constant use by other areas of the os?
I have managed to free up some space on my primary hdd so I am in the process of copying everything across. Once I have verified that everything has come across ok I'm going to switch to ext4 and then copy back across. Wish me luck!!
Something to look into is the system rescue cd. It has a tool called fsarchiver that will image a disk, backing up only used bits, it will compress the archive, and it can then restore the data back to a file system different from what the data came from. The cd also has tools like gparted to partition the drive etc. It's really pretty slick, the only downside I see in your case is the amount of data... I'm not sure just how far 250GB can be compressed.
I personally like to have an ntfs archive, just in case I might need a full windows installation at some point, the data is still available without too many hoops to jump through. I generally only mount that disk manually when I want to backup, thus making it a little safer from myself mostly.
so devnull10, what exactly did you do? Did you do like post 11 says, and just copy everything out, reformat, and copy everything back?
Nice @ gaining a few Gib -- good stuff!
I have my hdd on my machine partioned and mounted against /opt /var /home etc. So I deleted some old stuff and created some folders spread out across these partitions so the total amount would be enough to hold the stuff on the external drive.
I then just copied everything across into those folders (cp command). Then I did a bit of trickery with the shell to basically list all files in the folders and on the drive, sort uniq and do a comparison between old an new. - all ok!
Then I just fdisk'ed the drive and created a new partition of type 82 and used mkfs.ext4 to set it up. Edited my fstab file to be ext4 rather than vfat. Copied everything back across, checked the file list again and then did a recursive update of permissions (they were all 777) to be 755.
All good!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.