FileSystems

From Alessandro's Wiki

Sizes

Kilobyte  - KB	1024 Bytes
Megabyte  - MB	1024 KB
Gigabyte  - GB	1024 MB
Terabyte  - TB	1024 GB
Petabyte  - PB	1024 TB
Exabyte   - EB	1024 PB
Zettabyte - ZB	1024 EB
Yottabyte - YB	1024 ZB

print a list of directories with more files

find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n

SSD

  • ssh drives behave differently from disks, to allow proper use of the TRIM command in delete operations, I must use ext4 and enable this feauture in the /etc/fstab file:
/dev/sda1   /   ext4   rw,defaults,discard 1 1
  • SSD in LVM
/etc/lvm/lvm.conf
issue_discards = 1
  • trim manually the root filesystem
fstrim -v /

ext2

  • basic old non-journalized linux filesystem

ext3

  • the officialjournalized Linux file system

Disk Labels

swap

   swaplabel -L <label> /dev/XXX using util-linux 

ext2/3/4

   e2label /dev/XXX <label> using e2fsprogs 

btrfs

   btrfs filesystem label /dev/XXX <label> using btrfs-progs 

reiserfs

   reiserfstune -l <label> /dev/XXX using reiserfsprogs 

jfs

   jfs_tune -L <label> /dev/XXX using jfsutils 

xfs

   xfs_admin -L <label> /dev/XXX using xfsprogs 

fat/vfat

   dosfslabel /dev/XXX <label> using dosfstools 

fat/vfat

   mlabel -i /dev/XXX ::<label> using mtools 

ntfs

   ntfslabel /dev/XXX <label> using ntfs-3g 

Encryption

In my examples I'll use the following information:

  • disk device: /dev/sdf (first partition, /dev/sdf1)
  • disk label: bkdisk
  • disk uuid: cdf1b76e-4d5d-4209-af51-d4d890253110
  • encrypted media name/label: crypdisk
  • encrypted media FStype: xfs
  • encrypted media uuid: 2381b61f-adac-4339-80c4-706186c50b39

encrypt a sparse disk image

I'll create a sparse disk image in an harddisk for backup purposes:

  • get the free space from the disk into the BK_FREE variable :
BK_FREE=`df -BG /dev/sdf1|awk '{print $4}'|tail -1`
  • decide a name for the image:
bkname=crypdisk.img
  • create the file with "truncate"
truncate -s $BK_FREE   "$bkname"
  • create the file with "dd"
dd if=/dev/zero of=IMAGEFILE bs=1 count=1 seek=SIZE
  • add the encription to the just created file
cryptsetup luksFormat --key-file /root/crypdisk.key "$bkname"
  • extended options:
--cipher aes-xts-plain --size 512
cryptsetup luksOpen "$bkname" crypdisk
mkfs.xfs  /dev/mapper/crypdisk
  • finally create the filesystem:
mkfs.xfs  "$bkname"

encrypt a disk partition

  • format with encryption the partition
cryptsetup luksFormat --key-file /root/crypdisk.key /dev/sdf1
  • create the filesystem:
cryptsetup luksOpen /dev/sdf1 crypdisk
mkfs.xfs  /dev/mapper/crypdisk

mounting

cryptsetup luksOpen /dev/sdf1 crypdisk
mount /dev/mapper/crypdisk /media/crypdisk -t xfs
  • or by uuid
mount UUID=2381b61f-adac-4339-80c4-706186c50b39 /media/crypdisk -t xfs
  • using the key file
cryptsetup luksOpen /dev/sdf1 -d crypdisk.key -S 1 crypdisk

umounting

umount /dev/sdf1 
cryptsetup luksClose /dev/mapper/crypdisk

key-file

  • generate
dd if=/dev/random of=/root/random_data_keyfile1 bs=512 count=1
  • add a password to a device
cryptsetup luksAddKey /dev/sda
Enter any existing passphrase:
  • add key-file to device
cryptsetup luksAddKey /dev/sda /root/random_data_keyfile1

