@@ -565,26 +565,80 @@ print_options()
565
565
printf " %-23s:\n" " -----------------------"
566
566
}
567
567
568
- ext_label ()
568
+ dst_part_label ()
569
569
{
570
570
pnum=$1
571
571
fs_type=$2
572
- flag=$3
573
- label_arg=" "
572
+ label=" "
574
573
575
574
if [ " $ext_label " != " " ] && [[ " $fs_type " == * " ext" * ]]
576
575
then
577
576
rep=" ${ext_label: -1} "
578
577
if [ " $rep " == " #" ]
579
578
then
580
- label_arg=${ext_label:: -1}
581
- label_arg=" $flag $label_arg$pnum "
579
+ label=" ${ext_label:: -1} "
582
580
elif (( pnum == root_part_num))
583
581
then
584
- label_arg= " $flag $ext_label "
582
+ label= " $ext_label "
585
583
fi
586
584
fi
587
- printf -v " ${4} " " %s" " $label_arg "
585
+
586
+ if [ -z " $label " -a -n " ${src_label[$pnum]} " ]
587
+ then
588
+ label=" ${src_label[$pnum]} "
589
+ fi
590
+ printf -v " ${3} " " %s" " $label "
591
+ }
592
+
593
+ mkfs_label ()
594
+ {
595
+ pnum=$1
596
+ fs_type=$2
597
+
598
+ label_flag=" "
599
+ case " $fs_type " in
600
+ # This list is probably overcomplete, but might simplify
601
+ # future additions.
602
+ vfat|msdos|exfat|fat16|fat32)
603
+ label_flag=-n
604
+ ;;
605
+ ext2|ext3|ext4|ntfs|xfs)
606
+ label_flag=-L
607
+ ;;
608
+ hfs|hfsplus)
609
+ label_flag=-v
610
+ ;;
611
+ reiserfs)
612
+ label_flag=-l
613
+ ;;
614
+ esac
615
+
616
+
617
+ label_arg=" "
618
+ dst_part_label " $pnum " " $fs_type " label
619
+ if [ -n " $label " -a -n " $label_flag " ]
620
+ then
621
+ label_arg=" $label_flag $label "
622
+ fi
623
+ printf -v " ${3} " " %s" " $label_arg "
624
+ }
625
+
626
+ change_label ()
627
+ {
628
+ pnum=$1
629
+ fs_type=$2
630
+ dev=$3
631
+
632
+ dst_part_label " $pnum " " $fs_type " label
633
+ if [ " $label " != " " ] && [[ " $fs_type " == * " ext" * ]]
634
+ then
635
+ echo " e2label $dev $label "
636
+ e2label $dev $label
637
+ elif [ " $label " != " " ] && [[ " $fs_type " == * " fat" * ]]
638
+ then
639
+ echo " fatlabel $dev $label "
640
+ fatlabel $dev $label
641
+ fi
588
642
}
589
643
590
644
get_src_disk ()
655
709
# src_root_dev, if on device other than booted, is not in src_partition_table
656
710
# and src_fdisk_table, but is in src_df_table and src_mount_table
657
711
#
658
- src_partition_table=$( parted -m " /dev/$src_disk " unit s print | tr -d ' ;' )
712
+ src_partition_table=$( parted --script - m " /dev/$src_disk " unit s print | tr -d ' ;' )
659
713
src_fdisk_table=$( fdisk -l /dev/$src_disk | grep " ^/dev/" )
714
+ # Parted seems to force a partition rescan, which hides fs labels from
715
+ # lsblk output. Wait for kernel/udev to be done processing.
716
+ udevadm settle
660
717
661
718
tmp=$( df | grep -e " ^/dev/$src_disk " -e " ^/dev/root" -e " $src_root_dev " \
662
719
| tr -s " " )
758
815
src_name[p]=" ${src_mounted_dir[p]} "
759
816
fi
760
817
761
- if [[ " $part_type " == * " ext" * ]]
818
+ label=` lsblk --raw --output label --noheadings " ${src_device[p]} " `
819
+ if [ " $label " != " " ]
762
820
then
763
- label=` e2label ${src_device[p]} 2> /dev/null`
764
- if [ " $label " != " " ]
765
- then
766
- src_label[p]=" $label "
767
- fi
821
+ src_label[p]=" $label "
768
822
fi
769
823
done
770
824
@@ -1115,7 +1169,11 @@ then
1115
1169
exit 1
1116
1170
fi
1117
1171
1118
- dst_partition_table=$( parted -m " /dev/$dst_disk " unit s print | tr -d ' ;' )
1172
+ dst_partition_table=$( parted --script -m " /dev/$dst_disk " unit s print | tr -d ' ;' )
1173
+ # Parted seems to force a partition rescan, which hides fs labels from
1174
+ # lsblk output. Wait for kernel/udev to be done processing.
1175
+ udevadm settle
1176
+
1119
1177
n_dst_parts=$( echo " $dst_partition_table " | tail -n 1 | cut -d " :" -f 1)
1120
1178
if [ " $n_dst_parts " == " /dev/$dst_disk " ]
1121
1179
then
@@ -1168,16 +1226,15 @@ do
1168
1226
if [[ " $part_type " == * " linux-swap" * ]]
1169
1227
then
1170
1228
dst_fs_type[p]=" swap"
1171
- elif [[ " $part_type " == * " ext " * ]]
1229
+ elif (( p == ext_num ))
1172
1230
then
1173
- label=` e2label ${dst_device[p]} 2> /dev/null`
1231
+ dst_fs_type[p]=" EXT"
1232
+ else
1233
+ label=` lsblk --raw --output label --noheadings " ${dst_device[p]} " `
1174
1234
if [ " $label " != " " ]
1175
1235
then
1176
1236
dst_label[p]=" $label "
1177
1237
fi
1178
- elif (( p == ext_num))
1179
- then
1180
- dst_fs_type[p]=" EXT"
1181
1238
fi
1182
1239
done
1183
1240
@@ -1534,9 +1591,9 @@ Use -U for unattended even if initializing.
1534
1591
1535
1592
if [ " ${src_mounted_dir[p]} " == " /boot" ] && (( p == 1 ))
1536
1593
then
1537
- ext_label $p " $fs_type " " -L " label
1538
- printf " => mkfs -t $mkfs_type $label $dst_dev ..."
1539
- yes | mkfs -t $mkfs_type $label $dst_dev & >> /tmp/$PGM -output
1594
+ mkfs_label $p " $fs_type " label_opt
1595
+ printf " => mkfs -t $fs_type $label_opt $dst_dev ..."
1596
+ yes | mkfs -t $mkfs_type $label_opt $dst_dev & >> /tmp/$PGM -output
1540
1597
echo " "
1541
1598
else
1542
1599
if [ " $fs_type " == " swap" ]
@@ -1547,9 +1604,9 @@ Use -U for unattended even if initializing.
1547
1604
then
1548
1605
if [ " ${src_mounted_dir[p]} " != " " ] || (( p == n_image_parts))
1549
1606
then
1550
- ext_label $p $fs_type " -L " label
1551
- printf " => mkfs -t $mkfs_type $label $dst_dev ..."
1552
- yes | mkfs -t $mkfs_type $label $dst_dev & >> /tmp/$PGM -output
1607
+ mkfs_label " $p " " $fs_type " label_opt
1608
+ printf " => mkfs -t $mkfs_type $label_opt $dst_dev ..."
1609
+ yes | mkfs -t $mkfs_type $label_opt $dst_dev & >> /tmp/$PGM -output
1553
1610
echo " "
1554
1611
if (( p == n_image_parts))
1555
1612
then
@@ -1569,12 +1626,7 @@ Use -U for unattended even if initializing.
1569
1626
else
1570
1627
echo " "
1571
1628
fi
1572
- ext_label $p $fs_type " " label
1573
- if [ " $label " != " " ]
1574
- then
1575
- echo " e2label $dst_dev $label "
1576
- e2label $dst_dev $label
1577
- fi
1629
+ change_label " $p " " $fs_type " " $dst_dev "
1578
1630
fi
1579
1631
fi
1580
1632
fi
@@ -1696,13 +1748,7 @@ do
1696
1748
sync_msg_done=1
1697
1749
dst_dev=/dev/${dst_part_base}${p}
1698
1750
fs_type=${src_fs_type[$p]}
1699
- ext_label $p $fs_type " " label
1700
- if [ " $label " != " " ]
1701
- then
1702
- qecho " e2label $dst_dev $label "
1703
- e2label $dst_dev $label
1704
- fi
1705
-
1751
+ change_label " $p " " $fs_type " " $dst_dev "
1706
1752
mount_partition ${src_device[p]} $clone_src " "
1707
1753
mount_partition $dst_dev $clone " $clone_src "
1708
1754
unmount_list=" $clone_src $clone "
@@ -1714,12 +1760,7 @@ done
1714
1760
qprintf " Syncing mounted partitions:\n"
1715
1761
1716
1762
fs_type=${src_fs_type[$root_part_num]}
1717
- ext_label $root_part_num $fs_type " " label
1718
- if [ " $label " != " " ]
1719
- then
1720
- qecho " e2label $dst_root_dev $label "
1721
- e2label $dst_root_dev $label
1722
- fi
1763
+ change_label " $root_part_num " " $fs_type " " $dst_root_dev "
1723
1764
1724
1765
mount_partition $dst_root_dev $clone " "
1725
1766
unmount_list=" $clone "
@@ -1742,12 +1783,7 @@ do
1742
1783
1743
1784
dst_dev=/dev/${dst_part_base}${p}
1744
1785
fs_type=${src_fs_type[$p]}
1745
- ext_label $p $fs_type " " label
1746
- if [ " $label " != " " ]
1747
- then
1748
- qecho " e2label $dst_dev $label "
1749
- e2label $dst_dev $label
1750
- fi
1786
+ change_label " $p " " $fs_type " " $dst_dev "
1751
1787
1752
1788
mount_partition " $dst_dev " " $dst_dir " " $unmount_list "
1753
1789
rsync_file_system " ${src_mounted_dir[p]} /" " ${dst_dir} " " "
@@ -1798,12 +1834,7 @@ fi
1798
1834
1799
1835
rm -f $clone /etc/udev/rules.d/70-persistent-net.rules
1800
1836
1801
- dst_root_vol_name=` e2label $dst_root_dev `
1802
-
1803
- if [ " $dst_root_vol_name " = " " ]
1804
- then
1805
- dst_root_vol_name=" no label"
1806
- fi
1837
+ dst_root_vol_name=${dst_label[$root_part_num]}
1807
1838
1808
1839
if (( have_grub))
1809
1840
then
0 commit comments