[ale] Tar with links
Jim Kinney
jim.kinney at gmail.com
Tue Sep 27 18:25:14 EDT 2016
Hmm. Cool hack. I thought cp -a was OK with full path links.
[jkinney at gozer dir1]$ ll
total 0
-rw-rw-r--. 1 jkinney jkinney 0 Sep 27 18:21 file2
lrwxrwxrwx. 1 jkinney jkinney 33 Sep 27 18:21 fullpathfile1 ->
/home/jkinney/Projects/test/file1
lrwxrwxrwx. 1 jkinney jkinney 8 Sep 27 18:21 up1file -> ../file1
[jkinney at gozer dir1]$ mkdir dir2
][jkinney at gozer dir1]$ cp -a * dir2/
cp: cannot copy a directory, 'dir2', into itself, 'dir2/dir2'
[jkinney at gozer dir1]$ ll dir2/
total 4
drwxrwxr-x. 2 jkinney jkinney 4096 Sep 27 18:22 dir2
-rw-rw-r--. 1 jkinney jkinney 0 Sep 27 18:21 file2
lrwxrwxrwx. 1 jkinney jkinney 33 Sep 27 18:21 fullpathfile1 ->
/home/jkinney/Projects/test/file1
lrwxrwxrwx. 1 jkinney jkinney 8 Sep 27 18:21 up1file -> ../file1
Now the dir2/up1file is a broken link but the dir2/fullpathfile1 is
just fine.
I've been bit FAR too many times with relative links. Wont even mention
links that cross file-system boundaries.
On Tue, 2016-09-27 at 18:13 -0400, Chris Fowler wrote:
> 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 th[jkinney at gozer dir1]$ ll
> > total 0
> > -rw-rw-r--. 1 jkinney jkinney 0 Sep 27 18:21 file2
> > lrwxrwxrwx. 1 jkinney jkinney 33 Sep 27 18:21 fullpathfile1 ->
> > /home/jkinney/Projects/test/file1
> > lrwxrwxrwx. 1 jkinney jkinney 8 Sep 27 18:21 up1file -> ../file1
> > [jkinney at gozer dir1]$ mkdir dir2
> > ][jkinney at gozer dir1]$ cp -a * dir2/
> > cp: cannot copy a directory, 'dir2', into itself, 'dir2/dir2'
> > [jkinney at gozer dir1]$ ll dir2/
> > total 4
> > drwxrwxr-x. 2 jkinney jkinney 4096 Sep 27 18:22 dir2
> > -rw-rw-r--. 1 jkinney jkinney 0 Sep 27 18:21 file2
> > lrwxrwxrwx. 1 jkinney jkinney 33 Sep 27 18:21 fullpathfile1 ->
> > /home/jkinney/Projects/test/file1
> > lrwxrwxrwx. 1 jkinney jkinney 8 Sep 27 18:21 up1file ->
> ../file1e
> > 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. :)
>
>
>
>
>
>
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
--
James P. Kinney III
Every time you stop a school, you will have to build a jail. What you
gain at one end you lose at the other. It's like feeding a dog on his
own tail. It won't fatten the dog.
- Speech 11/23/1900 Mark Twain
http://heretothereideas.blogspot.com/
More information about the Ale
mailing list