permanent mounting

  • the file to store information to mount the partitions at boot is /etc/crypttab , similar to /etc/fstab
blkid|egrep '(/dev/sdf1|crypdisk)'
/dev/sdf1: UUID="cdf1b76e-4d5d-4209-af51-d4d890253110" TYPE="crypto_LUKS" 
/dev/mapper/crypdisk: LABEL="crypdisk" UUID="2381b61f-adac-4339-80c4-706186c50b39" TYPE="xfs" 
  • create the hashed version of your password into a file:
cryptsetup luksAddKey UUID="cdf1b76e-4d5d-4209-af51-d4d890253110" /root/crypdisk.key
  • then add this in /etc/fstab
UUID="2381b61f-adac-4339-80c4-706186c50b39" /media/crypdisk xfs    rw,users 0 0
  • ...and this in /etc/crypttab
# <name>       <device>         <password>              <options>
crypdisk        UUID="cdf1b76e-4d5d-4209-af51-d4d890253110" /root/crypdisk.key

getting info

#  cryptsetup luksDump /dev/sdf1
LUKS header information for /dev/sdf1

Version:        1
Cipher name:    aes
Cipher mode:    cbc-essiv:sha256
Hash spec:      sha1
Payload offset: 4096
MK bits:        256
MK digest:      
MK salt:        
                
MK iterations:  
UUID:           cdf1b76e-4d5d-4209-af51-d4d890253110

Key Slot 0: ENABLED
        Iterations:             
        Salt:                   
        Key material offset:    8
        AF stripes:             
Key Slot 1: ENABLED
        Iterations:             
        Salt:                   
        Key material offset:    
        AF stripes:             
Key Slot 2: DISABLED
Key Slot 3: DISABLED
Key Slot 4: DISABLED
Key Slot 5: DISABLED
Key Slot 6: DISABLED
Key Slot 7: DISABLED

ext4 (not ext4dev anymore)

  • file system creation
mkfs.ext4 /dev/device -m0 -Letichetta

(dopo il seguente comando, il filesystem perderà la compatibilità con ext3)

tune2fs -O extents,uninit_bg,dir_index /dev/device
Timing cached reads:   1858 MB in  2.00 seconds = 929.12 MB/sec
Timing buffered disk reads:  280 MB in  3.01 seconds =  93.15 MB/sec


  • checking for ext4 fragmentation
[root@localhost ~]# e4defrag -c /dev/sda1
<Fragmented files>                             now/best       size/ext
1. /boot/grub2/grub.cfg                          2/1              3 KB
2. /boot/System.map-3.11.6-200.fc19.x86_64
                                                2/1           1313 KB
3. /boot/vmlinuz-3.11.4-201.fc19.x86_64          2/1           2514 KB
4. /boot/vmlinuz-3.11.3-201.fc19.x86_64          2/1           2514 KB
5. /boot/initramfs-3.11.3-201.fc19.x86_64.img
                                                2/1           4683 KB
Total/best extents                             368/359
Average size per extent                        322 KB
Fragmentation score                            0
[0-30 no problem: 31-55 a little bit fragmented: 56- needs defrag]
This device (/dev/sda1) does not need defragmentation.
Done.

XFS

Creazione

mkfs.xfs /dev/device -Letichetta

Frammentazione / Fragmentation

  • controllo stato:
xfs_db -c frag -r /dev/ <disk>
  • deframmentazione:
xfs_fsr
default parameters
xfs_fsr
 -m /etc/mtab              Get all defragmentable devices
 -t 1000                   Seconds to work
 -f /var/tmp/.fsrlast_xfs  Contains last file defragmented

Non è necessario deframmentare:

actual 992345, ideal 980834, fragmentation factor 1.16%

È necessario:

actual 511775, ideal 180931, fragmentation factor 64.65%
xfs_db -c frag -r  /dev/sdg1
actual 398296, ideal 335829, fragmentation factor 15.68%
xfs_fsr -t 1000
[...]
xfs_db -c frag -r  /dev/sdg1
actual 372842, ideal 335829, fragmentation factor 9.93%

