Linux File Systems
SubTopics
LVM
Encrypted FileSystem
NFS
FileSystems Benchmark
Resize file system
Quota
ISCSI
Zfs on Linux
BTRFS
OCFS2
GlusterFS
Striping
EFI GPT
Luks Encrypted Filesystem
Encrypted FileSystem
NFS
FileSystems Benchmark
Resize file system
Quota
ISCSI
Zfs on Linux
BTRFS
OCFS2
GlusterFS
Striping
EFI GPT
Luks Encrypted Filesystem
Other things
Filesystem and UUID - http://linuxshellaccount.blogspot.com/2008/08/how-to-manage-your-disk-by-uuid-on.htmlundelete
Foremost http://www.ubuntu-unleashed.com/2008/04/howtorecover-and-undelete-text-file-in.htmlhd tuning
# Query your hdd for maximum multi sector transfer supported. hdparm -i /dev/hda | grep MaxMultiSect # setting 32-bit IO_support flag to 1 # setting multcount to 16 hdparm -c1 -k1 -m16 /dev/hda # Benchmark using hdparm hdparm -tT /dev/hda # Tunning LVM # Add to /etc/sysctl.conf vm.max-readahead=256 vm.min-readahead=128
Mount options
| File system | option |
| ext2 | notail,noatime |
| ext3 | data=journal,errors=remount-ro |
| ext4dev | extents (tune2fs -O extents or mke2fs -O extents before mounting with this option) |
IO tuning reference: http://www-128.ibm.com/developerworks/linux/library/l-fs8.html
tmpfs
TMPFS is a Linux file system which keeps all files in virtual memory. It is supported by the Linux kernel from version 2.4 and up. TMPFS distinguishes itself from ramdisk by using memory dynamically, through swapping unneeded pages onto swap space.dd if=/dev/zero of=/.tmpfs bs=1024 count=250000
mkfs -t ext3 /.tmpfs
mount -o loop,noexec,nosuid,rw /.tmpfs /tmp
chmod 0777 /tmp
chmod +t /tmp
mkfs -t ext3 /.tmpfs
mount -o loop,noexec,nosuid,rw /.tmpfs /tmp
chmod 0777 /tmp
chmod +t /tmp
To make this permanent, add the following to /etc/fstab
/.tmpfs /tmp ext3 loop,rw,nosuid,noexec 0 0
loop mount
Take a look at the command losetupswap file
Sometimes it's useful to add swap space using swap files. To create a 500m swap file:dd if=/dev/zero of=swap_file_01 bs=1024 count=500000
mkswap swap_file_01
swapon swap_file_01
mkswap swap_file_01
swapon swap_file_01
To make this permanent, add this to /etc/fstab
/swap_file_01 swap swap defaults 0 0
It's a little more work to do the same thing under freebsd 4.x
# Create a vnode
cd /dev
sh MAKEDEV vn0
# Create a swapfile (/usr/swap0):
dd if=/dev/zero of=/usr/swap0 bs=1024k count=1024
# Set proper permissions on (/usr/swap0):
chmod 0600 /usr/swap0
#Enable the swap file in /etc/rc.conf:
swapfile="/usr/swap0" # Set to name of swapfile if aux swapfile desired.
# Reboot the machine or to enable the swap file immediately, type:
vnconfig -e /dev/vn0b /usr/swap0 swap
# Check swap usage
swapinfo
cd /dev
sh MAKEDEV vn0
# Create a swapfile (/usr/swap0):
dd if=/dev/zero of=/usr/swap0 bs=1024k count=1024
# Set proper permissions on (/usr/swap0):
chmod 0600 /usr/swap0
#Enable the swap file in /etc/rc.conf:
swapfile="/usr/swap0" # Set to name of swapfile if aux swapfile desired.
# Reboot the machine or to enable the swap file immediately, type:
vnconfig -e /dev/vn0b /usr/swap0 swap
# Check swap usage
swapinfo
It's yet a little different on FreeBSD 5.x
#Create a swapfile (/usr/swap0):
dd if=/dev/zero of=/usr/swap0 bs=1024k count=64
#Set proper permissions on (/usr/swap0):
chmod 0600 /usr/swap0
#Enable the swap file in /etc/rc.conf:
swapfile="/usr/swap0" # Set to name of swapfile if aux swapfile desired.
#Reboot the machine or to enable the swap file immediately, type:
mdconfig -a -t vnode -f /usr/swap0 -u 0 && swapon /dev/md0
# Check swap usage
swapinfo
dd if=/dev/zero of=/usr/swap0 bs=1024k count=64
#Set proper permissions on (/usr/swap0):
chmod 0600 /usr/swap0
#Enable the swap file in /etc/rc.conf:
swapfile="/usr/swap0" # Set to name of swapfile if aux swapfile desired.
#Reboot the machine or to enable the swap file immediately, type:
mdconfig -a -t vnode -f /usr/swap0 -u 0 && swapon /dev/md0
# Check swap usage
swapinfo
Raw partition
On Redhat, raw disk can be set up byraw /dev/raw/raw1 /dev/vg0/lv_raw
Then add the corresponding entry to /etc/sysconfig/rawdevices, and you're done!
/dev/raw/raw1 /dev/vg0/lv_raw
raw has been dropped on the Fedora / CentOS5 kernel. They said raw devices are now being created via udev http://kbase.redhat.com/faq/FAQ_105_9616.shtm followed by udevcontrol reload_rules But I got this error -
Jan 14 21:05:30 homme udevd[555]: add_to_rules: invalid ACTION operation Jan 14 21:05:30 homme udevd[555]: add_to_rules: invalid rule '/etc/udev/rules.d/90-raw.rules:1'
Raw device with loopback mount: see http://www.osdev.org/osfaq2/index.php/Disk%20Images%20Under%20Linux
Hard link vs Soft link
A link provides multiple access point to the same file.A soft link is a pointer to the real file. One can identify a soft link by ls -l and the first column should be displayed as lrwxrwxrwx. When the real file is removed, the soft links will be broken.
A hard link is a file pointing to the same inode number as the original file. To identify hard links, do a ls -i and compare the inode number. Alternatively, one can use find / -inum 1234 to locate all the hard links. One can think of the original file as the first hard link to the real file. Until the last hard link is deleted, all remaining hard links are still pointing to the real file.
Fixing ext3 journals
If this is observed from syslog and your fs is automatically mounted as read-onlyEXT3-fs error (device hda1) in start_transaction: Journal has aborted
Remove the journal, do an fsck, and rebuild the journal.
# tune2fs -O ^has_journal /dev/hda1 # fsck -yC /dev/hda1 # tune2fs -j /dev/hda3
Disk labeling
# show all labels /sbin/blkid # label a disk e2fslabel /dev/hdxn
Determine a partition's filesystem
head -c 1m /dev/sdc2 | file -
Copying existing partition to a new drive
I use tar. If it's the same filesystem, one can use dd or dump/restore. Check tar's man page, it seems the exclude option is slightly different on different distro. On CentOS, you don't need a = sign. On Debian, you do !tar cvfS - / --exclude /tmp --exclude /sys --exclude /dev --exclude /mnt | (cd /mnt/newdrive; tar xfS -) # a variant if the target is remote - tar cfS - / --exclude /tmp --exclude /sys --exclude /dev --exclude /mnt | ssh root@1.2.3.4 (cd / ; tar xvfS -)
Seems cpio is cool too
find / -xdev | cpio -pvmd /mnt
Or use dump | restore
cd /newdrive dump -0uan -f - / | restore -r -f -
Or use dd
dd if=/dev/sda1 of=/dev/sdb1 bs=4k
If it's just one file
gzip -c bigfile.log | ssh me@blah.domain.tld zcat ">" /tmp/bigfile.log
Identify processes on current file
fuser $filename
Ram drive
none /memtmp tmpfs size=3G 0 0
Re-read partition table
hdparm -z or partprobe
Resize reiserfs
umount /dev/mapper/vg0-reiserfs fsck -fC /dev/mapper/vg0-reiserfs resize_reiserfs -s 100G /dev/mapper/vg0-reiserfs lvresize --size 100G /dev/mapper/vg0-reiserfs sync # show free space vgdisplay
Remove raid
mdadm --manage --fail /dev/md0 mdadm --manage --remove /dev/md0 mdadm --manage --stop /dev/md0
There is one comment on this page. [Display comment]