- Persistent block device naming
- Contents
- Persistent naming methods
- by-label
- by-uuid
- by-id and by-path
- by-partlabel
- by-partuuid
- Static device names with udev
- Using persistent naming
- fstab
- Kernel parameters
- How to Change your Ubuntu Computer Name (Hostname)
- What is a computer name (hostname)?
- How to change the hostname?
- Method 1: Through the GUI
- Method 2: Manually through the hostname and hosts file
- Method 3: Through the hostnamectl command
- Conclusion
- Karim Buzdar
Persistent block device naming
This article describes how to use persistent names for your block devices. This has been made possible by the introduction of udev and has some advantages over bus-based naming. If your machine has more than one SATA, SCSI or IDE disk controller, the order in which their corresponding device nodes are added is arbitrary. This may result in device names like /dev/sda and /dev/sdb switching around on each boot, culminating in an unbootable system, kernel panic, or a block device disappearing. Persistent naming solves these issues.
Contents
Persistent naming methods
There are four different schemes for persistent naming: by-label, by-uuid, by-id and by-path. For those using disks with GUID Partition Table (GPT), two additional schemes can be used by-partlabel and by-partuuid. You can also use static device names by using Udev.
The directories in /dev/disk/ are created and destroyed dynamically, depending on whether there are devices in them.
The following sections describe what the different persistent naming methods are and how they are used.
The lsblk command can be used for viewing graphically the first persistent schemes:
For those using GPT, use the blkid command instead. The latter is more convenient for scripts, but more difficult to read.
by-label
Almost every file system type can have a label. All your volumes that have one are listed in the /dev/disk/by-label directory.
Most file systems support setting the label upon file system creation, see the man page of the relevant mkfs.* utility. For some file systems it is also possible to change the labels. Following are some methods for changing labels on common file systems:
swap swaplabel -L «new label» /dev/XXX using util-linux ext2/3/4 e2label /dev/XXX «new label» using e2fsprogs btrfs btrfs filesystem label /dev/XXX «new label» using btrfs-progs reiserfs reiserfstune -l «new label» /dev/XXX using reiserfsprogs jfs jfs_tune -L «new label» /dev/XXX using jfsutils xfs xfs_admin -L «new label» /dev/XXX using xfsprogs fat/vfat fatlabel /dev/XXX «new label» using dosfstools mlabel -i /dev/XXX ::»new label» using mtools exfat tune.exfat -L «new label» /dev/XXX using exfatprogs exfatlabel /dev/XXX «new label» using exfatprogs or exfat-utils ntfs ntfslabel /dev/XXX «new label» using ntfs-3g udf udflabel /dev/XXX «new label» using udftools crypto_LUKS (LUKS2 only) cryptsetup config —label=»new label» /dev/XXX using cryptsetup
The label of a device can be obtained with lsblk:
by-uuid
UUID is a mechanism to give each filesystem a unique identifier. These identifiers are generated by filesystem utilities (e.g. mkfs.* ) when the device gets formatted and are designed so that collisions are unlikely. All GNU/Linux filesystems (including swap and LUKS headers of raw encrypted devices) support UUID. FAT, exFAT and NTFS filesystems do not support UUID, but are still listed in /dev/disk/by-uuid/ with a shorter UID (unique identifier):
The UUID of a device can be obtained with lsblk:
The advantage of using the UUID method is that it is much less likely that name collisions occur than with labels. Further, it is generated automatically on creation of the filesystem. It will, for example, stay unique even if the device is plugged into another system (which may perhaps have a device with the same label).
The disadvantage is that UUIDs make long code lines hard to read and break formatting in many configuration files (e.g. fstab or crypttab). Also every time a volume is reformatted a new UUID is generated and configuration files have to get manually adjusted.
by-id and by-path
by-id creates a unique name depending on the hardware serial number, by-path depending on the shortest physical path (according to sysfs). Both contain strings to indicate which subsystem they belong to (i.e. pci- for by-path , and ata- for by-id ), so they are linked to the hardware controlling the device. This implies different levels of persistence: the by-path will already change when the device is plugged into a different port of the controller, the by-id will change when the device is plugged into a port of a hardware controller subject to another subsystem. [1] Thus, both are not suitable to achieve persistent naming tolerant to hardware changes.
However, both provide important information to find a particular device in a large hardware infrastructure. For example, if you do not manually assign persistent labels ( by-label or by-partlabel ) and keep a directory with hardware port usage, by-id and by-path can be used to find a particular device.[2] [3]
by-id also creates World Wide Name links of storage devices that support it. Unlike other by-id links, WWNs are fully persistent and will not change depending on the used subsystem.
This article or section needs expansion.
by-partlabel
GPT partition labels can be defined in the header of the partition entry on GPT disks.
This method is very similar to the filesystem labels, except the partition labels do not get affected if the file system on the partition is changed.
All partitions that have partition labels are listed in the /dev/disk/by-partlabel directory.
The partition label of a device can be obtained with lsblk:
by-partuuid
Like GPT partition labels, GPT partition UUIDs are defined in the partition entry on GPT disks.
MBR does not support partition UUIDs, but Linux[5] and software using libblkid[6] (e.g. udev[7]) are capable of generating pseudo PARTUUIDs for MBR partitions. The format is SSSSSSSS—PP , where SSSSSSSS is a zero-filled 32-bit MBR disk signature, and PP is a zero-filled partition number in hexadecimal form. Unlike a regular PARTUUID of a GPT partition, MBR’s pseudo PARTUUID can change if the partition number changes.
The dynamic directory is similar to other methods and, like filesystem UUIDs, using UUIDs is preferred over labels.
The partition UUID of a device can be obtained with lsblk:
Static device names with udev
Using persistent naming
There are various applications that can be configured using persistent naming. Following are some examples of how to configure them.
fstab
Kernel parameters
To use persistent names in kernel parameters, the following prerequisites must be met. On a standard installation following the installation guide both prerequisites are met:
- You are using an initramfs image that has udev in it.
- For mkinitcpio, enable either the udev or systemd hook in /etc/mkinitcpio.conf
The location of the root filesystem is given by the parameter root on the kernel command line. The kernel command line is configured from the boot loader, see Kernel parameters#Configuration. To change to persistent device naming, only change the parameters which specify block devices, e.g. root and resume , while leaving other parameters as is. Various naming schemes are supported:
Persistent device naming using label and the LABEL= format, in this example Arch Linux is the LABEL of the root file system.
Persistent device naming using UUID and the UUID= format, in this example 0a3407de-014b-458b-b5c1-848e92a327a3 is the UUID of the root file system.
Persistent device naming using disk id and the /dev path format, in this example wwn-0x60015ee0000b237f-part2 is the id of the root partition.
Persistent device naming using GPT partition UUID and the PARTUUID= format, in this example 98a81274-10f7-40db-872a-03df048df366 is the PARTUUID of the root partition.
Persistent device naming using GPT partition label and the PARTLABEL= format, in this example GNU/Linux is the PARTLABEL of the root partition.
Источник
How to Change your Ubuntu Computer Name (Hostname)
What is a computer name (hostname)?
Your computer name, in technical terms, is also referred to as the hostname of your computer system. A hostname is how other computers recognize your computer over a local network. Like on the Internet, we have URLs instead of hostnames. These URLs contain regular words like google.com that we can easily understand instead of remembering the numeric IP address of a server.
We can give easy computer name/hostname for our systems so that other computers can easily identify it over a local network. So instead of remembering your IP address, other people can access local web pages and other authorized data on your system through your hostname.
In this article, we will give a few simple ways to change your computer name through the graphical user interface and the command line.
The commands and procedures mentioned in this article have been run on a Ubuntu 18.04 LTS system.
How to change the hostname?
Method 1: Through the GUI
Through the UI, you can change your computer’s device name. It can be called a “pretty hostname” as it is not the permanent or static hostname of your computer. Nevertheless, you can change the device name as follows:
Open your system settings either by clicking the downward arrow located at the top-right corner of your Ubuntu screen and then clicking the settings icon from the following view:
Open the Settings utility through the system Dash as follows:
The Settings utility will by default open in the Wi-Fi view as follows:
Move to the Details view by clicking the Details tab from the left pane. You will be able to view the Device name in the About view as follows: Advertisement
The device name will change as soon as you enter a new name in the Device name textbox.
Please note that this is not your computer’s permanent hostname. Please read further in this article to view how you can change your computer’s permanent hostname.
Method 2: Manually through the hostname and hosts file
You can view the hostname of your computer by entering the following command in your Terminal:
(Click the Ctrl+Alt+T shortcut to open the Terminal application)
One way to change the hostname is through the following command:
$ sudo hostname new-hostname
The drawbackof this method is that the hostname will revert to the original when you restart your system.
The proper way to change the hostname is by changing it in two configuration files named the hostname and hosts file located in the /etc/ folder.
You can open these files through any of your favorite text editors. We are opening this file in the nano editor as follows:
The only text in this file lists the hostname of your computer. Simply change the text to a new hostname and then exit and save the file by clicking Ctrl+X, and then y and hit enter.
Then open the hosts file as follows:
In this file, the hostname is listed against the IP: 127.0.1.1
Change this hostname to a new hostname and then exit and save the file by clicking Ctrl+X, and then y and hit enter.
Now when you restart the system, your hostname will change to a static new hostname.
Method 3: Through the hostnamectl command
The smartest way to change your hostname is through the hostnamectl command that is a part of the Systemd utility. If Systemd is not already installed on your system, you can install it through the following command as root:
You can check the version number of the Systemd utility by running the following command:
This command will give you the version number of the utility and also ensure that it is indeed installed on your system
Now that the Systemd utility is installed on your system, you can run the following command in order to view detailed information about your system, including the hostname:
In this output, the Static hostname lists the permanent hostname of your machine. The Pretty hostname lists the Device name you have set up through the UI in the Settings utility. The hostnamectl lists the Pretty hostname(device name) only if it is different from the static hostname.
In order to change your computer’s hostname through the hostnamectl command, use the following syntax:
$ hostnamectl set-hostname “new-hostname”
Now when you see, the hostname through the hostnamectl command, it will show the static hostname as the new hostname you have set. The system has also changed the device name to the hostname you specified through the set-hostname command.
You can verify through the UI that your device name will also be the same as your static hostname. Open the Settings utility and move to the Details tab to view your device name.
The plus point of the Hostnamectl command is that you do not need to restart your computer in order to permanently change the hostname.
Conclusion
Through this tutorial, you learned to change the device name and computer name(hostname) of your system. Now you can change your computer’s hostname either temporarily or permanently through the Ubuntu command line. All you need to do is change a few configuration files or simply use the hostnamectl command to do so. Now you can have a customized computer name through which other computers over the local area will identify you.
Karim Buzdar
About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn
Источник