Skip to main content

What is UUID in fstab



What is UUID used in fstab
UUID –Universally Unique Identifier/labels
The UUID is useful for identifying hard drives in a Linux system when other factors used to locate them might change.

To find the UUIDs of all hard drives (block devices) connected to a running Linux system, open a terminal and enter sudo blkid at the command prompt. You should see something like this:
#blkid

/dev/sda1: UUID="2e2be99d-5a55-4da1-8665-219a405a8f97" TYPE="ext4"
/dev/sda5: UUID="c2f99f78-bbc9-410a-bf72-186620a8e051" TYPE="swap"
/dev/sdb1: LABEL="new" UUID="ac3ed2c8-91f1-4d31-a601-28db9a36f53a" TYPE="ext4"
/dev/sdc1: LABEL="porta" UUID="F1A5-B5DE" TYPE="vfat"
Here, we see four storage devices and their UUIDs.
  • /dev/sda1 is the system drive.
  • /dev/sda5 is the Linux swap partition.
  • /dev/sdb1 is a spare hard drive.
  • /dev/sdc1 is an external USB drive formatted as FAT32 (vfat).




#ls -la /dev/disk/by-uuid
 
total 0
drwxr-xr-x. 2 root root 160 Mar 25 00:24 .
drwxr-xr-x. 5 root root 100 Mar 25 00:24 ..
lrwxrwxrwx. 1 root root  10 Mar 25 00:24 0982ce66-537a-497b-baaf-99136594f3e8 -> ../../sdb1
lrwxrwxrwx. 1 root root   9 Mar 25 00:24 2014-12-02-19-30-23-00 -> ../../sr0
lrwxrwxrwx. 1 root root  10 Mar 25 00:24 5afc1b25-e6cd-45b2-ad20-69f0fed323b9 -> ../../dm-1
lrwxrwxrwx. 1 root root  10 Mar 25 00:24 8f0652a8-d79b-453f-aa2d-0ff0b5d0ae7b -> ../../dm-0
lrwxrwxrwx. 1 root root  10 Mar 25 00:24 94e15e98-1cff-49a9-b76a-a8f3a948e2ea -> ../../dm-2
lrwxrwxrwx. 1 root root  10 Mar 25 00:24 ae55a647-3c57-4ab5-9651-1389703fe6fe -> ../../sda1
The UUID is required to permanently mount specific disk drives in /etc/fstab.



dump2fs command.But the output of the command will be too long, so use pipe less to see UUID entry of the partition.

dumpe2fs /dev/sda1 | grep UUID



#tune2fs


How do I change the UUID?

This isn’t hard at all.

First find the device path

You can find the device path using the following command:
1
sudo blkid
Your output will look something like this:
1
2
3
4
5
6
sudo blkid
/dev/sdb1: UUID="aabe7e48-2d11-421f-8609-7ea9d75e7f9b" TYPE="swap"
/dev/sdc1: UUID="9467f4de-4231-401f-bcaa-fee718d49e85" TYPE="ext4"
/dev/sdc3: UUID="93a54a4a-e0f5-4152-ae59-2245e8d16ee4" TYPE="ext4"
/dev/sde5: UUID="9467f4de-4231-401f-bcaa-fee718d49e85" TYPE="ext4"
/dev/sde6: LABEL="var" UUID="30433f28-1b79-4b4d-9985-fef5b1c886b5" TYPE="ext4"
Here you can see that /dev/sdc1 and /dev/sde5 have the same UUID. The path of the partition I want to change is /dev/sde5

Secondly, generate a UUID

This is simple, the following command will output a UUID like below:
1
2
uuidgen
f0acce91-a416-474c-8a8c-43f3ed3768f9

Finally apply the new UUID to the partition

This is also another command, tune2fs, which will apply our new UUID to our device path:
1
sudo tune2fs /dev/sde5 -U f0acce91-a416-474c-8a8c-43f3ed3768f9


Linux tune2fs command examples

The tune2fs utility displays and modifies filesystem parameters on ext2,ext3,and ext4 filesystems. This utility can also setup journaling on an ext2 filesystem, turning it into ext3 filesystem.
Below is the examples show you how to use tune2fs to display, modify, and change an ext2 filesystem to ext3
Assume the filesystem has been created on /dev/md1, detail in Ext2, Ext3, and Ext4 filesystems creation on linux

Display a filesystem parameters

#tune2fs -l /dev/md1

tune2fs 1.41.12 (17-May-2010)

Filesystem volume name:   <none>

Last mounted on:          <not available>

Filesystem UUID:          957e1766-4723-420e-b942-a5dafe67c661

Filesystem magic number:  0xEF53

