Sunday, February 11, 2007

Create New Filesystems via Command Line

Creating multiple filesystems is fairly easy using Solaris. We can create or re-create filesystems when we want to expand a slice or can't recover it with FSCK. In the example, we assume the filesystem is unmounted and it's a raw partition, i.e. rdsk.

Here's the example.

Creates a new filesystem on slice 3. It will prompt you for a go ahead response, y or n.
#newfs /dev/rdsk/c0t0d0s3

Loop the task for multiple slices. It will prompt you for a go ahead response, y or n, for each iteration. Gives you a chance to abort your decision.
#for slice in 0 3 4 5 6 7
do
newfs /dev/rdsk/c0t0d0s$slice
done

Loop the task for multiple slices. It will NOT prompt you for a go ahead response, y or n, for each iteration. Assumes you know what you are doing.
#for slice in 0 3 4 5 6 7
do
echo y | newfs /dev/rdsk/c0t0d0s$slice
done

1 comment:

UX-admin said...

Tip: tuning UFS for different workloads

When laying down a new UFS file system on the slice, there are several options that can be tweaked and which might improve performance or result in more available space in the UFS file system.

To lay down a new UFS file system optimized for speed, use:


newfs -v -b 8192 -m 0 -o time /dev/rdsk/c#t#d#s#


And for an UFS file system optimized for space, use:

newfs -v -b 8192 -m 0 -o space /dev/rdsk/c#t#d#s#


To lay down a file system expected to house very large amounts of data:

newfs -v -b 8192 -m 0 -o time -T /dev/md/rdsk/d#[##]


Let's go over some of these options.

-v verbose; pretty print what's being done

-b 8192 set the UFS block size to 8KB; currently, this is the largest block size that UFS supports. Unlike some other file systems, it is quite OK to use the biggest block size available, because UFS supports logical block allocation (by allocating block fragments), so files smaller than 8KB shouldn't actually occupy 8KB on disk; the smallest logical block that can be allocated inside of an UFS block is 1KB, which is also the default

-m 0 specifies that 0% be allocated as "emergency reserve" free space; normally, on OS disk(s), 1-3% are kept as a reserve that only root and root processes can use when the disk fills up; setting -m to a percentage effectively prevents a disk from filling up. This of course only works if the writer process is not running as root

-o space|time specifies whether to optimize the space fragmentation on the disk, or to minimize the time spent on block allocation

-T prepares the newly laid out UFS file system for eventual growth over a terabyte; it is expected that growfs(1M) will then be used at some point in time, which also implies that file systems which use -T are usually laid down on metadevices managed by some kind of a volume manager, such as the Sun Volume Manager (SVM) or the Veritas VxVM.

We can even tweak a knob or two at the lower level of the file system: by specifying a lower inode/cylinder group ratio, there will be less inodes available and the file system won't be able to support as many files, but there will be more space available because the FS overhead is less. This little tweak can be used for file systems expected to contain large files, or a lower amount of files, and where space is needed and preferred above everything else:


newfs -v -b 8192 -i 16384 -m 0 -o time /dev/rdsk/c#t#d#s#


The manual pages for newfs(1M) and growfs(1M) contain lots of interesting details on the subject.