Refracta Development, Scripts, etc.
Post a reply
dzz

- dzz
- Posts: 647
- Joined: Wed Apr 27, 2011 11:53 am
- Location: Devon, England

## Fstab and UUID in refracta installer

Wed May 23, 2012 1:32 am

I'm in the process of building a new tower, it's mostly up and running
There is a new 1.5TB Sata hard disk. For now, the 3 old ide disks are in there too. I had to use a pci controller for them as the new mainboard has only one ide port.
Thanks to refracta and snapshot, migrating old systems with critical data to the new disk is easy. There are already new installs including refracta
The sata disk is the new boot drive and set in bios as primary drive. However, the OS sees it most times as /dev/sda but sometimes as /dev/sdd. I gave up with udev rules, doesn't seem possible to change that. Grub seems to always get it right.
This makes a potential problem for refracta installer on some systems, which uses at the moment in fstab /dev/sdxy for "/" rather than UUID or label (I already changed it and all is well)
fsmithred

- fsmithred
- Posts: 2101
- Joined: Wed Mar 09, 2011 9:13 pm

## Re: Fstab and UUID in refracta installer

Wed May 23, 2012 2:34 am

Did you have an installer that used uuid? I think I remember seeing that in one of your scripts. Any idea what script debian used to convert fstab to uuid? I think that happened in the upgrade from lenny to squeeze.
dzz

- dzz
- Posts: 647
- Joined: Wed Apr 27, 2011 11:53 am
- Location: Devon, England

## Re: Fstab and UUID in refracta installer

Wed May 23, 2012 10:22 am

Yes, I think UUID in fstab became default after Lenny. The complaint was, it's not very "humanly readable" but does avoid that sort of problem.
The way round that is insert comments in fstab or use "LABEL=whatever"
I don't know how the Debian installer gets it or does the upgrade. For the Exe installer I get it by using (after partitioning)

Code:
  `INSTALLPARTITIONUUID=$(blkid -c /dev/null -o value -s UUID $INSTALLPARTITION)`

