Thought this might be useful to some folks... -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Lonni J Friedman [EMAIL PROTECTED] Linux Step-by-step & TyGeMo http://netllama.ipfox.com
---------- Forwarded message ---------- Date: Mon, 11 Nov 2002 09:51:20 -0500 From: Ian C. Blenke <[EMAIL PROTECTED]> To: Peter W <[EMAIL PROTECTED]>, [EMAIL PROTECTED] Subject: Re: [uml-user] resizing filesystem file On Monday 11 November 2002 07:22, Peter W wrote: > Hello, all. > > I have a root filesystem file (say, root_fs) which has data on it (a > complete OS). That root_fs file is quite small and needs to be made > larger - by increasing the file size without removing any data. > > I know there are a couple commands (dd and a ext2/ext3 resizing program) > which do this but I can't find any examples... could any one give me > one? Most of the time, you will see 512byte blocks. I prefer 1k blocks for this example. To create an image, you merely need to dd a block device and make a filesystem on it. Here's a 10M filesystem example (1024 bytes * 10*1024 blocks), created by seeking over most of the space (creating a sparse file): $ dd if=/dev/zero of=rootfs bs=1024 seek=10k To merely grow an image 1M (1024 blocks of 1024 bytes each) by appending to it, you could do: $ dd if=/dev/zero bs=1024 count=1024 >> rootfs This poses no risk at all to your existing data, as it merely appends the blocks relatively to the end. The downside to this approach is that it doesn't do sparse files. This example seeks to the 11M mark and writes a block, keeping a sparse file (but writing an extra block at the end): $ dd if=/dev/zero of=rootfs bs=1024 seek=11M Note: if you extend a UBD block device in ANY manner, AFAIK, you WILL need to reboot for the UML kernel to see the new geometry. After you've carefully added space to the block device, you need to resize the appropriate filesystem. When resizing an ext2 filesystem, you need to know the actual block size. Resize2fs is an absolute measure, not a relative one (DO NOT DO THIS ON A LIVE MOUNTED FILESYSTEM): $ resize2fs rootfs 11264 or better still: $ resize2fs rootfs `du rootfs | awk '{print $1}'` Reiserfs, however, can be simply grown (DO NOT DO THIS ON A LIVE MOUNTED FILESYSTEM): $ resize_reiserfs -s +1M rootfs And, likewise, XFS can be grown live (YES, YOU MAY DO THIS ON A LIVE FILESYSTEM, but only from within the UML, and only after a reboot of the UML kernel): $ xfs_growfs / This would automagically pick up the new geometry of the UBD block device and grow appropriately. Is there an easy way to make the UML kernel re-read the geometry of a UBD block device without rebooting? > p.s.- the root_fs file is currently 250mb but needs to be like 4 or 5 GB > - depending on the amount of Debian bloat I add. ;) Ok, let me take a stab at the commands you will need. To grow a 250M filesytem to be 4096M, you need (4096-250=3846) additional megabyte sized blocks. $ dd if=/dev/zero bs=1M count=3846 >> rootfs And this command should resize your ext2 filesystem: $ resize2fs rootfs `du rootfs | awk '{print $1}'` The `du rootfs | awk '{print $1}'` part of the above command-line will simply spit out the absolute block size of your current rootfs file. If you're using ext3, you might want to adjust the journal size as well (though 32M, by default, is probably fine for your root volume). BE CAREFUL WITH THESE COMMANDS. Make backups. I claim no responsibility for data loss due to careless commands or accidental typos. These commands work for me, YMMV. Hope this helps someone. - Ian C. Blenke <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> http://ian.blenke.com (This message bound by the following: http://www.nks.net/email_disclaimer.html) ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ User-mode-linux-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-user _______________________________________________ Linux-users mailing list [EMAIL PROTECTED] Unsubscribe/Suspend/Etc -> http://www.linux-sxs.org/mailman/listinfo/linux-users