path: root/meta/classes/fs-uuid.bbclass
diff options
authorPatrick Ohly <>2015-09-03 18:42:32 (GMT)
committerRichard Purdie <>2015-09-06 14:26:25 (GMT)
commit6d7bcd4df5722f3ccebbbf73361838cb0a5dc0ee (patch)
tree71567c46291b06559731d451466d7d6cfb59a279 /meta/classes/fs-uuid.bbclass
parent5d79814b0b9d4d0348dc36c0d9e003e4ba0bd367 (diff)
boot loader: support root=UUID
As mentioned when introducing the VM images (, the resulting images only work when the image is mounted as a disk that results in the hard-coded path (/dev/sda in the current default). Using the file system UUID to find the rootfs is more flexible. To enable this for boot-direct.bbclass and thus image-vm.bbclass (aka FSTYPEs vdi/vmdk/qcow2), set SYSLINUX_ROOT = "root=UUID=<<uuid-of-rootfs>>". The rootfs image must use an ext file system. The special string will get replaced in the APPEND line with the actual UUID when the boot loader (grub-efi, syslinux or gummiboot) writes the boot loader configuration files. At that time, the rootfs image has already been created and its UUID can be extracted using "tune2fs -l", which also should be available because the e2fsprogs-native tools were needed to create the image in the first place. (From OE-Core rev: 1e29d77d0d33ee216b43022439876863f0db39bb) Signed-off-by: Patrick Ohly <> Signed-off-by: Richard Purdie <>
Diffstat (limited to 'meta/classes/fs-uuid.bbclass')
1 files changed, 24 insertions, 0 deletions
diff --git a/meta/classes/fs-uuid.bbclass b/meta/classes/fs-uuid.bbclass
new file mode 100644
index 0000000..bd2613c
--- /dev/null
+++ b/meta/classes/fs-uuid.bbclass
@@ -0,0 +1,24 @@
1# Extract UUID from ${ROOTFS}, which must have been built
2# by the time that this function gets called. Only works
3# on ext file systems and depends on tune2fs.
4def get_rootfs_uuid(d):
5 import subprocess
6 rootfs = d.getVar('ROOTFS', True)
7 output = subprocess.check_output(['tune2fs', '-l', rootfs])
8 for line in output.split('\n'):
9 if line.startswith('Filesystem UUID:'):
10 uuid = line.split()[-1]
11 bb.note('UUID of %s: %s' % (rootfs, uuid))
12 return uuid
13 bb.fatal('Could not determine filesystem UUID of %s' % rootfs)
15# Replace the special <<uuid-of-rootfs>> inside a string (like the
16# root= APPEND string in a syslinux.cfg or gummiboot entry) with the
17# actual UUID of the rootfs. Does nothing if the special string
18# is not used.
19def replace_rootfs_uuid(d, string):
20 UUID_PLACEHOLDER = '<<uuid-of-rootfs>>'
21 if UUID_PLACEHOLDER in string:
22 uuid = get_rootfs_uuid(d)
23 string = string.replace(UUID_PLACEHOLDER, uuid)
24 return string