Showing posts with label ext3. Show all posts
Showing posts with label ext3. Show all posts

Tuesday, January 25, 2011

How to create .img file

An IMG file contains a raw dump of the content of a disk. We will use losetup to associate loop device with a file and mount it to work with.
  1. Pre-allocate img file (stuff.img) of the size you need (10M):
    dd if=/dev/zero of=/tmp/stuff.img bs=1M count=10
    
  2. Setup a loop device:
    losetup /dev/loop0 /tmp/stuff.img
    
  3. Create ext3 file system on loop device:
    mkfs.ext3 /dev/loop0
    
  4. Mount it:
    mount /dev/loop0 /mnt
    
Once you are done:
  1. Unmount file system:
    umount /mnt
    
  2. Delete loop device:
    losetup -d /dev/loop0
    

Tuesday, November 23, 2010

How to get Linux partition UUID

Ext3 file system UUID

tune2fs -l /dev/sda11 | grep UUID
Here is an output:
Filesystem UUID: 0827dce3-d1c0-41b1-bc6f-0d4cfa0a1849

XFS file system UUID

xfs_admin -u /dev/sda13
Here is an output:
UUID = f128170a-1ee4-4b4f-abe7-0acf169bb8ae

Monday, April 26, 2010

Mount EXT3 partitions securely

The ext3 file system has several options you can apply to /etc/fstab. The option nosuid ignores the setuid and setgid bits, noexec forbids execution of any program on that mount point, nodev ignores device files. Having this in mind, here you go:
# /home was on /dev/sda9 during installation
UUID=... /home  ext3 defaults,noatime,nodiratime,nodev,nosuid  0 2
# /tmp was on /dev/sda8 during installation
UUID=... /tmp   ext3    defaults,noatime,nodiratime,nodev,nosuid,noexec  0 2
# /usr was on /dev/sda5 during installation
UUID=... /usr   ext3    defaults,noatime,nodiratime,nodev,ro  0 2
# /var was on /dev/sda6 during installation
UUID=... /var   ext3    defaults,noatime,nodiratime,nodev,noexec,nosuid  0 2
/dev/hda  /cdrom udf,iso9660 user,noauto,ro,nodev,nosuid,noexec 0 0
While you have /usr read-only you need remount it read-write while making the system upgrade.
mount -o remount, rw /usr && mount -o remount, exec /var
apt-get upgrade
reboot
Here is a way to remount partions back:
mount -o remount, ro /usr && mount -o remount, noexec /var
Since entering the above command takes some time you soon come up with a script, here they are just in case, file /usr/local/sbin/fs-write:
#!/bin/sh

/bin/mount -o remount,rw /usr || echo 'Failed to remount /usr rw'
/bin/mount -o remount,exec /var || echo 'Failed to remount /var exec'
/bin/mount -o remount,exec /tmp || echo 'Failed to remount /tmp exec'
and /usr/local/sbin/fs-readonly:
#!/bin/sh

/bin/mount -o remount,ro /usr || echo 'Failed to remount /usr ro'
/bin/mount -o remount,noexec /var \
|| echo 'Failed to remount /var noexec'
/bin/mount -o remount,noexec /tmp \
|| echo 'Failed to remount /tmp noexec'
See also this.

Optimize EX3 filesystem performance

Suppose your /etc/fstab looks like this:
/dev/sda1 /     ext3    errors=remount-ro        0 1
/dev/sda9 /home ext3    defaults                 0 2

Turning off atime

If atime is on, every time a file is accessed, whether for read or write, a small change is written to the file detailing the last access time. To disable atime on ext3 partitions:
/dev/sda1 /     ext3  errors=remount-ro,noatime,nodiratime 0 1
/dev/sda9 /home ext3  defaults,noatime,nodiratime 0 2

Disable extended user attributes

Most likely you do not need extended user attributes, so disable them.
/dev/sda9 /home ext3  defaults,noatime,nodiratime,nouser_xattr 0 2

Use journal data writeback

By default journal data ordered option is used. According to this report, you can double read performance. You can simply turn on writeback for any filesystem (but root) by adding data=writeback.
/dev/sda1 /     ext3    errors=remount-ro        0 1
/dev/sda9 /home ext3    defaults,noatime,nodiratime,nouser_xattr,data=writeback 0 2

Journal data writeback for root filesystem

If you try to do this with root (/) filesystem you will get an error message during the boot and the root filesystem remains read-only. Remount it read-write:
mount -n -o remount, rw /
You need setup default filesystem option for root:
deby:~# tune2fs -o journal_data_writeback /dev/sda1
deby:~# tune2fs -l /dev/sda1 | grep 'Default mount option'
Default mount options:    journal_data_writeback
Now you can reboot your system so your changes take effect.

Deactivate barriers

Write barriers enforce proper on-disk ordering of journal commits, making volatile disk write caches safe to use, at some performance penalty. Deactivating barriers make sense if you have battery-backed storage only.
/dev/sda9 /home ext3  defaults,noatime,nodiratime,nouser_xattr,data=writeback,barrier=0 0 2

Avoid buffer heads association

Do not attach buffer_heads to file pagecache. This works together with data writeback option.
/dev/sda9 /home ext3  defaults,noatime,nodiratime,data=writeback,barrier=0,nobh 0 2

Extend commit interval

This options let sync all data and metadata every N seconds. The default value is 5 seconds.
/dev/sda9 /home ext3  defaults,noatime,nodiratime,nouser_xattr,data=writeback,barrier=0,nobh,commit=30 0 2
Have a look at more mount options here. Reboot your computer so all fine tunning take place.