[SOLVED] Erasing a disk before writing and expanding a fs image
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Erasing a disk before writing and expanding a fs image
I'm writing a small ext4 image I've built to a block device in Linux using the dd utility.
i.e.
Code:
dd if=/root/ext4image.img of=/dev/'blockdevice'
After this, I delete the partition on the device with fdisk and recreate it to use the rest of the disk. I then run fsck to check the disk and then finally resize2fs to resize the file system. This works for me just fine.
My main question with this method is, is it necessary to erase the disk first?
i.e.
Code:
dd if=/dev/zero of=/dev/'blockdevice'
Are there any consequences to not erasing it first?
Not from an ext4 standpoint. It will recognize the additional space you give it with the resize2fs.
Since you're using a partition you'd have to make sure you see the additional space at OS level before you did the resize2fs of the filesystem. (e.g. After the change use fdisk -l or parted to verify the OS sees the additional space.
If you do not erase the disk completly, the data in the area, which was not overwritten by the image, will be kept.
So let's say I have a full device with an ext4 file system. I then perform my method of writing this smaller image, then re-partitioning and expanding. It is than possible that the files from the previous full file system are still present in this new one? Where would they be, in lost+found?
"Kept" only in the sense of still available for forensic recovery. If you ever do run into a problem where you have to resort to recovery tools like testdisk and photorec, it can be a bit confusing to have them discovering that old data. Other than that and privacy concerns, there's no need to erase the disk.
That said, I generally do zero a hard disk or flash drive (though probably not an SSD) before re-using it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.