ISO

mkisofs -f -J -r -l -v -volid "Volume Name" source_folder > iso_file_name.iso

Opzioni

-f, -follow-links --> Follow symbolic links
-V ID, -volid ID --> Set Volume ID
-volset ID --> Set Volume set ID
-volset-size # --> Set Volume set size
-volset-seqno # --> Set Volume set sequence number
  • File System: Joliet
 -J, -joliet --> Generate Joliet directory information
  • File System: ISO9660
 -l, -full-iso9660-filenames --> Allow full 31 character filenames for ISO9660 names
  • File System: ISO9660 relaxed (violates ISO9660)
 -max-iso9660-filenames --> Allow 37 character filenames for ISO9660 names (violates ISO9660)
 -allow-leading-dots --> Allow ISO9660 filenames to start with '.' (violates ISO9660)
 -ldots --> Allow ISO9660 filenames to start with '.' (violates ISO9660)
 -N, -omit-version-number --> Omit version number from ISO9660 filename (violates ISO9660)
 -relaxed-filenames --> Allow 7 bit ASCII except lower case characters (violates ISO9660)
 -no-iso-translate --> Do not translate illegal ISO characters '~', '-' and '#' (violates ISO9660)
 -allow-lowercase --> Allow lower case characters in addition to the current character set(violates ISO9660)
 -allow-multidot --> Allow more than one dot in filenames (e.g. .tar.gz) (violates ISO9660)
 -U, -untranslated-filenames --> Allow Untranslated filenames (for HPUX & AIX - violates ISO9660). Forces -l, -d, -N, -allow-leading-dots,
 -relaxed-filenames, -allow-lowercase, -allow-multidot 
  • File System: Rock Ridge
 -r, -rational-rock --> Generate rationalized Rock Ridge directory information
 -R, -rock --> Generate Rock Ridge directory information
  • File System: UDF
 -udf --> Generate UDF file system
 -dvd-video --> Generate DVD-Video compliant UDF file system


ReiserFS

3.6

# mkfs.reiserfs /dev/md8 -l usr --format 3.6
mkfs.reiserfs 3.6.19 (2003 www.namesys.com)

A pair of credits:
Nikita Danilov  wrote  most of the core  balancing code, plugin infrastructure,
and directory code. He steadily worked long hours, and is the reason so much of
the Reiser4 plugin infrastructure is well abstracted in its details.  The carry
f unction, and the use of non-recursive balancing, are his idea.

Edward Shushkin wrote the encryption and compression  file plugins,  and the V3
journal relocation code.

Format 3.6 with standard journal
Count of blocks on the device: 4196944
Number of blocks consumed by mkreiserfs formatting process: 8340
Blocksize: 4096
Hash function used to sort names: "r5"
Journal Size 8193 blocks (first block 18)
Journal Max transaction length 1024
inode generation number: 0
UUID: e620b92a-67b0-4d84-a193-2fea4ceb756a
LABEL: usr
ATTENTION: YOU SHOULD REBOOT AFTER FDISK!
        ALL DATA WILL BE LOST ON '/dev/md8'!
Continue (y/n):y
Initializing journal - 0%....20%....40%....60%....80%....100% 
Syncing..ok

Tell your friends to use a kernel based on 2.4.18 or later, and especially not a
kernel based on 2.4.9, when you use reiserFS. Have fun.

ReiserFS is successfully created on /dev/md8.


4

  • Creo il filesystem per la dir /usr/portage
# mkfs.reiser4 /dev/md8 -L usr -b 4096 -s 
mkfs.reiser4 1.0.6
Copyright (C) 2001-2005 by Hans Reiser, licensing governed by reiser4progs/COPYING.

Block size 4096 will be used.
Linux 2.6.29-gentoo-r5 is detected.
Uuid 4f849b56-1169-4396-81c8-8d0244254b3b will be used.
Reiser4 is going to be created on /dev/md8.
(Yes/No): Y

NTFS

Fat32