Linux set partition uuid

Как изменить UUID раздела и его метку

А зачем?

Если вы много экспериментируете со своей системой Linux, постоянно пробуете всякие новые программы, частый гость в репозиториях testing и Sid, пробуете удалить GRUB2 и поставить Grub Legacy и т.д. и т.п., то у вас, без сомнения, есть запасной клон вашей системы, спрятанный где-нибудь в надежном месте. О изготовлении таких клонов я писал в конце 2010 года.

Но, если вы «убили» систему, а клон еще не занял ее место, вы, лишенные привычного рабочего окружения, некоторое время испытываете определенные неудобства. Поэтому предлагаю для экспериментов иметь клон вашей системы в соседнем разделе того же диска.

Все эксперименты сначала проводятся на клоне ≈ подопытном кролике, и в случае удачи переносятся в основной вариант системы.

Как делается клон

Затем клонируем систему в новый раздел:

(bs=10M ≈ это величина блока (в данном случае ≈ 10 мегабайт), которыми будет происходить копирование на уровне секторов диска. Чем больше блок, тем быстрее копируется, но и меру нужно знать).

Полученный клон является побайтовой копией оригинала, поэтому он имеет ту же файловую систему со всеми своими суперблоками на тех же местах. Дублируется также и нулевой сектор, недоступный при обычном копировании. Кроме того, при копировании командой cp данные записываются на свободное место, а при клонировании ≈ на то же самое, что и в оригинале. Это приводит к тому, что оригинал и клон имеют абсолютно идентичные файловые системы, одинаковые UUID’ы и метки тома.

Так как мы собираемся пользоваться обеими копиями одновременно, то наличие у них одинаковых UUID’ов и меток (LABEL), неудобно в работе, так как приводит к путанице. Почему и нужно изменить UUID клона и дать ему новую метку.

Изменение UUID раздела

Чтобы узнать UUID’ы всех разделов вашей системы нужно применить команду:

Такой синтаксис команды предпочтителен. Подробное объяснение в статье «Как узнать UUID’ы разделов?», там же описаны другие команды для этой цели.

Хотя теоретически можно самостоятельно придумать новый UUID, рекомендуется пользоваться командой uuid ≈ генератором UUID’ов. Если у вас нет этой команды, то нужно установить пакет uuid (или соответствующий ему в вашей системе) привычным вам способом. Команда без лишних слов генерирует новый UUID при каждом запуске.

Поскольку UUID есть атрибут файловой системы, то для его изменения применяется команда tune2fs, служащая для настройки файловых систем ext2, ext3, ext4.

Проверим, что получилось:

Отлично! Теперь займемся меткой тома.

Как изменить метку тома

Узнать, какой раздел кроется за данной меткой тома, можно при помощи команды:

Если вы часто удаляете / создаете разделы, то их имена (/dev/sdxx) могут измениться, зато UUID и LABEL останутся неизменными и никакой путаницы в конфигах не произойдет.

Итак, два раздела с одинаковой меткой тома ≈ это нонсенс! Давайте менять метку. Для этого применяется команда e2label. Она не входит в стандартный набор команд, поэтому скорее устанавливайте одноименный пакет. Пользоваться ей просто ≈ пишем имя раздела и за ним новый LABEL:

Теперь наш основной рабочий раздел (/dev/sda7 «squeeze») и его клон (/dev/sda8 «clone») имеют свои уникальные UUID’ы и понятные метки тома.

Источник

How to Change Partition UUID in Linux

The UUID of a Linux partition is the Universally Unique IDentifier of that partition. I would say with a fair bit of confidence that in this and most scenarios, the Linux partition UUID has more of a local machine scope. This ID is used in a few places to identify the partition. The most notable being your /etc/fstab file, which manages the mounting of partitions at boot time.

Читайте также:  Популярность серверных linux дистрибутивов

UUID should be unique and it is used to identify storage devices on a Linux system.

In this article I will show how to change UUID of Linux partition.

Change UUID of Linux Partition

Follow the below steps to change the UUID of Linux Partition.

1. Run the below command to find out UUID of the devices.

2. Alternatively you can also use the below command to find out the UUID of devices.

3. Check the mounted partitions.

There is mounted /data in the system with UUID=”b100ad2b-ad89-4e2d-ba8e-7eda7d703c40″.