where $INSTALLPARTITION is e.g. /dev/sda9. ("-c /dev/null" means it won't read a possibly outdated cache)
Example fstab snip:

Code:
  `# (rootfs)
  UUID=8bc751d9-ffca-4dcd-8fd3-8c99413ac408 / ext3 relatime,errors=remount-ro 0 1`

The "configure-mounts" script I did rebuilt the fstab with UUID but I haven’t been there for a while, it needs updating (not for installers anyway)
fsmithred

- fsmithred
- Posts: 2101
- Joined: Wed Mar 09, 2011 9:13 pm

## Re: Fstab and UUID in refracta installer

Sun May 27, 2012 2:54 pm

I've been looking at how to fit either disk labels or uuids into the (cli) installer script, and I think I've got it down to just adding a few lines. If the partition is encrypted, fstab doesn't need to use the uuid, but crypttab does.
Double-commented stuff is proposed code (untested so far)

Code:
  `# setup fstab
  # Option to use uuid in fstab for the installation partition, unless it's encrypted
  #
  ## if [[ $use_uuid = yes ]]; then
  ## if [[ $encrypt_os = no ]]; then
  ## install_part="UUID=$(blkid $install_dev | awk -F"\"" '{ print $2 }')"
  ## fi
  echo -e "\n Creating /etc/fstab...\n"
  echo -e "proc\t\t/proc\tproc\tdefaults\t0\t0
  /swapfile\tswap\tswap\tdefaults\t0\t0
  $install_part\t/\t$fs_type_os\tdefaults,noatime\t0\t1" >> /target/etc/fstab
  check_exit`

Code:
  `# Add entry for root filesystem to crypttab if needed
  if [[ $encrypt_os = yes ]] ; then
  ## if [[ $use_uuid = yes ]]; then
  ## install_dev="UUID=$(blkid $install_dev | awk -F"\"" '{ print $2 }')"
  ## fi
  ##
  echo -e "\n Adding $install_part entry to crypttab...\n"
  echo -e "root-fs\t\t$install_dev\t\tnone\t\tluks" >> /target/etc/crypttab
  fi`

Still need to add similar code for separate /home and /boot, and also need to add the question about using uuid. In gui version, it'll be another entry in the options checkbox. I'm assuming that during any one boot, all tools agree on the device names, and it's only between reboots that the disk order changes. If that's not the case, then we might be screwed.
fsmithred

- fsmithred
- Posts: 2101
- Joined: Wed Mar 09, 2011 9:13 pm

## Re: Fstab and UUID in refracta installer

Sun May 27, 2012 3:17 pm

Oops! Looks like I need to come up with another name for one of those install_devs.

Code:
  `install_dev="UUID=$(blkid $install_dev | awk -F"\"" '{ print $2 }')"`

fsmithred

- fsmithred
- Posts: 2101
- Joined: Wed Mar 09, 2011 9:13 pm

## Re: Fstab and UUID in refracta installer

Sun May 27, 2012 4:15 pm

First test works. Install to single partition, no encryption, and fstab uses the uuid for the root partition.
Separate note: I need to reduce the number of questions asked in the cli installer.
fsmithred

- fsmithred
- Posts: 2101
- Joined: Wed Mar 09, 2011 9:13 pm

## Re: Fstab and UUID in refracta installer

Sun May 27, 2012 8:47 pm

Seems to be working. Tried it with separate home and boot, with either /home or / encrypted. If you want to try it, get refractasnapshot-test from the github repo. No .deb files yet and no gui script yet. The fstab entries with uuid show up without a comment line to tell you what device name they started with.
Edit: The test script uses uuid by default. If you want to set it to just use device names, edit the variable on line 197, so it says:
use_uuid="no"
I'll add a question for that later.
Edit 2: If I encrypt only the root directory, I get fstab entries with uuid for /boot and /home as expected. When I encrypt only /home, there's a uuid entry for /, but not for /boot in fstab - it looks like this,

Code:
  `UUID= /boot ext2 defaults,noatime, 0 1`

and it boots ok (without mounting /boot).
Haven't tried it with encrypted / and /home yet.
dzz

- dzz
- Posts: 647
- Joined: Wed Apr 27, 2011 11:53 am
- Location: Devon, England

## Re: Fstab and UUID in refracta installer

Mon May 28, 2012 12:32 am

The problem with using awk on blkid output is, it doesn't organise columns very well, whatever special options one uses.
Column 2 is LABEL, unless there is no label. then column 2 is UUID. Then for ext* you got the 'SEC _TYPE="ext2"' column before the actual 'TYPE' (e.g. ext4)
That then throws all the others in the list out of order, hence any script that relies on it can fail.
A script I made (scrappily and out of desperation) to get a consistent, readable partition list marking what is mounted for my new setup :

Code:
  `#!/bin/bash
  # script name : partlist
  # udev doesn't always assign the same device node to a disk Thanks udev.
  # What was once, e.g. /dev/sda3, might be /dev/sdd3 next boot
  # How do you know for sure which one you want to mount ?
  # Don't you just love how blkid formats it's output and screws up the columns?
  #
  # get the partition list
  # -c /dev/null stops blkid reading a (maybe outdated) cache
  # get rid of some bits we don't want
  /sbin/blkid -c /dev/null|sed 's/SEC_TYPE=\"ext2\"//'g|sed 's/://'g|sed 's/"//'g|sort > /tmp/blkid
  # list what has no label
  while read line; do
  echo -e "$line"|grep -v LABEL=|awk '{print $1}'; done < /tmp/blkid >/tmp/nolabel
  # If no label the columns are out of order so insert a non-blank "LABEL=" entry
  for i in $(cat /tmp/nolabel); do sed -i "s:$i:$i LABEL=\"\" :" /tmp/blkid;done
  # list what is mounted
  /sbin/blkid -c /dev/null -o list|grep /dev|grep -v "(not mounted)"|awk '{print $1}'>/tmp/mounted
  # mark mounts with "**" in the main list
  for i in $(cat /tmp/mounted); do sed -i "s:$i:$i\**:" /tmp/blkid;done
  # append a footnote to explain **
  echo "** ** ** **">> /tmp/blkid
  echo "**=MOUNTED">> /tmp/blkid
  # tidy it up into nice columns
  column -t /tmp/blkid >/tmp/partlist
  # delete the crap
  rm -f /tmp/blkid /tmp/mounted /tmp/nolabel
  # display the result
  xterm -geometry 95x30 -e "less /tmp/partlist"`

Maybe bits of that are of some use. I'm not sure if "-c /dev/null" is a good idea or not, I don't trust the cache.
Anyway, thanks for looking in to this. Personally I'm really pleased with installer as it is, I can edit my own fstab, it depends how far you want to go supporting those who can't. But apparently the reason UUID became Debian default after Lenny was because of how udev handles device nodes, not always consistently.
With 27 partitions on 4 HD's here, I'm now using labels for absolutely everything.
dzz

- dzz
- Posts: 647
- Joined: Wed Apr 27, 2011 11:53 am
- Location: Devon, England

## Re: Fstab and UUID in refracta installer

Mon May 28, 2012 12:04 pm

Another useful blkid option is "-s TAG1 -s TAG2 -s TAG3"
So if you use blkid -s UUID -s TYPE it prints (after the device name) only those tags in 3 columns. You can't set the tag order though.
Could be wrong but I'm almost sure I seen before the columns inconsistent (in the same list, column 2 might show in one line a different tag from others)
I'm still looking at what can be done as normal user, to make a gui (p)mount script, as the xfce mount plugin is not very good.
fsmithred

- fsmithred
- Posts: 2101
- Joined: Wed Mar 09, 2011 9:13 pm

## Re: Fstab and UUID in refracta installer

Mon May 28, 2012 12:08 pm

That's odd; I see the uuid as the second field in the blkid output, even if there's a disk label. The label is last. Either of these works consistently for me, with or without a device name:

Code:
  `blkid | awk '{ print $2 }'
  blkid /dev/sda1 |cut -d" " -f2`

Here's my blkid output. What does yours look like?

Code:
  `/dev/sda3: UUID="95395ac9-84e3-4498-99e5-d7d1460953e1" TYPE="crypto_LUKS"
  /dev/sda2: UUID="8adab59e-164f-41a4-a470-d34e25a652a4" TYPE="ext4"
  /dev/mapper/home-fs: UUID="290334be-fb0c-4d38-83d3-a27402fa6671" TYPE="ext4"
  /dev/sda1: UUID="f73778a0-2378-457b-8be7-74c2c7ef782c" TYPE="ext2" LABEL="bootpart"
  `

I considered using disk labels in the installer, but I was afraid of name collisions. Labels require more attention from the user, and I'd like it to be automatic.
Post a reply
Jump to:

Powered by phpBB © phpBB Group.

phpBB Mobile / SEO by Artodia.