Filesystem revision #:    1 (dynamic)

Filesystem features:      has_journal ext_attr resize_inode dir_index filetype sparse_super large_file

Filesystem flags:         signed_directory_hash 

Default mount options:    (none)

Filesystem state:         clean

Errors behavior:          Continue

Filesystem OS type:       Linux

Inode count:              30539776

Block count:              61048976

Reserved block count:     3052448

Free blocks:              19734533

Free inodes:              30508949

First block:              0

Block size:               4096

Fragment size:            4096

Reserved GDT blocks:      1009

Blocks per group:         32768

Fragments per group:      32768

Inodes per group:         16384

Inode blocks per group:   512

Filesystem created:       Tue Sep 27 11:09:10 2011

Last mount time:          Fri Aug 21 23:28:40 2015

Last write time:          Fri Aug 21 23:33:36 2015

Mount count:              1

Maximum mount count:      32

Last checked:             Thu Aug 20 23:19:10 2015

Check interval:           15552000 (6 months)

Next check after:         Tue Feb 16 22:19:10 2016

Reserved blocks uid:      0 (user root)

Reserved blocks gid:      0 (group root)

First inode:              11

Inode size:              128

Journal inode:            8

Default directory hash:   tea

Directory Hash Seed:      0aa9310b-d299-4d55-a83b-e4eca6c0a6f2

Journal backup:           inode blocks

Modify filesystem parameters

Almost all of the parameters in previous example output can be set by tune2fs, here I jus show few of popular ones as examples, once you know how this utility works, it's easy for other options.

Set  volume label for a filesystem

The option -L volume-label is to set the volume label of the filesystem
/dev/md1 has no volume label in previous output, now set it to data
#tune2fs -L data /dev/md1

tune2fs 1.41.12 (17-May-2010)

#tune2fs -l /dev/md1 | grep volume

Filesystem volume name:   data

Change an ext2 filesystem to an ext3 filesystem

To change an ext2 filesystem to an ext3 filesystem, you must put a journal on the filesystem, and the kernel must support ext3 filesystems.
Use the option -j to set up a journal on an unmounted filesystem:
#tune2fs -j /dev/md2
Also change the entry in the fstab to reflect its new type.

To change an ext3 filesystem to an ext2 filesystem

#tune2fs -O ^has_journal /dev/md2


Comments

Popular posts from this blog

sed

Sed Command in Linux/Unix with examples SED command in UNIX is stands for stream editor and it can perform lot’s of function on file like, searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace. By using SED you can edit files even without opening it, which is much quicker way to find and replace something in file, than first opening that file in VI Editor and then changing it. o     SED is a powerful text stream editor. Can do insertion, deletion, search and replace(substitution). o     SED command in unix supports regular expression which allows it perform complex pattern matching. Syntax: sed OPTIONS... [SCRIPT] [INPUTFILE...] Example: Consider the below text file as an input. $cat > geekfile.txt unix is great os. unix is opensource. unix is free os. learn operating system. unixlinux which one you choose. unix is easy to learn.unix ...

initramfs" file is deleted or corrupted on your RHEL or CentOS 7

Initrd/Initramfs image provides the capability to load a RAM disk by the boot loader. This RAM disk can then be mounted as the root filesystem and programs can be run from it. Afterwards, a new root file system can be mounted from a different device. The previous root filesystem which was mounted from initrd/initramfs is then moved to a directory and can be subsequently unmounted. Their are chances that either you might have accidentally deleted "initramfs" file from the /boot partition or it is corrupted due to some reason.  Then boot process will get interrupted and you will see below error: error: file '/initramfs-3.10.0-957.el7.x86_64.img' not found. Good news is you can still recover this "initramfs" by following below steps: Step 1 :  Mount RHEL or CentOS 7 ISO image on your physical server and boot from it. In case you are using HPE Prolient server you can mount this ISO image on iLO, if this is virtual environment then mount it accordingly and reboot...

nw commands

troubleshoot commands in Linux.   1. ifconfig ifconfig (interface configurator) command   is use to initialize an interface, assign IP  Address to interface and enable or disable  interface on demand. With this command  you can view IP Address and Hardware / MAC   address assign to interface and also MTU (Maximum transmission unit) size. # ifconfig   eth0       Link encap:EthernetHWaddr 00:0C:29:28:FD:4C inet addr:192.168.50.2   Bcast:192.168.50.255   Mask:255.255.255.0           inet6 addr: fe80::20c:29ff:fe28:fd4c/64 Scope:Link           UP BROADCAST RUNNING MULTICAST   MTU:1500   Metric:1           RX packets:6093 errors:0 dropped:0 overruns:0 frame:0  ...
# # #