4. Change UUID for /dev/mapper/vg_data-centos7_vol which is in /data mounted partition.

  • 1.Create the new UUID using below command.
  • 2. Please take note that the UUID may only be changed when the filesystem is unmounted.
  • 3. Now change UUID for LVM /dev/mapper/vg_data-centos7_vol with new generated UUID.
  • 4. Mount back the /data partition.
  • 5. Update /etc/fstab.
  • 6. Verify new UUID for /dev/mapper/vg_data-centos7_vol.

Источник

How to Change Linux Partition Label Names on EXT4 / EXT3 / EXT2 and Swap

A Partition is a space carved out from a physical disk which can be used to either install an Operating System or just act as a storage space for Users files and other data. Each partition is created directly on Hard Disk or External Disk attached to the system with starting and ending block address identifying the amount of space it takes on the drive.

Change Linux Partition Disk Label Names

Although you can create n number of partitions you desire but a Linux system identifies maximum of 16 partitions which can be associated to any of SCSI, SATA, PATA or virtual hard disk. For identifying above partitions, A Linux system has its own general convention. That convention is in the form ‘ /dev/sdxn ‘ or ‘ /dev/vdxn ‘ where ‘ x ‘ is alphabet and ‘ n ‘ a number.

Here, ‘/dev’ is the directory in ‘/’ file system which holds files associated to each of the devices attached to a Linux system. After that ‘s’ identifies a SATA, SCSI or PATA drive and ‘v’ is for virtual disks on KVM based Machines. The next alphabet i.e. ‘d’ is acronym for device and finally the next alphabet identifies the drive attached.

If your system has 4 hard disks, you may find listing for: /dev/sda , /dev/sdb , /dev/sdc , /dev/sdd in the output of fdisk command when ‘l’ option is invoked.

After the alphabet comes the number. A typical hard disk identifies 4 primary partitions of which there can be an extended partition too, which again holds multiple logical partitions. In that case, the first primary partition, which generally is the boot partition, holds the default label: ‘/dev/sda1’ which signifies its position as first primary partition on first hard disk, likewise ‘/dev/sdb1’ will be first primary partition on second hard disk.

The next primary partition will have sda2, then sda3 and so on, with logical partition starting from sda5. This is a just of how a Linux Partitioning is laid down, although currently one more type of partition exists, which is Linux LVM partition on which Logical Volume is created out of Physical Volume and Volume Groups on the fly without directly affecting the underlying hardware.

Linux Filesystem and Partitions – Types and Terminologies

A bare Linux system configures 2 partitions during normal installation i.e. root ( ‘/’ ) (Where the filesystem is laid down) and swap (a temporary storage space which is assumed to be twice of RAM by default which is although not necessary).

Bootloader is generally installed in root partition or the first primary partition. Partition lays down the base for filesystems which are then created on the partition, but before that it requires the partition to be formatted for the type of filesystem to be supported on that partition.

Читайте также:  Горячие клавиши windows два окна
Some of the filesystems supported by Linux Systems include:
  1. ext2
  2. ext3
  3. ext4
  4. ReiserFS
  5. xfs
  6. FAT
  7. HPFS/NTFS/exFAT

Some Terminologies Relating to Linux Partitioning:

Primary Partition:

Directly holds area on hard disk specified in terms of first and last sector address and holding a label indicating the hard disk where it is and its number. It can hold the boot files for OS or the data as configured by user.

Extended Partition:

Partition which holds other partitions. Extended partition is created to hold multiple logical partitions. Unlike primary partition, it can’t hold the boot files of installed OS, as it holds and manages the logical partitions.

Logical Partition:

After first 4 primary partitions, come the logical partitions which are laid down on extended partition. These are generally used to hold the filesystem as laid down by user. Swap space is also configured as a logical partition.

Linux LVM Partition:

LVM partition is used for laying down filesystems created on Logical Volumes. LVM is acronym for Logical Volume Management, a feature of Linux to create on the fly Logical Volumes on partitions. It takes a partition, which then holds a Physical Volume and multiple Physical volumes are combined to create a volume group on which Logical Volume is laid down. Logical Volume is then formatted to hold the filesystem.

Volume:

A formatted segment of space, which can hold filesystem. Volume is created on the partition for mounting filesystem on it and allowing it to hold user data.

Since all the operations on partitions require modification of size of filesystem hosted by it, any modification, deletion or creation of partition require filesystems to be carefully unmounted and backed up to avoid risking loss of data.

