I would:
- resize the filesystem in-place with something like
resize2fs -p /dev/<device_name_fs_is_on> 20G
It will undoubtedly refuse to run first time, suggesting that you run fsck
first. You can force it to run, but the fsck
operation is strongly recommended as trying to resize a filesystem with errors (even minor ones) could lead to disaster. Rerun the resize command once the check is completed
- copy it to the other drive with
dd if=/dev/<device_name_fs_is_on> of=/path/to/other/location/filesystem.img bs=1048576 count=20480
- reformat the disks as needed
- copy the filesystem back with
dd if=/path/to/other/location/filesystem.img of=/dev/<new_device_name>
- resize up to fill the new partition with
resize2fs -p /dev/<new_device_name>
- mount the newly resized filesystem and edit any relevant config it contains, like /etc/fstab
- you will also need to check your grub configuration to make sure it refers to the new root partition name and you may need to rebuild your initrd (though probably not as you are going from RAID to normal not the other way around which causes problems if the initrd is not RAID aware)
- cross your fingers and reboot...
As this is your root filesystem, you are going to need to do this from a live CD as you will not be able to resize the filesystem (step 2) while it is mounted.
If you change the 20G passed to resize2fs
in step 1, make sure you change the 1048576x20480 passed to dd
in step 2 accordingly.
Obviously this is not a risk free operation, so you might want to separately backup important data+configuration on the filesystem by other means before step 3.
For even greater safety: if you have time and a disk to spare, restore the shrunk filesystem to the extra disk, reconfigure appropriately as per steps 6 & 7, and make sure you can boot off that before progressing to step 3. This way you know you have a fully working copy of the filesystem elsewhere before wiping it from the old location, and can easily revert back to the old setup and abort/retry if you discover problems at that stage.
This way you are not going to lose any file/directory/device properties while copying stuff around as you are operating on the filesystem wholesale rather than individual files, dirs and device nodes.
Using pv instead of dd can give progress in disk cloning. As with dd user would not see the progress till the end of the process or an error. – pbies – 2013-08-27T16:31:17.923
@pbies you can see progress with dd. The method is open up a new shell and find the dd pid:
pgrep -l '^dd$'
then issue a watch and kill to the pidwatch -n 10 kill -USR1 8789
This will output dd's progress every 10 seconds. – Verdi Erel Ergün – 2014-03-11T17:15:35.983I usually use
pv
myself for the progress indicator, but I stick withdd
andcat
when giving examples publicly as they are found almost everywhere andpv
, while increasingly available by default in Linux distributions, is much less common on out-of-the-box installs. – David Spillett – 2014-03-11T20:38:27.467