[ale] Tar with links

Chris Fowler cfowler at outpostsentinel.com
Tue Sep 27 18:13:10 EDT 2016


I've been dealing with mkinitramfs under LFS for a bit and realized my stow system is biting me in the a$$. The solution is to bite back. 

I can simplify the issue. In mkinitramfs from 

http://www.linuxfromscratch.org/blfs/view/svn/postlfs/initramfs.html 

if [ -d /lib/udev ]; then
  cp -a /lib/udev $WDIR/lib
fi 

symlinks will bomb with that -a. 

because of (shortened listing) 

root:/run# ls -l /lib/udev//cdrom_id 
lrwxrwxrwx 1 root root 41 Sep 21 23:18 /lib/udev//cdrom_id -> ../../ usr/pkg/eudev-3.2/lib/udev/cdrom_id 
root:/run# 

What you end up with is a directory of broken links and modules are not loaded. 

Two solutions. In the post install run a program that converts files like that to real ones. Remove the links. Or put the files with the links in the initramfs image. 

Since I love a good beating I chose the later. And came up with this idea 


if [ -e /lib/udev ]; then 
#cp -aL /lib/udev $WDIR/lib 
find /lib/udev/ > /tmp/udev.txt 
while IFS= read -r line; do # Whitespace-safe EXCEPT newlines 
if test -h "${line}"; then 
FILE=${line}; 
printf "${FILE}\n" 
while test -h "${FILE}"; do 
FILE=$(realpath -s $(readlink ${FILE}) 2>/dev/null) && \ 
printf "${FILE}\n" 
done 
elif test -d "${line}"; then 
# If I specify a dir will it try it all? 
: 
else 
# Not a dir and not a link 
printf "${FILE}\n" 
fi 
done < /tmp/udev.txt | sort > /tmp/udev-sorted.txt 
(tar -C / -T /tmp/udev-sorted.txt -cf - | tar -C ${WDIR} -xvf -) 
fi 

# The result and what is needed in initramfs to preserve links is 
# /lib/udev/ata_id 
# /lib/udev/cdrom_id 
# /lib/udev/collect 
# /lib/udev/init-net-rules.sh 
# /lib/udev/mtd_probe 
# /lib/udev/rule_generator.functions 
# /lib/udev/rules.d/10-dm.rules 
# /lib/udev/rules.d/11-dm-lvm.rules 
# /lib/udev/rules.d/13-dm-disk.rules 
# /lib/udev/rules.d/50-udev-default.rules 
# /lib/udev/rules.d/60-block.rules 
# /lib/udev/rules.d/60-cdrom_id.rules 
# /lib/udev/rules.d/60-drm.rules 
# /lib/udev/rules.d/60-evdev.rules 
# /lib/udev/rules.d/60-persistent-alsa.rules 
# /lib/udev/rules.d/60-persistent-input.rules 
# /lib/udev/rules.d/60-persistent-storage-tape.rules 
# /lib/udev/rules.d/60-persistent-storage.rules 
# /lib/udev/rules.d/60-persistent-v4l.rules 
# /lib/udev/rules.d/60-serial.rules 
# /lib/udev/rules.d/64-btrfs.rules 
# /lib/udev/rules.d/70-mouse.rules 
# /lib/udev/rules.d/75-net-description.rules 
# /lib/udev/rules.d/75-probe_mtd.rules 
# /lib/udev/rules.d/78-sound-card.rules 
# /lib/udev/rules.d/80-drivers.rules 
# /lib/udev/rules.d/80-net-name-slot.rules 
# /lib/udev/rules.d/95-dm-notify.rules 
# /lib/udev/scsi_id 
# /lib/udev/v4l_id 
# /lib/udev/write_cd_rules 
# /lib/udev/write_net_rules 
# /usr/pkg/LVM2.2.02.164/lib/udev/rules.d/10-dm.rules 
# /usr/pkg/LVM2.2.02.164/lib/udev/rules.d/11-dm-lvm.rules 
# /usr/pkg/LVM2.2.02.164/lib/udev/rules.d/13-dm-disk.rules 
# /usr/pkg/LVM2.2.02.164/lib/udev/rules.d/95-dm-notify.rules 
# /usr/pkg/eudev-3.2/lib/udev/ata_id 
# /usr/pkg/eudev-3.2/lib/udev/cdrom_id 
# /usr/pkg/eudev-3.2/lib/udev/collect 
# /usr/pkg/eudev-3.2/lib/udev/init-net-rules.sh 
# /usr/pkg/eudev-3.2/lib/udev/mtd_probe 
# /usr/pkg/eudev-3.2/lib/udev/rule_generator.functions 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/50-udev-default.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/60-block.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/60-cdrom_id.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/60-drm.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/60-evdev.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/60-persistent-alsa.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/60-persistent-input.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/60-persistent-storage-tape.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/60-persistent-storage.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/60-persistent-v4l.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/60-serial.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/64-btrfs.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/70-mouse.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/75-net-description.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/75-probe_mtd.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/78-sound-card.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/80-drivers.rules 
# /usr/pkg/eudev-3.2/lib/udev/rules.d/80-net-name-slot.rules 
# /usr/pkg/eudev-3.2/lib/udev/scsi_id 
# /usr/pkg/eudev-3.2/lib/udev/v4l_id 
# /usr/pkg/eudev-3.2/lib/udev/write_cd_rules 
# /usr/pkg/eudev-3.2/lib/udev/write_net_rules 



No real reason for the sort. The issue is that the original cp copied /lib/udev. I can't just tar up that directory because there are links that references files in different directories. I opted to basically set /lib/udev as the target, create a list of everything there, walk that list and list out the links with their realpaths. Instead of cp I used tar as the copy. 


99.9% of the time I'd break out Perl and do it there. Much easier on me, but Perl is not really ready for use in the LFS system until you install all needed modules. Since most distis use bash to do these things I stuck with it. 

Not sure if there is a better way. 

Note: I did not create those boxes. I'm using Zimbra's web interface and a copy from the LFS online manual created them. :) 







-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20160927/96ca9604/attachment.html>


More information about the Ale mailing list