Disk breakdown: Difference between revisions

From Hackepedia
Jump to navigationJump to search
breakdown of a disk from ffs
 
Line 3: Line 3:
I created a virtual disk, it is 32MB big:
I created a virtual disk, it is 32MB big:


# dd if=/dev/zero of=disk bs=32m count=1
1+0 records in
1+0 records out
33554432 bytes transferred in 0.164 secs (203728139 bytes/sec)
  # ls -lh disk
  # ls -lh disk
  -rw-r--r--  1 root  wheel  32.0M Oct 28 08:55 disk
  -rw-r--r--  1 root  wheel  32.0M Oct 28 08:55 disk

Revision as of 10:24, 28 October 2005

A breakdown of a disk

I created a virtual disk, it is 32MB big:

# dd if=/dev/zero of=disk bs=32m count=1
1+0 records in
1+0 records out
33554432 bytes transferred in 0.164 secs (203728139 bytes/sec)
# ls -lh disk
-rw-r--r--  1 root  wheel  32.0M Oct 28 08:55 disk

WTF? It's a file! Ok so lets make it a disk device:

# vnconfig -cv svnd0 disk
svnd0: 33554432 bytes on disk

let's make a new partition on it called a:

# disklabel -E /dev/rsvnd0c
disklabel: Can't get bios geometry: Device not configured
Initial label editor (enter '?' for help at any prompt)
> a
partition: [a] 
offset: [0] 
size: [65536] 
FS type: [4.2BSD] 
> p a
device: /dev/rsvnd0c
type: SCSI
disk: vnd device
label: fictitious
bytes/sector: 512
sectors/track: 100
tracks/cylinder: 1
sectors/cylinder: 100
cylinders: 655
total sectors: 65536
free sectors: 0
rpm: 3600
16 partitions:
#             size        offset  fstype [fsize bsize  cpg]
  a:         65536             0  4.2BSD   2048 16384   16 # Cyl     0 -   655*
  c:         65536             0  unused      0     0      # Cyl     0 -   655*
> q
Write new label?: [y] y
# 

Now write the filesystem on it with newfs:

# newfs /dev/rsvnd0a
Warning: cylinder groups must have a multiple of 8 cylinders
Warning: 64 sector(s) in last cylinder unallocated
/dev/rsvnd0a:   65536 sectors in 656 cylinders of 1 tracks, 100 sectors
       32.0MB in 1 cyl groups (656 c/g, 32.03MB/g, 4096 i/g)
super-block backups (for fsck -b #) at:
 32,

mount the new filesystem to /mnt:

# mount /dev/svnd0a /mnt
# df /mnt
Filesystem  512-blocks      Used     Avail Capacity  Mounted on
/dev/svnd0a      64412         4     61188     0%    /mnt
# df -i /mnt
Filesystem  512-blocks      Used     Avail Capacity iused   ifree  %iused  Mounted on
/dev/svnd0a      64412         4     61188     0%       1    4093     0%   /mnt

OK let's count it up, we have 65536 blocks in total for the disk, 4094 inodes exist at 128 bytes size which is 1023 blocks, and we have 2 superblocks (0 and 32) which are 16384 bytes big each or 32 blocks, then the filesystem space claims 64412 blocks, this gives us a total of 65499 blocks which isn't quite the complete disksize of 65536 blocks, however I left the disklabel unaccounted for which also takes up some space.

Now let's fill the drive:

$ dd if=/dev/zero of=fill bs=1
/mnt: write failed, file system is full
dd: fill: No space left on device
31326209+0 records in
31326208+0 records out
31326208 bytes transferred in 40.458 secs (774289 bytes/sec)
$ df /mnt
Filesystem  512-blocks      Used     Avail Capacity  Mounted on
/dev/svnd0a      64412     61220       -28   100%    /mnt

100% capacity, but the used blocks aren't all the blocks that the filesystem claims, so let's repeat that last step but this time as root:

# dd if=/dev/zero of=fill bs=1
/mnt: write failed, file system is full
dd: fill: No space left on device
32931841+0 records in
32931840+0 records out
32931840 bytes transferred in 44.276 secs (743779 bytes/sec)
# df /mnt
Filesystem  512-blocks      Used     Avail Capacity  Mounted on
/dev/svnd0a      64412     64356     -3164   105%    /mnt

Lovely almost all used up and it can't go further. Note that we're using up 105% capacity this is built into ffs and can be tweaked at newfs time. The superuser gets 5% above 100% of capacity noone else.