Some Linux Utilities/Commands that come in handy for filesystem related operations include:
  1. fdisk – for creating, modifying, deleting partition, including creating and printing partition table and so on.
  2. parted – performs same operations as fdisk and even many more also considered.
  3. df – displays all the filesystems mounted on Linux Filesystem and their mount points.
  4. mount – for mounting filesystems, directories, changing mount point for a directory/device and all sorts of such operations.
  5. mkfs – creating and formatting a filesystem. Usually command is used in concatenation with the type of formatting desired. Like: mkfs.ext4 for formatting filesystem with type ext4.
  6. umount – for unmounting filesystem from a partition.
  7. GParted/QParted – GUI Parted for Gnome and KDE systems.
  8. Disks – Software Utility pre-installed on Linux systems for managing partitions through GUI.

Linux Utilities/Commands for Changing or Modifying Partition Names/Labels

Commands for changing or modifying Partition Name/ Label are dependent on type of filesystem on that partition with exception of some general commands.

Below you can find listing of all such commands.

1. e2label or tune2fs

The commands e2label or tune2fs used for changing label of ext2, ext3 and ext4 type partitions.

Here, ROOT and ROOT_PART are the labels to be added to /dev/sda1 which is ext4 formatted partition.

2. ntfslabel

The ntfslabel command used for changing label of NTFS partitions.

3. reiserfstune

The reiserfstune command used for labeling reiserFS formatted partitions.

Note: It is advisable to first unmount the filesystem before this command.

Where, /dev/sdb1 is the partition formatted with reiserFS filesystem.

4. mkswap

The mkswap command used for changing label of SWAP partition.

After unmounting the filesystem, following command needs to be executed to change the label of swap partition.

Where, /dev/sda5 is the SWAP formatted partition.

5. exfatlabel

The exfatlabel command used for changing the label of exFAT formatted partition.

6. Changing Label of a partition in GUI – DISKS

Disks is a pre-installed utility found in most Linux systems which presents GUI for doing all the partitions related tasks which are done by fdisk and parted and even more than that. Disks can be used to change label of a partition by following procedure:

Читайте также:  Oem windows 10 минусы

Show Linux Partition Table

GUI of Disks shows, all the external drives and details of selected external drive including partitions, their labels, their size and type of formatting. First step is to select the partition whose label is to be changed, which is Partition 1 here, next step is to select gear icon and edit filesystem.

Change Linux Partition Label

After this you will be prompted to change the label of selected partition.

Set Linux Partition Label Name

And finally, the label of the partition will be changed.

Linux Partition Name Modified

Special Linux Utilities to Mount Partition with Label Names

1. Using Label for loading partition at boot time – /etc/fstab file

/etc/fstab is the file which is consulted at the boot time to mount the partitions that exist on the system. Partitions are by default identified by using UUID as per the entry in this /etc/fstab file.

But, there is another way to load the partition, instead of that long UUID, you can just pass the label of that partition in the file instead of UUID and from then on, your system would mount the partitions on the system using LABEL instead of UUID.

For loading any partition using Label rather than UUID just open the /etc/fstab file for editing:

File looks like below:

Linux Fstab Mounted Partitions

Here, partition is recognized using UUID as seen above. Now if you want the partition to be recognized using label just edit the corresponding entry in the file replacing UUID= by LABEL= . Then, save and close the file. On next boot, the partition will be loaded using label instead of UUID.

2. Changing entries of partitions in partition table:

Some commands can be used to play with entries of partitions in partition table and shuffle the entries in the partition table.

These commands include:

1. gdisk

Utility which can be used to perform many useful operations on partitions, but highlighted here is one of its operation to change the partition names.

Procedure to follow:

This opens the gdisk and you will be prompted to enter the disk to be selected. Just enter the disk you want to select. ‘/dev/sda’ for operating on first hard disk.

Next, you will get following prompt would appear asking you to enter any command. Enter ‘c’ here. You will be prompted to select the partition number whose name you want to edit. Enter the partition name and then you will be prompted to enter the new name. Enter the new name and hit ENTER.

Next, use the following option to verify that the change you did, is done.

Now Close and exit gdisk, saving your changes.

2. mount

Mount can also be used to change the name of partition. Following procedure can be used here:

Unmount the partition.

Change the name of directory after it is un-mounted.

Edit /etc/fstab and change the mount point of partition from /partition to /new_name_partition and then remount the partition.

Conclusion

Above are the techniques presented for Changing/Modifying the Name/Label of Linux Partitions. If you have other interesting techniques which can achieve the same thing do share with us in your precious comments.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Оцените статью